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
fix: metabot returns null for pasted question references (#70388)
Maksym Yakubych47471f9518cd
diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.tsxindex 427cff1bb7c..90acd21ca0e 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.tsx@@ -439,7 +439,7 @@ export const useEntityData = (};export const SmartLinkComponent = memo(- ({ node }: NodeViewProps) => {+ ({ node, updateAttributes }: NodeViewProps) => {const { entityId, model, label } = node.attrs;const {@@ -455,9 +455,10 @@ export const SmartLinkComponent = memo(if (entity) {const name ="display_name" in entity ? entity.display_name : entity?.name;+ updateAttributes({ label: name });dispatch(updateMentionsCache({ entityId, model, name }));}- }, [dispatch, entity, entityId, model]);+ }, [updateAttributes, dispatch, entity, entityId, model]);const showLoading = isLoading && !entity;if (showLoading) {diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.unit.spec.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.unit.spec.tsxindex 561b62e3d9e..4354c485bcc 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.unit.spec.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.unit.spec.tsx@@ -28,21 +28,27 @@ function createProps(model: SuggestionModel,entity: SmartLinkEntity | { id: number; label?: string },label?: string,+ updateAttributes?: NodeViewProps["updateAttributes"],) {const node = { attrs: { entityId: entity.id, model, label } };- return { node } as unknown as NodeViewProps;+ return {+ node,+ updateAttributes: updateAttributes ?? jest.fn(),+ } as unknown as NodeViewProps;}function setup({entity,model,label,+ updateAttributes,}: {model: SuggestionModel;entity: SmartLinkEntity;label?: string;+ updateAttributes?: NodeViewProps["updateAttributes"];}) {- const props = createProps(model, entity, label);+ const props = createProps(model, entity, label, updateAttributes);renderWithProviders(<SmartLinkComponent {...props} />);}@@ -61,6 +67,25 @@ describe("SmartLink", () => {expect(await screen.findByText("Network Card Name")).toBeInTheDocument();expect(screen.queryByText("Cached Card Name")).not.toBeInTheDocument();});++ it("updates missing labels for pasted smart links", async () => {+ const card = createMockCard({ id: 123, name: "Network Card Name" });+ const updateAttributes = jest.fn();++ setupCardEndpoints(card);+ setup({+ model: "card",+ entity: card,+ label: undefined,+ updateAttributes,+ });++ await waitFor(() => {+ expect(updateAttributes).toHaveBeenCalledWith({+ label: "Network Card Name",+ });+ });+ });});describe("for Card", () => {