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
Show tooltip on disabled databases when creating transforms (#70987)
Andersonc42e6a731214
diff --git a/e2e/test/scenarios/data-studio/transforms/transforms.cy.spec.ts b/e2e/test/scenarios/data-studio/transforms/transforms.cy.spec.tsindex dcc33bd244e..11e65b9dd0f 100644--- a/e2e/test/scenarios/data-studio/transforms/transforms.cy.spec.ts+++ b/e2e/test/scenarios/data-studio/transforms/transforms.cy.spec.ts@@ -500,7 +500,7 @@ LIMITH.assertQueryBuilderRowCount(3);});- it("should not be possible to create an mbql transform from a table from an unsupported database", () => {+ it("should not be possible to create an MBQL transform from a table from an unsupported database", () => {visitTransformListPage();cy.button("Create a transform").click();H.popover().findByText("Query builder").click();@@ -520,10 +520,19 @@ LIMITcy.findAllByTestId("picker-item").contains(/Writable Postgres/).should("not.have.attr", "data-disabled");++ cy.log("Should show a tooltip explaining why the database is disabled");+ cy.findAllByTestId("picker-item")+ .contains("Sample Database")+ .realHover();});+ H.tooltip().should(+ "contain.text",+ "Transforms can't be enabled on the Sample Database.",+ );});- it("should not be possible to create an mbql transform from metrics", () => {+ it("should not be possible to create an MBQL transform from metrics", () => {H.getTableId({ name: "Animals", databaseId: WRITABLE_DB_ID }).then((tableId) =>H.createQuestion({@@ -572,6 +581,13 @@ LIMITcy.log("Clicking the disabled item does not close the popover");H.popover().should("be.visible");++ cy.log("Should show a tooltip explaining why the database is disabled");+ H.popover().findByRole("option", { name: "Sample Database" }).realHover();+ H.tooltip().should(+ "contain.text",+ "Transforms can't be enabled on the Sample Database.",+ );});it("not show the 'Show details' buttons in ID columns (metabase#64473)", () => {diff --git a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ItemLists/ItemList.tsx b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ItemLists/ItemList.tsxindex efe7cb8ec81..b967f80121f 100644--- a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ItemLists/ItemList.tsx+++ b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ItemLists/ItemList.tsx@@ -13,6 +13,7 @@ import {Icon,NavLink,type NavLinkProps,+ Tooltip,} from "metabase/ui";import { useSelector } from "metabase/utils/redux";@@ -102,6 +103,7 @@ export function ItemList({isTenantUser,});const isDisabled = isDisabledItem(item);+ const tooltip = options.getItemTooltip?.(item);return (<Box@@ -109,43 +111,55 @@ export function ItemList({key={`${item.model}-${item.id}`}{...containerProps}>- <NavLink- w={"auto"}- disabled={isDisabled}- rightSection={- isFolderItem(item) ? (- <Icon name="chevronright" size={10} />- ) : null- }- mb={0}- label={- <Flex align="center">- {tc(item.name)}{" "}- <PLUGIN_MODERATION.ModerationStatusIcon- status={"moderated_status" in item && item.moderated_status}- filled- size={14}- ml="0.5rem"- />- </Flex>- }- active={isSelected}- leftSection={<Icon {...icon} />}- onClick={(e: React.MouseEvent) => {- e.preventDefault(); // prevent form submission- e.stopPropagation(); // prevent parent onClick- setPath((prevPath) => [- ...prevPath.slice(0, pathIndex + 1),- item,- ]);-- if (!options?.hasConfirmButtons && isSelectableItem(item)) {- onChange(item);+ <Tooltip label={tooltip} disabled={!tooltip} position="right">+ <NavLink+ w={"auto"}+ disabled={isDisabled}+ style={+ isDisabled && tooltip ? { pointerEvents: "all" } : undefined+ }+ rightSection={+ isFolderItem(item) ? (+ <Icon name="chevronright" size={10} />+ ) : null+ }+ mb={0}+ label={+ <Flex align="center">+ {tc(item.name)}{" "}+ <PLUGIN_MODERATION.ModerationStatusIcon+ status={+ "moderated_status" in item && item.moderated_status+ }+ filled+ size={14}+ ml="0.5rem"+ />+ </Flex>}- }}- variant={isCurrentLevel ? "default" : "mb-light"}- {...navLinkProps?.(isSelected)}- />+ active={isSelected}+ leftSection={<Icon {...icon} />}+ onClick={(e: React.MouseEvent) => {+ e.preventDefault(); // prevent form submission+ e.stopPropagation(); // prevent parent onClick++ if (isDisabled) {+ return;+ }++ setPath((prevPath) => [+ ...prevPath.slice(0, pathIndex + 1),+ item,+ ]);++ if (!options?.hasConfirmButtons && isSelectableItem(item)) {+ onChange(item);+ }+ }}+ variant={isCurrentLevel ? "default" : "mb-light"}+ {...navLinkProps?.(isSelected)}+ />+ </Tooltip></Box>);})}diff --git a/frontend/src/metabase/common/components/Pickers/EntityPicker/types.ts b/frontend/src/metabase/common/components/Pickers/EntityPicker/types.tsindex 2382c441ad6..2af4c7e7604 100644--- a/frontend/src/metabase/common/components/Pickers/EntityPicker/types.ts+++ b/frontend/src/metabase/common/components/Pickers/EntityPicker/types.ts@@ -24,6 +24,7 @@ export type EntityPickerOptions = {hasLibrary?: boolean;hasRootCollection?: boolean;hasPersonalCollections?: boolean; // other users personal collections+ getItemTooltip?: (item: OmniPickerItem) => string | undefined;// options to customize the button barhasConfirmButtons?: boolean;@@ -85,7 +86,6 @@ export type OmniPickerCollectionItem = Pick<| "location"| "type"| "database_id"- | "location"| "effective_location"> & {id: CollectionItem["id"] | CollectionId;diff --git a/frontend/src/metabase/query_builder/components/DataSelector/DataSelector.jsx b/frontend/src/metabase/query_builder/components/DataSelector/DataSelector.jsxindex fa039f1b5a4..c9088ec23a7 100644--- a/frontend/src/metabase/query_builder/components/DataSelector/DataSelector.jsx+++ b/frontend/src/metabase/query_builder/components/DataSelector/DataSelector.jsx@@ -163,6 +163,7 @@ export class UnconnectedDataSelector extends Component {canSelectMetric: PropTypes.bool,canSelectSavedQuestion: PropTypes.bool,databaseIsDisabled: PropTypes.func,+ databaseDisabledTooltip: PropTypes.func,// from search entity list loaderallError: PropTypes.bool,@@ -905,6 +906,7 @@ export class UnconnectedDataSelector extends Component {hasFiltering: true,hasInitialFocus: true,databaseIsDisabled: this.props.databaseIsDisabled,+ databaseDisabledTooltip: this.props.databaseDisabledTooltip,};switch (this.state.activeStep) {diff --git a/frontend/src/metabase/query_builder/components/DataSelector/DataSelectorDatabasePicker/DataSelectorDatabasePicker.tsx b/frontend/src/metabase/query_builder/components/DataSelector/DataSelectorDatabasePicker/DataSelectorDatabasePicker.tsxindex 3486f6a9759..3b261484573 100644--- a/frontend/src/metabase/query_builder/components/DataSelector/DataSelectorDatabasePicker/DataSelectorDatabasePicker.tsx+++ b/frontend/src/metabase/query_builder/components/DataSelector/DataSelectorDatabasePicker/DataSelectorDatabasePicker.tsx@@ -1,4 +1,5 @@import cx from "classnames";+import type { ReactNode } from "react";import { useCallback, useMemo } from "react";import {@@ -6,7 +7,7 @@ import {type Section,} from "metabase/common/components/AccordionList";import CS from "metabase/css/core/index.css";-import { Icon } from "metabase/ui";+import { Icon, Tooltip } from "metabase/ui";import type Database from "metabase-lib/v1/metadata/Database";import type Schema from "metabase-lib/v1/metadata/Schema";@@ -26,6 +27,7 @@ type DataSelectorDatabasePickerProps = {onChangeDatabase: (database: Database) => void;onChangeSchema: (item: { schema?: Schema }) => void;databaseIsDisabled?: (database: Database) => boolean;+ databaseDisabledTooltip?: (database: Database) => string | undefined;};type Item = {@@ -42,6 +44,7 @@ export const DataSelectorDatabasePicker = ({onBack,hasInitialFocus,databaseIsDisabled,+ databaseDisabledTooltip,}: DataSelectorDatabasePickerProps) => {const sections = useMemo(() => {const sections: Section<Item>[] = [];@@ -97,6 +100,17 @@ export const DataSelectorDatabasePicker = ({size={18}/>)}+ renderItemWrapper={(content: ReactNode, item: Item) => {+ const tooltip = databaseDisabledTooltip?.(item.database);+ if (tooltip) {+ return (+ <Tooltip label={tooltip} position="right">+ <div>{content}</div>+ </Tooltip>+ );+ }+ return content;+ }}showItemArrows={hasNextStep}maxHeight={Infinity}/>diff --git a/frontend/src/metabase/query_builder/components/NativeQueryEditor/DataSourceSelectors/DataSourceSelectors.jsx b/frontend/src/metabase/query_builder/components/NativeQueryEditor/DataSourceSelectors/DataSourceSelectors.jsxindex f8a6f4f86b8..6492ea70e2a 100644--- a/frontend/src/metabase/query_builder/components/NativeQueryEditor/DataSourceSelectors/DataSourceSelectors.jsx+++ b/frontend/src/metabase/query_builder/components/NativeQueryEditor/DataSourceSelectors/DataSourceSelectors.jsx@@ -21,6 +21,7 @@ const DataSourceSelectorsPropTypes = {setTableId: PropTypes.func,editorContext: PropTypes.oneOf(["action", "question"]),databaseIsDisabled: PropTypes.func,+ databaseDisabledTooltip: PropTypes.func,};const PopulatedDataSourceSelectorsPropTypes = {@@ -32,6 +33,7 @@ const PopulatedDataSourceSelectorsPropTypes = {setDatabaseId: PropTypes.func,setTableId: PropTypes.func,databaseIsDisabled: PropTypes.func,+ databaseDisabledTooltip: PropTypes.func,};const DatabaseSelectorPropTypes = {@@ -40,6 +42,7 @@ const DatabaseSelectorPropTypes = {readOnly: PropTypes.bool,setDatabaseId: PropTypes.func,databaseIsDisabled: PropTypes.func,+ databaseDisabledTooltip: PropTypes.func,};const SingleDatabaseNamePropTypes = {@@ -67,6 +70,7 @@ export const DataSourceSelectors = ({setTableId,editorContext,databaseIsDisabled,+ databaseDisabledTooltip,}) => {const database = question.database();@@ -101,6 +105,7 @@ export const DataSourceSelectors = ({setDatabaseId={setDatabaseId}setTableId={setTableId}databaseIsDisabled={databaseIsDisabled}+ databaseDisabledTooltip={databaseDisabledTooltip}/>);};@@ -115,6 +120,7 @@ const PopulatedDataSourceSelectors = ({setDatabaseId,setTableId,databaseIsDisabled,+ databaseDisabledTooltip,}) => {const dataSourceSelectors = [];@@ -132,6 +138,7 @@ const PopulatedDataSourceSelectors = ({readOnly={readOnly}setDatabaseId={setDatabaseId}databaseIsDisabled={databaseIsDisabled}+ databaseDisabledTooltip={databaseDisabledTooltip}/>,);} else if (database) {@@ -167,6 +174,7 @@ const DatabaseSelector = ({readOnly,setDatabaseId,databaseIsDisabled,+ databaseDisabledTooltip,}) => (<divclassName={cx(@@ -186,6 +194,7 @@ const DatabaseSelector = ({isInitiallyOpen={database == null && databases.length > 1}readOnly={readOnly}databaseIsDisabled={databaseIsDisabled}+ databaseDisabledTooltip={databaseDisabledTooltip}/></div>);diff --git a/frontend/src/metabase/query_builder/components/NativeQueryEditor/NativeQueryEditor.tsx b/frontend/src/metabase/query_builder/components/NativeQueryEditor/NativeQueryEditor.tsxindex dc815661dad..9213a15e450 100644--- a/frontend/src/metabase/query_builder/components/NativeQueryEditor/NativeQueryEditor.tsx+++ b/frontend/src/metabase/query_builder/components/NativeQueryEditor/NativeQueryEditor.tsx@@ -63,6 +63,7 @@ type NativeQueryEditorProps = Omit<CodeMirrorEditorProps, "query"> & {className?: string;closeSnippetModal?: () => void;databaseIsDisabled?: (database: Database) => boolean;+ databaseDisabledTooltip?: (database: Database) => string | undefined;editorContext?: "question" | "action";extraButton?: ReactNode;handleResize?: () => void;@@ -125,6 +126,7 @@ export const NativeQueryEditor = forwardRef<className,closeSnippetModal,databaseIsDisabled,+ databaseDisabledTooltip,editorContext,extensions,handleResize: handleResizeFromProps,@@ -322,6 +324,7 @@ export const NativeQueryEditor = forwardRef<setDatasetQuery={setDatasetQuery}onFormatQuery={handleFormatQuery}databaseIsDisabled={databaseIsDisabled}+ databaseDisabledTooltip={databaseDisabledTooltip}readOnly={readOnly}>{topBarInnerContent}diff --git a/frontend/src/metabase/query_builder/components/NativeQueryEditor/NativeQueryEditorTopBar/NativeQueryEditorTopBar.tsx b/frontend/src/metabase/query_builder/components/NativeQueryEditor/NativeQueryEditorTopBar/NativeQueryEditorTopBar.tsxindex 6c82d813a0c..b8326663737 100644--- a/frontend/src/metabase/query_builder/components/NativeQueryEditor/NativeQueryEditorTopBar/NativeQueryEditorTopBar.tsx+++ b/frontend/src/metabase/query_builder/components/NativeQueryEditor/NativeQueryEditorTopBar/NativeQueryEditorTopBar.tsx@@ -54,6 +54,7 @@ interface NativeQueryEditorTopBarProps extends PropsWithChildren {focus: () => void;setDatasetQuery: (query: NativeQuery) => void;databaseIsDisabled?: (database: Database) => boolean;+ databaseDisabledTooltip?: (database: Database) => string | undefined;}export const NativeQueryEditorTopBar = forwardRef<@@ -91,6 +92,7 @@ export const NativeQueryEditorTopBar = forwardRef<hasParametersList = true,setDatasetQuery,databaseIsDisabled,+ databaseDisabledTooltip,} = props;const dispatch = useDispatch();@@ -138,6 +140,7 @@ export const NativeQueryEditorTopBar = forwardRef<setTableId={setTableId}editorContext={editorContext}databaseIsDisabled={databaseIsDisabled}+ databaseDisabledTooltip={databaseDisabledTooltip}/>)}{hasParametersList && setParameterValue && (diff --git a/frontend/src/metabase/querying/editor/components/QueryEditor/QueryEditor.tsx b/frontend/src/metabase/querying/editor/components/QueryEditor/QueryEditor.tsxindex be88a8c6992..f2851b48fdb 100644--- a/frontend/src/metabase/querying/editor/components/QueryEditor/QueryEditor.tsx+++ b/frontend/src/metabase/querying/editor/components/QueryEditor/QueryEditor.tsx@@ -123,6 +123,7 @@ export function QueryEditor({uiState.sidebarType === "template-tags"}shouldDisableItem={uiOptions?.shouldDisableDataPickerItem}+ getItemTooltip={uiOptions?.getDataPickerItemTooltip}shouldDisableDatabase={uiOptions?.shouldDisableDatabasePickerItem}shouldShowLibrary={uiOptions?.shouldShowLibrary}onChange={setQuestion}diff --git a/frontend/src/metabase/querying/editor/components/QueryEditor/QueryEditorBody/QueryEditorBody.tsx b/frontend/src/metabase/querying/editor/components/QueryEditor/QueryEditorBody/QueryEditorBody.tsxindex b37511e06fa..a7513ec1508 100644--- a/frontend/src/metabase/querying/editor/components/QueryEditor/QueryEditorBody/QueryEditorBody.tsx+++ b/frontend/src/metabase/querying/editor/components/QueryEditor/QueryEditorBody/QueryEditorBody.tsx@@ -58,6 +58,9 @@ type QueryEditorBodyProps = {isShowingTemplateTagsSidebar: boolean;shouldDisableDatabase?: (database: QueryEditorDatabasePickerItem) => boolean;shouldDisableItem?: (item: OmniPickerItem | RecentCollectionItem) => boolean;+ getItemTooltip?: (+ item: OmniPickerItem | RecentCollectionItem,+ ) => string | undefined;shouldShowLibrary?: boolean;onBlur?: () => void;onChange: (newQuestion: Question) => void;@@ -96,6 +99,7 @@ export function QueryEditorBody({isShowingTemplateTagsSidebar,shouldDisableDatabase,shouldDisableItem,+ getItemTooltip,shouldShowLibrary,onBlur,onChange,@@ -124,10 +128,32 @@ export function QueryEditorBody({);const dataPickerOptions = useMemo(- () => ({ shouldDisableItem, shouldDisableDatabase, shouldShowLibrary }),- [shouldDisableItem, shouldDisableDatabase, shouldShowLibrary],+ () => ({+ shouldDisableItem,+ getItemTooltip,+ shouldDisableDatabase,+ shouldShowLibrary,+ }),+ [+ shouldDisableItem,+ getItemTooltip,+ shouldDisableDatabase,+ shouldShowLibrary,+ ],);+ const databaseDisabledTooltip = useMemo(() => {+ if (!getItemTooltip) {+ return undefined;+ }+ return (database: QueryEditorDatabasePickerItem) =>+ getItemTooltip({+ id: database.id,+ model: "database",+ name: "",+ });+ }, [getItemTooltip]);+const setQuestion = (newQuestion: Question) => {onChange(newQuestion);return Promise.resolve();@@ -171,6 +197,7 @@ export function QueryEditorBody({runQuery={hideRunButton ? undefined : onRunQuery}cancelQuery={onCancelQuery}databaseIsDisabled={shouldDisableDatabase}+ databaseDisabledTooltip={databaseDisabledTooltip}setDatasetQuery={handleNativeQueryChange}sidebarFeatures={NATIVE_EDITOR_SIDEBAR_FEATURES}toggleDataReference={onToggleDataReference}diff --git a/frontend/src/metabase/querying/editor/types.ts b/frontend/src/metabase/querying/editor/types.tsindex a9c5d01370c..98aa286a02f 100644--- a/frontend/src/metabase/querying/editor/types.ts+++ b/frontend/src/metabase/querying/editor/types.ts@@ -68,6 +68,9 @@ export type QueryEditorUiOptions = {convertToNativeButtonLabel?: string;disableDefaultLimit?: boolean;shouldDisableDataPickerItem?: (item: QueryEditorDataPickerItem) => boolean;+ getDataPickerItemTooltip?: (+ item: QueryEditorDataPickerItem,+ ) => string | undefined;shouldDisableDatabasePickerItem?: (item: QueryEditorDatabasePickerItem,) => boolean;diff --git a/frontend/src/metabase/querying/notebook/components/DataStep/DataStep.tsx b/frontend/src/metabase/querying/notebook/components/DataStep/DataStep.tsxindex a77c4779854..5124b8a2e2b 100644--- a/frontend/src/metabase/querying/notebook/components/DataStep/DataStep.tsx+++ b/frontend/src/metabase/querying/notebook/components/DataStep/DataStep.tsx@@ -9,6 +9,7 @@ import * as Lib from "metabase-lib";import type { NotebookStepProps } from "../../types";import { FieldPicker, type FieldPickerItem } from "../FieldPicker";+import { useNotebookContext } from "../Notebook/context";import { NotebookCell, NotebookCellItem } from "../NotebookCell";import { CONTAINER_PADDING } from "../NotebookCell/constants";import { NotebookDataPicker } from "../NotebookDataPicker";@@ -22,8 +23,8 @@ export const DataStep = ({readOnly = false,color,updateQuery,- dataPickerOptions,}: NotebookStepProps) => {+ const { dataPickerOptions } = useNotebookContext();const { question, stageIndex } = step;const tableId = Lib.sourceTableOrCardId(query);const table = tableIddiff --git a/frontend/src/metabase/querying/notebook/components/Notebook/Notebook.tsx b/frontend/src/metabase/querying/notebook/components/Notebook/Notebook.tsxindex b409a5d392f..19f34604e69 100644--- a/frontend/src/metabase/querying/notebook/components/Notebook/Notebook.tsx+++ b/frontend/src/metabase/querying/notebook/components/Notebook/Notebook.tsx@@ -47,14 +47,16 @@ export const Notebook = ({};return (- <NotebookProvider modelsFilterList={modelsFilterList}>+ <NotebookProvider+ modelsFilterList={modelsFilterList}+ dataPickerOptions={dataPickerOptions}+ ><Box pos="relative" p={{ base: "1rem", sm: "2rem" }}><NotebookStepListupdateQuestion={handleUpdateQuestion}question={question}reportTimezone={reportTimezone}readOnly={readOnly}- dataPickerOptions={dataPickerOptions}/>{hasVisualizeButton && runQuestionQuery && (<VisualizeButtondiff --git a/frontend/src/metabase/querying/notebook/components/Notebook/context.tsx b/frontend/src/metabase/querying/notebook/components/Notebook/context.tsxindex c703fa70ce3..92ab1b47b13 100644--- a/frontend/src/metabase/querying/notebook/components/Notebook/context.tsx+++ b/frontend/src/metabase/querying/notebook/components/Notebook/context.tsx@@ -1,9 +1,17 @@-import { type PropsWithChildren, createContext, useContext } from "react";+import {+ type PropsWithChildren,+ createContext,+ useContext,+ useMemo,+} from "react";import type { DataPickerValue } from "metabase/common/components/Pickers/DataPicker";+import type { NotebookDataPickerOptions } from "../../types";+export type NotebookContextType = {modelsFilterList: DataPickerValue["model"][];+ dataPickerOptions?: NotebookDataPickerOptions;};export const NotebookContext = createContext<NotebookContextType | undefined>(@@ -12,10 +20,16 @@ export const NotebookContext = createContext<NotebookContextType | undefined>(export const NotebookProvider = ({modelsFilterList = ["table", "card", "dataset", "metric"],+ dataPickerOptions,children,}: PropsWithChildren<Partial<NotebookContextType>>) => {+ const value = useMemo(+ () => ({ modelsFilterList, dataPickerOptions }),+ [modelsFilterList, dataPickerOptions],+ );+return (- <NotebookContext.Provider value={{ modelsFilterList }}>+ <NotebookContext.Provider value={value}>{children}</NotebookContext.Provider>);diff --git a/frontend/src/metabase/querying/notebook/components/NotebookDataPicker/NotebookDataPicker.tsx b/frontend/src/metabase/querying/notebook/components/NotebookDataPicker/NotebookDataPicker.tsxindex 1a6c1980ac5..a03dea0fd4e 100644--- a/frontend/src/metabase/querying/notebook/components/NotebookDataPicker/NotebookDataPicker.tsx+++ b/frontend/src/metabase/querying/notebook/components/NotebookDataPicker/NotebookDataPicker.tsx@@ -175,6 +175,7 @@ function ModernDataPicker({shouldShowLibrary,}: ModernDataPickerProps) {const context = useNotebookContext();+ const getItemTooltip = context.dataPickerOptions?.getItemTooltip;const modelList = getModelFilterList(context, hasMetrics);const databaseId = Lib.databaseID(query) ?? undefined;@@ -262,6 +263,7 @@ function ModernDataPicker({shouldDisableDatabase?.(i)),);}}+ options={getItemTooltip ? { getItemTooltip } : undefined}// searchQuery={dataSourceSearchQuery} ?/>)}diff --git a/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookStep.tsx b/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookStep.tsxindex 95a8318f280..35285bff718 100644--- a/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookStep.tsx+++ b/frontend/src/metabase/querying/notebook/components/NotebookStep/NotebookStep.tsx@@ -10,7 +10,6 @@ import type * as Lib from "metabase-lib";import type {NotebookStep as INotebookStep,- NotebookDataPickerOptions,NotebookStepAction,} from "../../types";@@ -31,7 +30,6 @@ interface NotebookStepProps {readOnly?: boolean;openStep: (id: string) => void;updateQuery: (query: Lib.Query) => Promise<void>;- dataPickerOptions?: NotebookDataPickerOptions;}export function NotebookStep({@@ -42,7 +40,6 @@ export function NotebookStep({openStep,updateQuery,readOnly = false,- dataPickerOptions,}: NotebookStepProps) {const [isPreviewOpen, { turnOn: openPreview, turnOff: closePreview }] =useToggle(false);@@ -122,7 +119,6 @@ export function NotebookStep({isLastOpened={isLastOpened}reportTimezone={reportTimezone}readOnly={readOnly}- dataPickerOptions={dataPickerOptions}/></Box>{!readOnly && (diff --git a/frontend/src/metabase/querying/notebook/components/NotebookStepList/NotebookStepList.tsx b/frontend/src/metabase/querying/notebook/components/NotebookStepList/NotebookStepList.tsxindex 5817f26ed7a..c95febb16ef 100644--- a/frontend/src/metabase/querying/notebook/components/NotebookStepList/NotebookStepList.tsx+++ b/frontend/src/metabase/querying/notebook/components/NotebookStepList/NotebookStepList.tsx@@ -5,11 +5,7 @@ import type { Query } from "metabase-lib";import * as Lib from "metabase-lib";import type Question from "metabase-lib/v1/Question";-import type {- NotebookStep as INotebookStep,- NotebookDataPickerOptions,- OpenSteps,-} from "../../types";+import type { NotebookStep as INotebookStep, OpenSteps } from "../../types";import { NotebookStep } from "../NotebookStep";interface NotebookStepListProps {@@ -19,7 +15,6 @@ interface NotebookStepListProps {reportTimezone: string;updateQuestion: (question: Question) => Promise<void>;readOnly?: boolean;- dataPickerOptions?: NotebookDataPickerOptions;}function getInitialOpenSteps(question: Question, readOnly: boolean): OpenSteps {@@ -41,7 +36,6 @@ export function NotebookStepList({reportTimezone,updateQuestion,readOnly = false,- dataPickerOptions,}: NotebookStepListProps) {const metadata = question.metadata();const [openSteps, setOpenSteps] = useState<OpenSteps>(@@ -110,7 +104,6 @@ export function NotebookStepList({updateQuery={onChange}openStep={handleStepOpen}readOnly={readOnly}- dataPickerOptions={dataPickerOptions}/>);})}diff --git a/frontend/src/metabase/querying/notebook/types.ts b/frontend/src/metabase/querying/notebook/types.tsindex 3fe7936b37f..3206af9384a 100644--- a/frontend/src/metabase/querying/notebook/types.ts+++ b/frontend/src/metabase/querying/notebook/types.ts@@ -1,3 +1,4 @@+import type { OmniPickerItem } from "metabase/common/components/Pickers";import type { ColorName } from "metabase/ui/colors/types";import type * as Lib from "metabase-lib";import type Question from "metabase-lib/v1/Question";@@ -49,7 +50,9 @@ export interface NotebookStepAction {export type NotebookDataPickerOptions = Pick<NotebookDataPickerProps,"shouldDisableItem"->;+> & {+ getItemTooltip?: (item: OmniPickerItem) => string | undefined;+};export interface NotebookStepProps {step: NotebookStep;@@ -60,7 +63,6 @@ export interface NotebookStepProps {reportTimezone: string;readOnly?: boolean;updateQuery: (query: Lib.Query) => Promise<void>;- dataPickerOptions?: NotebookDataPickerOptions;}export interface NotebookStepHeaderProps {diff --git a/frontend/src/metabase/transforms/components/TransformEditor/utils.ts b/frontend/src/metabase/transforms/components/TransformEditor/utils.tsindex 5381843969d..8a95afe42cb 100644--- a/frontend/src/metabase/transforms/components/TransformEditor/utils.ts+++ b/frontend/src/metabase/transforms/components/TransformEditor/utils.ts@@ -3,7 +3,7 @@ import { t } from "ttag";import type { QueryEditorUiOptions } from "metabase/querying/editor/types";import type { Database } from "metabase-types/api";-import { doesDatabaseSupportTransforms } from "../../utils";+import { doesDatabaseSupportTransforms, validateDatabase } from "../../utils";export function getEditorOptions(databases: Database[],@@ -41,6 +41,25 @@ export function getEditorOptions(return false;},+ getDataPickerItemTooltip: (item) => {+ if (item.model === "database") {+ const database = databases.find((db) => db.id === item.id);+ return database ? validateDatabase(database).message : undefined;+ }++ if (+ item.model === "card" ||+ item.model === "dataset" ||+ item.model === "metric" ||+ item.model === "table"+ ) {+ const databaseId = "db_id" in item ? item.db_id : item.database_id;+ const database = databases.find((db) => db.id === databaseId);+ return database ? validateDatabase(database).message : undefined;+ }++ return undefined;+ },shouldShowLibrary: false,readOnly,};diff --git a/frontend/src/metabase/transforms/components/TransformEditor/utils.unit.spec.ts b/frontend/src/metabase/transforms/components/TransformEditor/utils.unit.spec.tsnew file mode 100644index 00000000000..573426f0d97--- /dev/null+++ b/frontend/src/metabase/transforms/components/TransformEditor/utils.unit.spec.ts@@ -0,0 +1,120 @@+import { createMockDatabase } from "metabase-types/api/mocks";++import { getEditorOptions } from "./utils";++const DB_ROUTING_TOOLTIP =+ "Transforms can't be enabled when database routing is enabled.";+const UNSUPPORTED_DB_TOOLTIP = "Transforms can't be enabled on this database.";++function createTransformCapableDatabase(opts = {}) {+ return createMockDatabase({+ features: ["transforms/table"],+ router_user_attribute: null,+ router_database_id: null,+ ...opts,+ });+}++describe("getEditorOptions", () => {+ describe("getDataPickerItemTooltip", () => {+ it("returns a tooltip for a database item with DB routing enabled via router_user_attribute", () => {+ const database = createTransformCapableDatabase({+ id: 1,+ router_user_attribute: "tenant_id",+ });+ const options = getEditorOptions([database]);++ const tooltip = options.getDataPickerItemTooltip?.({+ model: "database",+ id: 1,+ name: "Routed DB",+ });++ expect(tooltip).toBe(DB_ROUTING_TOOLTIP);+ });++ it("returns a tooltip for a database item with DB routing enabled via router_database_id", () => {+ const database = createTransformCapableDatabase({+ id: 2,+ router_database_id: 99,+ });+ const options = getEditorOptions([database]);++ const tooltip = options.getDataPickerItemTooltip?.({+ model: "database",+ id: 2,+ name: "Routing Destination DB",+ });++ expect(tooltip).toBe(DB_ROUTING_TOOLTIP);+ });++ it("returns a tooltip for a database that does not support transforms", () => {+ const database = createMockDatabase({ id: 3, features: [] });+ const options = getEditorOptions([database]);++ const tooltip = options.getDataPickerItemTooltip?.({+ model: "database",+ id: 3,+ name: "H2 DB",+ });++ expect(tooltip).toBe(UNSUPPORTED_DB_TOOLTIP);+ });++ it("returns undefined for a transform-capable database", () => {+ const database = createTransformCapableDatabase({ id: 4 });+ const options = getEditorOptions([database]);++ const tooltip = options.getDataPickerItemTooltip?.({+ model: "database",+ id: 4,+ name: "Normal DB",+ });++ expect(tooltip).toBeUndefined();+ });++ it("returns undefined for an unknown database id", () => {+ const database = createMockDatabase({ id: 1 });+ const options = getEditorOptions([database]);++ const tooltip = options.getDataPickerItemTooltip?.({+ model: "database",+ id: 999,+ name: "Unknown DB",+ });++ expect(tooltip).toBeUndefined();+ });++ it("returns a tooltip for a table item whose database has DB routing", () => {+ const database = createTransformCapableDatabase({+ id: 5,+ router_user_attribute: "org_id",+ });+ const options = getEditorOptions([database]);++ const tooltip = options.getDataPickerItemTooltip?.({+ model: "table",+ id: 10,+ database_id: 5,+ name: "My Table",+ });++ expect(tooltip).toBe(DB_ROUTING_TOOLTIP);+ });++ it("returns undefined for dashboard items", () => {+ const options = getEditorOptions([]);++ const tooltip = options.getDataPickerItemTooltip?.({+ model: "dashboard",+ id: 1,+ name: "My Dashboard",+ });++ expect(tooltip).toBeUndefined();+ });+ });+});