The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Allow passing `dataPicker` to `EditableDashboard` (#82259)
Mahatthana (Kelvin) Nomsawadi9f1d48c268c8
diff --git a/docs/embedding/dashboard.md b/docs/embedding/dashboard.mdindex 2b0f5fc7b46..369864e62cb 100644--- a/docs/embedding/dashboard.md+++ b/docs/embedding/dashboard.md@@ -277,12 +277,16 @@ For the full list of attributes, see [web component attributes](./browser-refere{% include_file "{{ dirname }}/sdk/snippets/dashboards/editable-dashboard.tsx" %}```-When someone adds a new question to a dashboard, `EditableDashboard` opens the query builder. To narrow what they can query, pass `dataPickerProps` with the entity types you want in the data picker: `"table"`, `"question"`, or `"model"`. For example, limiting people to tables keeps them building on the data you point them at, rather than on other people's saved questions:+When someone adds a new question to a dashboard, `EditableDashboard` opens the query builder. Pass `dataPickerProps` to shape the query builder's data picker: `entityTypes` narrows what people can query to `"table"`, `"question"`, or `"model"`, and `dataPicker` switches between the simple and staged pickers. Metabase defaults to the simple picker, switching to staged at 100 or more data sources.++For example, limiting people to tables keeps them building on the data you point them at, rather than on other people's saved questions:```typescript{% include_file "{{ dirname }}/sdk/snippets/dashboards/editable-dashboard-data-picker.tsx" %}```+> `"question"` only works in the staged picker. In the simple picker it does nothing.+For the full list of props, see [`EditableDashboard` props](./dashboard-reference.md#react-sdk-editabledashboard-props).## Let people create dashboardsdiff --git a/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/EditableDashboard.schema.ts b/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/EditableDashboard.schema.tsindex 12c27e46142..e1055d6c412 100644--- a/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/EditableDashboard.schema.ts+++ b/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/EditableDashboard.schema.ts@@ -10,6 +10,7 @@ const propsSchema: Yup.SchemaOf<EditableDashboardProps> = Yup.object({dashboardId: Yup.mixed().required(),token: Yup.mixed().optional(),dataPickerProps: Yup.object({+ dataPicker: Yup.mixed().optional(),entityTypes: Yup.mixed().optional(),}).optional()diff --git a/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/enterprise.unit.spec.tsx b/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/enterprise.unit.spec.tsxindex b295f959197..21157f7cd18 100644--- a/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/enterprise.unit.spec.tsx+++ b/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/enterprise.unit.spec.tsx@@ -187,6 +187,36 @@ describe("EditableDashboard", () => {expect(dataPickerDataCallUrl).not.toContain("models=table");});+ it("should allow to pass `dataPickerProps.dataPicker` to the query builder", async () => {+ await setupEnterprise({+ dataPickerProps: {+ dataPicker: "staged",+ },+ });+ setupSimpleDataPickerEndpoints();++ expect(screen.getByTestId("dashboard-header")).toBeInTheDocument();++ await userEvent.click(+ within(screen.getByTestId("dashboard-header")).getByLabelText(+ "Edit dashboard",+ ),+ );+ await userEvent.click(+ screen.getByRole("button", { name: "Add questions" }),+ );+ await userEvent.click(screen.getByRole("button", { name: "New Question" }));++ // The instance is below the 100-source threshold, so only `dataPicker`+ // can be keeping the simple picker away.+ expect(+ await screen.findByRole("button", { name: "Pick your starting data" }),+ ).toBeInTheDocument();+ expect(+ screen.queryByTestId("embedding-simple-data-picker-trigger"),+ ).not.toBeInTheDocument();+ });+it("should show 'Add a chart' button on empty dashboards", async () => {await setupEnterprise({ dashcards: [] });diff --git a/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.schema.ts b/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.schema.tsindex d030653480c..d5472829ad3 100644--- a/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.schema.ts+++ b/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.schema.ts@@ -9,11 +9,6 @@ const propsSchema: Yup.SchemaOf<InteractiveDashboardProps> = Yup.object({className: Yup.mixed().optional(),dashboardId: Yup.mixed().required(),token: Yup.mixed().optional(),- dataPickerProps: Yup.object({- entityTypes: Yup.mixed().optional(),- })- .optional()- .noUnknown(),drillThroughQuestionHeight: Yup.mixed().optional(),drillThroughQuestionProps: Yup.object({children: Yup.mixed().optional(),diff --git a/frontend/src/embedding-sdk-bundle/components/public/dashboard/SdkDashboard.tsx b/frontend/src/embedding-sdk-bundle/components/public/dashboard/SdkDashboard.tsxindex 667b2d2d6e0..04bfdba9d94 100644--- a/frontend/src/embedding-sdk-bundle/components/public/dashboard/SdkDashboard.tsx+++ b/frontend/src/embedding-sdk-bundle/components/public/dashboard/SdkDashboard.tsx@@ -206,8 +206,7 @@ export type SdkDashboardProps = PropsWithChildren<*/onParametersChange?: (payload: ParameterChangePayload) => void;} & SdkDashboardDisplayProps &- DashboardEventHandlersProps &- EditableDashboardOwnProps+ DashboardEventHandlersProps>;type RenderMode = "dashboard" | "question" | "queryBuilder";@@ -220,11 +219,14 @@ type RenderMode = "dashboard" | "question" | "queryBuilder";export type EditableDashboardOwnProps = {/*** Additional props to pass to the query builder rendered by `InteractiveQuestion` when creating a new dashboard question.+ *+ * Set `dataPicker: "staged"` to always get the staged data picker. By default, Metabase shows a simple dropdown menu with tables and models, and only switches to the staged picker when there are 100 or more data sources. `entityTypes: ["question"]` only takes effect in the staged picker.*/- dataPickerProps?: Pick<SdkQuestionProps, "entityTypes">;+ dataPickerProps?: Pick<SdkQuestionProps, "entityTypes" | "dataPicker">;};export type SdkDashboardInnerProps = SdkDashboardProps &+ EditableDashboardOwnProps &Partial<Pick<DashboardContextProps,@@ -785,6 +787,7 @@ function DashboardQueryBuilder({name: dashboard.name,}}entityTypes={dataPickerProps?.entityTypes}+ dataPicker={dataPickerProps?.dataPicker}withChartTypeSelector// Fill the available space so the query builder matches the dashboard's// sizing instead of a fixed height that leaves whitespace / scrolls.diff --git a/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/StaticDashboard.schema.ts b/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/StaticDashboard.schema.tsindex c43fc808fd5..d9f7cfc1179 100644--- a/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/StaticDashboard.schema.ts+++ b/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/StaticDashboard.schema.ts@@ -13,11 +13,6 @@ const propsSchema: Yup.SchemaOf<StaticDashboardProps> = Yup.object({otherwise: (schema) => schema.required(),}),token: Yup.mixed().optional(),- dataPickerProps: Yup.object({- entityTypes: Yup.mixed().optional(),- })- .optional()- .noUnknown(),hiddenParameters: Yup.mixed().optional(),initialParameters: Yup.mixed().optional(),parameters: Yup.mixed().optional(),diff --git a/frontend/src/embedding-sdk-bundle/components/public/dashboard/tests/setup.tsx b/frontend/src/embedding-sdk-bundle/components/public/dashboard/tests/setup.tsxindex 95dd38290fe..3b3151213b8 100644--- a/frontend/src/embedding-sdk-bundle/components/public/dashboard/tests/setup.tsx+++ b/frontend/src/embedding-sdk-bundle/components/public/dashboard/tests/setup.tsx@@ -118,7 +118,9 @@ export interface SetupSdkDashboardOptions extends NotificationChannelSetup {props?: Omit<Partial<SdkDashboardProps>, "token">;providerProps?: Partial<MetabaseProviderProps>;isLocaleLoading?: boolean;- component: ComponentType<SdkDashboardProps>;+ component: ComponentType<+ SdkDashboardProps & Pick<EditableDashboardProps, "dataPickerProps">+ >;dashboardName?: string;dataPickerProps?: EditableDashboardProps["dataPickerProps"];dashcards?: DashboardCard[];