Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Fix search with documents (#65000)

Alexander Polyankin5b8a0877549d
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/DependencyGraph.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/DependencyGraph.tsx
index 5f013a3c180..8bddb6ec702 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/DependencyGraph.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/DependencyGraph.tsx
@@ -19,6 +19,7 @@ import type { DependencyEntry } from "metabase-types/api";
import S from "./DependencyGraph.module.css";
import { GraphContext } from "./GraphContext";
import { GraphDependencyPanel } from "./GraphDependencyPanel";
+import { GraphEdge } from "./GraphEdge";
import { GraphEntryInput } from "./GraphEntryInput";
import { GraphInfoPanel } from "./GraphInfoPanel";
import { GraphNode } from "./GraphNode";
@@ -32,11 +33,21 @@ const NODE_TYPES = {
node: GraphNode,
};
+const EDGE_TYPES = {
+ edge: GraphEdge,
+};
+
type DependencyGraphProps = {
entry?: DependencyEntry;
+ getGraphUrl: (entry?: DependencyEntry) => string;
+ withEntryPicker?: boolean;
};
-export function DependencyGraph({ entry }: DependencyGraphProps) {
+export function DependencyGraph({
+ entry,
+ getGraphUrl,
+ withEntryPicker,
+}: DependencyGraphProps) {
const {
data: graph,
isFetching,
@@ -48,13 +59,11 @@ export function DependencyGraph({ entry }: DependencyGraphProps) {
const { sendErrorToast } = useMetadataToasts();
const entryNode = useMemo(() => {
- return entry != null ? findNode(nodes, entry.id, entry.type) : null;
+ return entry != null ? findNode(nodes, entry) : null;
}, [nodes, entry]);
const selectedNode = useMemo(() => {
- return selection != null
- ? findNode(nodes, selection.id, selection.type)
- : null;
+ return selection != null ? findNode(nodes, selection) : null;
}, [nodes, selection]);
useEffect(() => {
@@ -87,6 +96,7 @@ export function DependencyGraph({ entry }: DependencyGraphProps) {
nodes={nodes}
edges={edges}
nodeTypes={NODE_TYPES}
+ edgeTypes={EDGE_TYPES}
fitView
minZoom={MIN_ZOOM}
maxZoom={MAX_ZOOM}
@@ -99,24 +109,29 @@ export function DependencyGraph({ entry }: DependencyGraphProps) {
<GraphNodeLayout />
<Panel position="top-left">
<Group>
- <GraphEntryInput
- node={entryNode?.data ?? null}
- isGraphFetching={isFetching}
- />
+ {withEntryPicker && (
+ <GraphEntryInput
+ node={entryNode?.data ?? null}
+ isGraphFetching={isFetching}
+ getGraphUrl={getGraphUrl}
+ />
+ )}
{nodes.length > 1 && <GraphSelectInput nodes={nodes} />}
</Group>
</Panel>
- {selection != null && selection.withInfo && selectedNode != null && (
+ {selection != null && selectedNode != null && (
<Panel className={S.panel} position="top-right">
{selection.groupType != null ? (
<GraphDependencyPanel
node={selectedNode.data}
groupType={selection.groupType}
+ getGraphUrl={getGraphUrl}
onClose={handlePanelClose}
/>
) : (
<GraphInfoPanel
node={selectedNode.data}
+ getGraphUrl={getGraphUrl}
onClose={handlePanelClose}
/>
)}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/GraphDependencyPanel.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/GraphDependencyPanel.tsx
index 88a21d0029b..207edcd26fa 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/GraphDependencyPanel.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/GraphDependencyPanel.tsx
@@ -6,7 +6,11 @@ import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErr
import { SEARCH_DEBOUNCE_DURATION } from "metabase/lib/constants";
import { Box, Card } from "metabase/ui";
import { useListNodeDependentsQuery } from "metabase-enterprise/api";
-import type { DependencyGroupType, DependencyNode } from "metabase-types/api";
+import type {
+ DependencyEntry,
+ DependencyGroupType,
+ DependencyNode,
+} from "metabase-types/api";
import { DEPENDENTS_SEARCH_THRESHOLD } from "../constants";
@@ -25,12 +29,14 @@ import {
type GraphDependencyPanelProps = {
node: DependencyNode;
groupType: DependencyGroupType;
+ getGraphUrl: (entry: DependencyEntry) => string;
onClose: () => void;
};
export function GraphDependencyPanel({
node,
groupType,
+ getGraphUrl,
onClose,
}: GraphDependencyPanelProps) {
const {
@@ -83,7 +89,7 @@ export function GraphDependencyPanel({
{t`Didn't find any results`}
</Box>
) : (
- <PanelBody nodes={visibleNodes} />
+ <PanelBody nodes={visibleNodes} getGraphUrl={getGraphUrl} />
)}
</Card>
);
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelBody/PanelBody.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelBody/PanelBody.tsx
index 8a7936cd2b6..9ad0f0ae553 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelBody/PanelBody.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelBody/PanelBody.tsx
@@ -1,8 +1,7 @@
import { memo } from "react";
-import * as Urls from "metabase/lib/urls";
import { Box, Group, Stack } from "metabase/ui";
-import type { DependencyNode } from "metabase-types/api";
+import type { DependencyEntry, DependencyNode } from "metabase-types/api";
import { GraphBreadcrumbs } from "../../GraphBreadcrumbs";
import { GraphExternalLink } from "../../GraphExternalLink";
@@ -21,13 +20,21 @@ import { getNodeViewCountLabel } from "./utils";
type PanelBodyProps = {
nodes: DependencyNode[];
+ getGraphUrl: (entry: DependencyEntry) => string;
};
-export const PanelBody = memo(function ListBody({ nodes }: PanelBodyProps) {
+export const PanelBody = memo(function ListBody({
+ nodes,
+ getGraphUrl,
+}: PanelBodyProps) {
return (
<Box className={S.body}>
{nodes.map((node) => (
- <ListItem key={getNodeId(node.id, node.type)} node={node} />
+ <ListItem
+ key={getNodeId(node.id, node.type)}
+ node={node}
+ getGraphUrl={getGraphUrl}
+ />
))}
</Box>
);
@@ -35,9 +42,10 @@ export const PanelBody = memo(function ListBody({ nodes }: PanelBodyProps) {
type ListItemProps = {
node: DependencyNode;
+ getGraphUrl: (entry: DependencyEntry) => string;
};
-function ListItem({ node }: ListItemProps) {
+function ListItem({ node, getGraphUrl }: ListItemProps) {
const label = getNodeLabel(node);
const link = getNodeLink(node);
const location = getNodeLocationInfo(node);
@@ -49,7 +57,7 @@ function ListItem({ node }: ListItemProps) {
<GraphLink
label={label}
icon={getNodeIcon(node)}
- url={Urls.dependencyGraph({ entry: node })}
+ url={getGraphUrl(node)}
/>
{viewCount != null ? (
<Box c="text-secondary" fz="sm" lh="1rem">
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEdge/GraphEdge.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEdge/GraphEdge.tsx
new file mode 100644
index 00000000000..1f5337a4699
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEdge/GraphEdge.tsx
@@ -0,0 +1,15 @@
+import { BezierEdge, type EdgeProps, useNodesInitialized } from "@xyflow/react";
+
+export function GraphEdge({ style, ...props }: EdgeProps) {
+ const isInitialized = useNodesInitialized();
+
+ return (
+ <BezierEdge
+ {...props}
+ style={{
+ ...style,
+ visibility: !isInitialized ? "hidden" : undefined,
+ }}
+ />
+ );
+}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEdge/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEdge/index.ts
new file mode 100644
index 00000000000..8d0cf6131ce
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEdge/index.ts
@@ -0,0 +1 @@
+export * from "./GraphEdge";
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntryButton/EntryButton.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntryButton/EntryButton.tsx
index df128ad831a..f36b0c53a76 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntryButton/EntryButton.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntryButton/EntryButton.tsx
@@ -8,7 +8,7 @@ import { getNodeIcon, getNodeLabel } from "../../utils";
type EntryButtonProps = {
node: DependencyNode | null;
- onEntryChange: (entry: DependencyEntry | null) => void;
+ onEntryChange: (entry: DependencyEntry | undefined) => void;
onPickerOpen: () => void;
};
@@ -19,7 +19,7 @@ export function EntryButton({
}: EntryButtonProps) {
const handleIconClick = (event: MouseEvent) => {
event.stopPropagation();
- onEntryChange(null);
+ onEntryChange(undefined);
};
return (
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntrySearchInput/SearchModelPicker/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntrySearchInput/SearchModelPicker/utils.ts
index 3e246f186e1..0a717a552ce 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntrySearchInput/SearchModelPicker/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/EntrySearchInput/SearchModelPicker/utils.ts
@@ -17,7 +17,7 @@ export function getSearchModelItems(data: SearchResponse): SearchModelItem[] {
dataset: t`Models`,
metric: t`Metrics`,
dashboard: t`Dashboards`,
- document: t`Transforms`,
+ document: t`Documents`,
};
const allItems = ENABLED_SEARCH_MODELS.map((model) => ({
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/GraphEntryInput.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/GraphEntryInput.tsx
index 7c4d42d5e89..a4ed0bd9ade 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/GraphEntryInput.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphEntryInput/GraphEntryInput.tsx
@@ -3,7 +3,6 @@ import { useState } from "react";
import { push } from "react-router-redux";
import { useDispatch } from "metabase/lib/redux";
-import * as Urls from "metabase/lib/urls";
import { Card } from "metabase/ui";
import type {
DependencyEntry,
@@ -19,11 +18,13 @@ import { SEARCH_MODELS } from "./constants";
type GraphEntryInputProps = {
node: DependencyNode | null;
isGraphFetching: boolean;
+ getGraphUrl: (entry: DependencyEntry | undefined) => string;
};
export function GraphEntryInput({
node,
isGraphFetching,
+ getGraphUrl,
}: GraphEntryInputProps) {
const [searchModels, setSearchModels] =
useState<SearchModel[]>(SEARCH_MODELS);
@@ -31,8 +32,8 @@ export function GraphEntryInput({
const [isPickerOpened, { open: openPicker, close: closePicker }] =
useDisclosure();
- const handleEntryChange = (newEntry: DependencyEntry | null) => {
- dispatch(push(Urls.dependencyGraph(newEntry ? { entry: newEntry } : {})));
+ const handleEntryChange = (newEntry: DependencyEntry | undefined) => {
+ dispatch(push(getGraphUrl(newEntry)));
};
const handlePickerChange = (newEntry: DependencyEntry) => {
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/GraphInfoPanel.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/GraphInfoPanel.tsx
index 94a15797807..97d4c48ecc0 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/GraphInfoPanel.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/GraphInfoPanel.tsx
@@ -1,5 +1,5 @@
import { Card } from "metabase/ui";
-import type { DependencyNode } from "metabase-types/api";
+import type { DependencyEntry, DependencyNode } from "metabase-types/api";
import S from "./GraphInfoPanel.module.css";
import { PanelBody } from "./PanelBody";
@@ -7,14 +7,19 @@ import { PanelHeader } from "./PanelHeader";
type GraphInfoPanelProps = {
node: DependencyNode;
+ getGraphUrl: (entry: DependencyEntry) => string;
onClose: () => void;
};
-export function GraphInfoPanel({ node, onClose }: GraphInfoPanelProps) {
+export function GraphInfoPanel({
+ node,
+ getGraphUrl,
+ onClose,
+}: GraphInfoPanelProps) {
return (
<Card className={S.root} withBorder data-testid="graph-info-panel">
<PanelHeader node={node} onClose={onClose} />
- <PanelBody node={node} />
+ <PanelBody node={node} getGraphUrl={getGraphUrl} />
</Card>
);
}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/PanelBody.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/PanelBody.tsx
index 12e9184a87b..c92bbcc4a1d 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/PanelBody.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/PanelBody.tsx
@@ -5,7 +5,7 @@ import { getColumnIcon } from "metabase/common/utils/columns";
import { getUserName } from "metabase/lib/user";
import { Box, FixedSizeIcon, Group, Stack, Title } from "metabase/ui";
import * as Lib from "metabase-lib";
-import type { DependencyNode } from "metabase-types/api";
+import type { DependencyEntry, DependencyNode } from "metabase-types/api";
import { GraphBreadcrumbs } from "../../GraphBreadcrumbs";
import { GraphExternalLink } from "../../GraphExternalLink";
@@ -25,14 +25,15 @@ import {
type PanelBodyProps = {
node: DependencyNode;
+ getGraphUrl: (entry: DependencyEntry) => string;
};
-export function PanelBody({ node }: PanelBodyProps) {
+export function PanelBody({ node, getGraphUrl }: PanelBodyProps) {
return (
<Stack className={S.body} p="lg" gap="lg">
<DescriptionSection node={node} />
<CreatorAndLastEditorSection node={node} />
- <TableSection node={node} />
+ <TableSection node={node} getGraphUrl={getGraphUrl} />
<FieldsSection node={node} />
</Stack>
);
@@ -98,8 +99,13 @@ function CreatorAndLastEditorSection({ node }: SectionProps) {
);
}
-function TableSection({ node }: SectionProps) {
- const info = getNodeTableInfo(node);
+type TableSectionProps = {
+ node: DependencyNode;
+ getGraphUrl: (entry: DependencyEntry) => string;
+};
+
+function TableSection({ node, getGraphUrl }: TableSectionProps) {
+ const info = getNodeTableInfo(node, getGraphUrl);
if (info == null) {
return null;
}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/utils.ts
index e6946167fdd..9d94039b13d 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphInfoPanel/PanelBody/utils.ts
@@ -3,6 +3,7 @@ import { msgid, ngettext, t } from "ttag";
import * as Urls from "metabase/lib/urls";
import type {
CardCreatorInfo,
+ DependencyEntry,
DependencyNode,
Field,
LastEditInfo,
@@ -66,7 +67,10 @@ export function getNodeLastEditedBy(node: DependencyNode): LastEditInfo | null {
}
}
-export function getNodeTableInfo(node: DependencyNode): NodeTableInfo | null {
+export function getNodeTableInfo(
+ node: DependencyNode,
+ getGraphUrl: (entry: DependencyEntry) => string,
+): NodeTableInfo | null {
if (node.type !== "transform" && node.type !== "sandbox") {
return null;
}
@@ -80,7 +84,7 @@ export function getNodeTableInfo(node: DependencyNode): NodeTableInfo | null {
label: node.type === "transform" ? t`Generated table` : t`Restricted table`,
title: {
label: table.display_name,
- url: Urls.dependencyGraph({ entry: { id: table.id, type: "table" } }),
+ url: getGraphUrl({ id: table.id, type: "table" }),
},
metadata: {
label: t`View metadata`,
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/GraphNode.module.css b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/GraphNode.module.css
index 99cf557f84a..b30b12989f5 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/GraphNode.module.css
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/GraphNode.module.css
@@ -7,6 +7,15 @@
}
}
+.card,
+.handle {
+ visibility: hidden;
+
+ &.initialized {
+ visibility: visible;
+ }
+}
+
.pill {
color: var(--mb-color-text-primary);
background-color: var(--mb-color-bg-medium);
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/GraphNode.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/GraphNode.tsx
index 8ee586b0add..68ed2f34d6a 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/GraphNode.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/GraphNode.tsx
@@ -3,6 +3,7 @@ import {
type NodeProps,
Position,
useNodeConnections,
+ useNodesInitialized,
} from "@xyflow/react";
import cx from "classnames";
import { type MouseEvent, memo, useContext } from "react";
@@ -46,17 +47,20 @@ export const GraphNode = memo(function ItemNode({
const groups = getDependentGroups(node);
const sources = useNodeConnections({ handleType: "source" });
const targets = useNodeConnections({ handleType: "target" });
- const isSelected =
- selection != null && isSameNode(node, selection.id, selection.type);
+ const isSelected = selection != null && isSameNode(node, selection);
+ const isInitialized = useNodesInitialized();
const handleClick = () => {
- setSelection({ id: node.id, type: node.type, withInfo: true });
+ setSelection({ id: node.id, type: node.type });
};
return (
<>
<Card
- className={cx(S.card, { [S.selected]: isSelected })}
+ className={cx(S.card, {
+ [S.initialized]: isInitialized,
+ [S.selected]: isSelected,
+ })}
p="lg"
withBorder
aria-label={label}
@@ -91,10 +95,20 @@ export const GraphNode = memo(function ItemNode({
</Stack>
</Card>
{sources.length > 0 && (
- <Handle type="source" position={Position.Left} isConnectable={false} />
+ <Handle
+ className={cx(S.handle, { [S.initialized]: isInitialized })}
+ type="source"
+ position={Position.Left}
+ isConnectable={false}
+ />
)}
{targets.length > 0 && (
- <Handle type="target" position={Position.Right} isConnectable={false} />
+ <Handle
+ className={cx(S.handle, { [S.initialized]: isInitialized })}
+ type="target"
+ position={Position.Right}
+ isConnectable={false}
+ />
)}
</>
);
@@ -115,7 +129,7 @@ function DependencyGroupButton({
}: DependencyGroupButtonProps) {
const isSelected =
selection != null &&
- isSameNode(node, selection.id, selection.type) &&
+ isSameNode(node, selection) &&
selection.groupType === group.type;
const handleClick = (event: MouseEvent) => {
@@ -124,7 +138,6 @@ function DependencyGroupButton({
id: node.id,
type: node.type,
groupType: group.type,
- withInfo: true,
});
};
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/utils.ts
index 030b7f1b8b3..10f36d17436 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphNode/utils.ts
@@ -36,15 +36,15 @@ export function getDependencyGroupTitle(
node: DependencyNode,
groups: DependentGroup[],
) {
- if (node.type === "transform") {
- return t`Generates`;
- }
if (node.type === "sandbox") {
return t`Restricts table data`;
}
if (groups.length === 0) {
return t`Nothing uses this`;
}
+ if (node.type === "transform") {
+ return t`Generates`;
+ }
return t`Used by`;
}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/types.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/types.ts
index 086a3d922c3..abb31a0c5bf 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/types.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/types.ts
@@ -30,7 +30,6 @@ export type GraphSelection = {
id: DependencyId;
type: DependencyType;
groupType?: DependencyGroupType;
- withInfo?: boolean;
};
export type GraphContextType = {
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/utils.ts
index e04089f0ebf..d259efdbdf1 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/utils.ts
@@ -7,6 +7,7 @@ import visualizations from "metabase/visualizations";
import type {
CardType,
DependencyEdge,
+ DependencyEntry,
DependencyGraph,
DependencyGroupType,
DependencyId,
@@ -54,6 +55,7 @@ function getEdges(edges: DependencyEdge[]): Edge[] {
return {
id: getEdgeId(sourceId, targetId),
+ type: "edge",
data: edge,
source: sourceId,
target: targetId,
@@ -71,19 +73,17 @@ export function getInitialGraph({ nodes, edges }: DependencyGraph): GraphData {
}
export function isSameNode(
- node: DependencyNode,
- id: DependencyId,
- type: DependencyType,
+ entry1: DependencyEntry,
+ entry2: DependencyEntry,
): boolean {
- return node.id === id && node.type === type;
+ return entry1.id === entry2.id && entry1.type === entry2.type;
}
export function findNode(
nodes: NodeType[],
- id: DependencyId,
- type: DependencyType,
-): NodeType | null {
- return nodes.find((node) => isSameNode(node.data, id, type)) ?? null;
+ entry: DependencyEntry,
+): NodeType | undefined {
+ return nodes.find((node) => isSameNode(node.data, entry));
}
export function getNodeLabel(node: DependencyNode): string {
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/hooks/use-check-dependencies/use-check-dependencies.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/hooks/use-check-dependencies/use-check-dependencies.ts
index a6dde0a6987..b38fb7eb658 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/hooks/use-check-dependencies/use-check-dependencies.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/hooks/use-check-dependencies/use-check-dependencies.ts
@@ -6,7 +6,7 @@ import type { CheckDependenciesResponse } from "metabase-types/api";
type UseCheckDependenciesQueryData = {
data?: CheckDependenciesResponse;
error?: unknown;
- isLoading: boolean;
+ isFetching?: boolean;
};
type UseCheckDependenciesArgsData<TRequest> = {
@@ -35,7 +35,7 @@ export function useCheckDependencies<TChange, TRequest>({
>): UseCheckDependenciesResult<TChange> {
const [change, setChange] = useState<TChange | null>(null);
const [isConfirmationShown, setIsConfirmationShown] = useState(false);
- const [checkDependencies, { data, isLoading }] =
+ const [checkDependencies, { data, isFetching = false }] =
useLazyCheckDependenciesQuery();
const handleInitialSave = useCallback(
@@ -70,7 +70,7 @@ export function useCheckDependencies<TChange, TRequest>({
return {
checkData: data,
- isCheckingDependencies: isLoading,
+ isCheckingDependencies: isFetching,
isConfirmationShown,
handleInitialSave,
handleSaveAfterConfirmation,
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/index.ts
index 39e00eb354b..1c98d9b17a3 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/index.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/index.ts
@@ -10,7 +10,8 @@ import { useCheckTransformDependencies } from "./hooks/use-check-transform-depen
import { DependencyGraphPage } from "./pages/DependencyGraphPage";
if (hasPremiumFeature("dependencies")) {
- PLUGIN_DEPENDENCIES.isEnabled = true;
+ // TODO Alex P re-enable after v57
+ PLUGIN_DEPENDENCIES.isEnabled = false;
PLUGIN_DEPENDENCIES.DependencyGraphPage = DependencyGraphPage;
PLUGIN_DEPENDENCIES.CheckDependenciesForm = CheckDependenciesForm;
PLUGIN_DEPENDENCIES.CheckDependenciesModal = CheckDependenciesModal;
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyGraphPage/DependencyGraphPage.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyGraphPage/DependencyGraphPage.tsx
index 9fb0f63c5f2..30bf15b1c9a 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyGraphPage/DependencyGraphPage.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyGraphPage/DependencyGraphPage.tsx
@@ -1,13 +1,36 @@
+import type { Location } from "history";
+import { useContext } from "react";
+
+import * as Urls from "metabase/lib/urls";
+import { PLUGIN_DEPENDENCIES } from "metabase/plugins";
+
import { DependencyGraph } from "../../components/DependencyGraph";
-import type { DependencyGraphRawParams } from "../../types";
+import { isSameNode } from "../../components/DependencyGraph/utils";
-import { parseParams } from "./utils";
+import { parseDependencyEntry } from "./utils";
+
+export type DependencyGraphPageQuery = {
+ id?: string;
+ type?: string;
+};
type DependencyGraphPageProps = {
- params?: DependencyGraphRawParams;
+ location?: Location<DependencyGraphPageQuery>;
};
-export function DependencyGraphPage({ params }: DependencyGraphPageProps) {
- const { entry } = parseParams(params);
- return <DependencyGraph entry={entry} />;
+export function DependencyGraphPage({ location }: DependencyGraphPageProps) {
+ const entry = parseDependencyEntry(location?.query?.id, location?.query.type);
+ const { defaultEntry, baseUrl } = useContext(
+ PLUGIN_DEPENDENCIES.DependencyGraphPageContext,
+ );
+ const withEntryPicker =
+ defaultEntry == null || (entry != null && !isSameNode(entry, defaultEntry));
+
+ return (
+ <DependencyGraph
+ entry={entry ?? defaultEntry}
+ getGraphUrl={(entry) => Urls.dependencyGraph({ entry, baseUrl })}
+ withEntryPicker={withEntryPicker}
+ />
+ );
}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyGraphPage/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyGraphPage/utils.ts
index c567760df90..578a456c5c8 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyGraphPage/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyGraphPage/utils.ts
@@ -1,19 +1,16 @@
import * as Urls from "metabase/lib/urls";
-import type { DependencyType } from "metabase-types/api";
+import type { DependencyEntry, DependencyType } from "metabase-types/api";
-import type { DependencyGraphRawParams } from "../../types";
-
-export function parseParams(
- params: DependencyGraphRawParams = {},
-): Urls.DependencyGraphParams {
- const id = Urls.extractEntityId(params.id);
- const type = parseDependencyType(params.type);
- return {
- entry: id != null && type != null ? { id, type } : undefined,
- };
+export function parseDependencyEntry(
+ rawId?: string,
+ rawType?: string,
+): DependencyEntry | undefined {
+ const id = Urls.extractEntityId(rawId);
+ const type = parseDependencyType(rawType);
+ return id != null && type != null ? { id, type } : undefined;
}
-function parseDependencyType(type: unknown): DependencyType | null {
+function parseDependencyType(type: unknown): DependencyType | undefined {
switch (type) {
case "card":
case "table":
@@ -24,6 +21,6 @@ function parseDependencyType(type: unknown): DependencyType | null {
case "sandbox":
return type;
default:
- return null;
+ return undefined;
}
}
diff --git a/frontend/src/metabase/admin/routes.jsx b/frontend/src/metabase/admin/routes.jsx
index 2c1148b6d91..dcf0da01946 100644
--- a/frontend/src/metabase/admin/routes.jsx
+++ b/frontend/src/metabase/admin/routes.jsx
@@ -48,6 +48,7 @@ import {
PLUGIN_ADMIN_USER_MENU_ROUTES,
PLUGIN_CACHING,
PLUGIN_DB_ROUTING,
+ PLUGIN_DEPENDENCIES,
PLUGIN_METABOT,
PLUGIN_TRANSFORMS,
} from "metabase/plugins";
@@ -279,6 +280,12 @@ const getRoutes = (store, CanAccessSettings, IsAdmin) => (
}}
/>
</Route>
+ {PLUGIN_DEPENDENCIES.isEnabled && (
+ <Route
+ path="dependencies"
+ component={PLUGIN_DEPENDENCIES.DependencyGraphPage}
+ />
+ )}
</Route>
</Route>
</Route>
diff --git a/frontend/src/metabase/admin/tools/components/ToolsApp.tsx b/frontend/src/metabase/admin/tools/components/ToolsApp.tsx
index 36f8433e18a..f0a9ea3df7b 100644
--- a/frontend/src/metabase/admin/tools/components/ToolsApp.tsx
+++ b/frontend/src/metabase/admin/tools/components/ToolsApp.tsx
@@ -1,3 +1,5 @@
+import type { Location } from "history";
+import type { ReactNode } from "react";
import { t } from "ttag";
import {
@@ -6,60 +8,80 @@ import {
AdminNavWrapper,
} from "metabase/admin/components/AdminNav";
import { AdminSettingsLayout } from "metabase/common/components/AdminLayout/AdminSettingsLayout";
-import { useSelector } from "metabase/lib/redux";
-import { getLocation } from "metabase/selectors/routing";
+import * as Urls from "metabase/lib/urls";
+import { PLUGIN_DEPENDENCIES } from "metabase/plugins";
-export function ToolsApp({ children }: { children: React.ReactNode }) {
- {
- return (
- <AdminSettingsLayout
- maw="100rem"
- sidebar={
- <AdminNavWrapper>
- <ToolsNavItem
- label={t`Help`}
- path="/admin/tools/help"
- icon="info"
- />
- <ToolsNavItem
- label={t`Tasks`}
- path="/admin/tools/tasks"
- icon="clipboard"
- />
- <ToolsNavItem
- label={t`Jobs`}
- path="/admin/tools/jobs"
- icon="clock"
- />
- <ToolsNavItem
- label={t`Logs`}
- path="/admin/tools/logs"
- icon="audit"
- />
- <ToolsNavItem
- label={t`Erroring questions`}
- path="/admin/tools/errors"
- icon="warning_round_filled"
- />
+type ToolsAppProps = {
+ location: Location;
+ children?: ReactNode;
+};
+
+export function ToolsApp({ location, children }: ToolsAppProps) {
+ return (
+ <AdminSettingsLayout
+ maw="100rem"
+ fullWidth={location?.pathname === Urls.dependencyGraph()}
+ sidebar={
+ <AdminNavWrapper>
+ <ToolsNavItem
+ label={t`Help`}
+ path={Urls.adminToolsHelp()}
+ icon="info"
+ location={location}
+ />
+ <ToolsNavItem
+ label={t`Tasks`}
+ path={Urls.adminToolsTasks()}
+ icon="clipboard"
+ location={location}
+ />
+ <ToolsNavItem
+ label={t`Jobs`}
+ path={Urls.adminToolsJobs()}
+ icon="clock"
+ location={location}
+ />
+ <ToolsNavItem
+ label={t`Logs`}
+ path={Urls.adminToolsLogs()}
+ icon="audit"
+ location={location}
+ />
+ <ToolsNavItem
+ label={t`Erroring questions`}
+ path={Urls.adminToolsErrors()}
+ icon="warning_round_filled"
+ location={location}
+ />
+ <ToolsNavItem
+ label={t`Model cache log`}
+ path={Urls.adminToolsModelCaching()}
+ icon="database"
+ location={location}
+ />
+ {PLUGIN_DEPENDENCIES.isEnabled && (
<ToolsNavItem
- label={t`Model cache log`}
- path="/admin/tools/model-caching"
- icon="database"
+ label={t`Dependency graph`}
+ path={Urls.dependencyGraph()}
+ icon="schema"
+ location={location}
/>
- </AdminNavWrapper>
- }
- >
- {children}
- </AdminSettingsLayout>
- );
- }
+ )}
+ </AdminNavWrapper>
+ }
+ >
+ {children}
+ </AdminSettingsLayout>
+ );
}
-const ToolsNavItem = (props: AdminNavItemProps) => {
- const location = useSelector(getLocation);
- const subpath = location?.pathname;
+type ToolsNavItemProps = AdminNavItemProps & {
+ location: Location;
+};
+const ToolsNavItem = ({ location, ...props }: ToolsNavItemProps) => {
// we want to highlight the nav item even if a subpath is active
+ const subpath = location?.pathname;
const isActive = !!props.path && subpath.includes(props.path);
return <AdminNavItem {...props} active={isActive} />;
diff --git a/frontend/src/metabase/lib/urls/admin.ts b/frontend/src/metabase/lib/urls/admin.ts
index 60ce0c73a43..df46fcad4aa 100644
--- a/frontend/src/metabase/lib/urls/admin.ts
+++ b/frontend/src/metabase/lib/urls/admin.ts
@@ -71,3 +71,27 @@ export function uploadsSettings() {
export function adminLicense() {
return "/admin/settings/license";
}
+
+export function adminToolsHelp() {
+ return "/admin/tools/help";
+}
+
+export function adminToolsTasks() {
+ return "/admin/tools/tasks";
+}
+
+export function adminToolsJobs() {
+ return "/admin/tools/jobs";
+}
+
+export function adminToolsLogs() {
+ return "/admin/tools/logs";
+}
+
+export function adminToolsErrors() {
+ return "/admin/tools/errors";
+}
+
+export function adminToolsModelCaching() {
+ return "/admin/tools/model-caching";
+}
diff --git a/frontend/src/metabase/lib/urls/dependencies.ts b/frontend/src/metabase/lib/urls/dependencies.ts
index d2344008d03..8aff1ed09a7 100644
--- a/frontend/src/metabase/lib/urls/dependencies.ts
+++ b/frontend/src/metabase/lib/urls/dependencies.ts
@@ -1,11 +1,20 @@
import type { DependencyEntry } from "metabase-types/api";
-const BASE_URL = `/dependencies`;
+const BASE_URL = `/admin/tools/dependencies`;
export type DependencyGraphParams = {
entry?: DependencyEntry;
+ baseUrl?: string;
};
-export function dependencyGraph({ entry }: DependencyGraphParams) {
- return entry ? `${BASE_URL}/${entry.type}/${entry.id}` : BASE_URL;
+export function dependencyGraph({
+ entry,
+ baseUrl = BASE_URL,
+}: DependencyGraphParams = {}) {
+ const params = new URLSearchParams();
+ if (entry != null) {
+ params.set("id", String(entry.id));
+ params.set("type", entry.type);
+ }
+ return params.size > 0 ? `${baseUrl}?${params}` : baseUrl;
}
diff --git a/frontend/src/metabase/plugins/index.ts b/frontend/src/metabase/plugins/index.ts
index b64024799e1..2039513ca0b 100644
--- a/frontend/src/metabase/plugins/index.ts
+++ b/frontend/src/metabase/plugins/index.ts
@@ -2,10 +2,12 @@ import type { Middleware } from "@reduxjs/toolkit";
import type { TagDescription } from "@reduxjs/toolkit/query";
import React, {
type ComponentType,
+ type Context,
type Dispatch,
type HTMLAttributes,
type ReactNode,
type SetStateAction,
+ createContext,
useCallback,
} from "react";
import { t } from "ttag";
@@ -71,6 +73,7 @@ import type {
DatabaseLocalSettingAvailability,
Database as DatabaseType,
Dataset,
+ DependencyEntry,
Document,
Group,
GroupPermissions,
@@ -962,6 +965,7 @@ export const PLUGIN_TRANSFORMS_PYTHON: PythonTransformsPlugin = {
type DependenciesPlugin = {
isEnabled: boolean;
DependencyGraphPage: ComponentType;
+ DependencyGraphPageContext: Context<DependencyGraphPageContextType>;
CheckDependenciesForm: ComponentType<CheckDependenciesFormProps>;
CheckDependenciesModal: ComponentType<CheckDependenciesModalProps>;
CheckDependenciesTitle: ComponentType;
@@ -976,6 +980,11 @@ type DependenciesPlugin = {
) => UseCheckDependenciesResult<UpdateTransformRequest>;
};
+export type DependencyGraphPageContextType = {
+ baseUrl?: string;
+ defaultEntry?: DependencyEntry;
+};
+
export type CheckDependenciesFormProps = {
checkData: CheckDependenciesResponse;
onSave: () => void | Promise<void>;
@@ -1017,6 +1026,7 @@ function useCheckDependencies<TChange>({
export const PLUGIN_DEPENDENCIES: DependenciesPlugin = {
isEnabled: false,
DependencyGraphPage: PluginPlaceholder,
+ DependencyGraphPageContext: createContext({}),
CheckDependenciesForm: PluginPlaceholder,
CheckDependenciesModal: PluginPlaceholder,
CheckDependenciesTitle: PluginPlaceholder,