Skip to content
Snippets Groups Projects
Unverified Commit 41f6d175 authored by Kamil Mielnik's avatar Kamil Mielnik Committed by GitHub
Browse files

Fix - Empty collections shown in Data Picker (#42959)

* Generate different shouldShowItem for different pickers

* Add repro for #42957

* Update test to use models instead of metrics
parent 848fd930
No related branches found
No related tags found
No related merge requests found
import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
import {
createQuestion,
entityPickerModal,
entityPickerModalTab,
restore,
startNewQuestion,
} from "e2e/support/helpers";
const { ORDERS_ID } = SAMPLE_DATABASE;
describe("issue 42957", () => {
beforeEach(() => {
restore();
cy.signInAsAdmin();
});
it("does not show collections that contain models from different tabs (metabase#42957)", () => {
createQuestion({
name: "Model",
type: "model",
query: {
"source-table": ORDERS_ID,
},
});
cy.createCollection({ name: "Collection without models" }).then(
({ body: collection }) => {
cy.wrap(collection.id).as("collectionId");
},
);
cy.get("@collectionId").then(collectionId => {
createQuestion({
name: "Question",
type: "question",
query: {
"source-table": ORDERS_ID,
},
collection_id: collectionId,
});
});
startNewQuestion();
entityPickerModal().within(() => {
entityPickerModalTab("Models").should(
"have.attr",
"aria-selected",
"true",
);
cy.findByText("Collection without models").should("not.exist");
});
});
});
......@@ -69,8 +69,16 @@ export const DataPickerModal = ({
databaseId,
});
const shouldShowItem = useMemo(() => {
return createShouldShowItem(databaseId);
const modelsShouldShowItem = useMemo(() => {
return createShouldShowItem(["dataset"], databaseId);
}, [databaseId]);
const metricsShouldShowItem = useMemo(() => {
return createShouldShowItem(["metric"], databaseId);
}, [databaseId]);
const questionsShouldShowItem = useMemo(() => {
return createShouldShowItem(["card"], databaseId);
}, [databaseId]);
const searchParams = useMemo(() => {
......@@ -114,7 +122,7 @@ export const DataPickerModal = ({
initialValue={isModelItem(value) ? value : undefined}
models={MODEL_PICKER_MODELS}
options={options}
shouldShowItem={shouldShowItem}
shouldShowItem={modelsShouldShowItem}
onItemSelect={handleCardChange}
/>
),
......@@ -130,7 +138,7 @@ export const DataPickerModal = ({
initialValue={isMetricItem(value) ? value : undefined}
models={METRIC_PICKER_MODELS}
options={options}
shouldShowItem={shouldShowItem}
shouldShowItem={metricsShouldShowItem}
onItemSelect={handleCardChange}
/>
),
......@@ -158,7 +166,7 @@ export const DataPickerModal = ({
initialValue={isQuestionItem(value) ? value : undefined}
models={QUESTION_PICKER_MODELS}
options={options}
shouldShowItem={shouldShowItem}
shouldShowItem={questionsShouldShowItem}
onItemSelect={handleCardChange}
/>
),
......
......@@ -4,6 +4,7 @@ import * as Lib from "metabase-lib";
import { getSchemaName } from "metabase-lib/v1/metadata/utils/schema";
import type {
CollectionItem,
CollectionItemModel,
Database,
DatabaseId,
SchemaName,
......@@ -140,16 +141,16 @@ export const isValidValueItem = (model: SearchModel): boolean => {
return ["table", "card", "dataset", "metric"].includes(model);
};
export const createShouldShowItem = (databaseId?: DatabaseId) => {
export const createShouldShowItem = (
models: CollectionItemModel[],
databaseId?: DatabaseId,
) => {
return (item: QuestionPickerItem) => {
if (item.model === "collection") {
const below = item.below ?? [];
const here = item.here ?? [];
const contents = [...below, ...here];
const hasCards =
contents.includes("card") ||
contents.includes("dataset") ||
contents.includes("metric");
const hasCards = models.some(model => contents.includes(model));
if (item.id !== "root" && !item.is_personal && !hasCards) {
return false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment