From b418d4490fff461b92394583427369f2e542de1f Mon Sep 17 00:00:00 2001 From: Tianyu Gao Date: Fri, 6 Dec 2024 04:20:36 +0800 Subject: [PATCH] Fix fetching workspace visualizations error (#2268) * fix: fix fetching workspace visualizations error Signed-off-by: tygao * fix: fix fetching workspace visualizations error Signed-off-by: tygao * test: add unit tests Signed-off-by: tygao --------- Signed-off-by: tygao Co-authored-by: Adam Tackett <105462877+TackAdam@users.noreply.github.com> --- .../__snapshots__/paragraphs.test.tsx.snap | 418 ++++++++++++++++++ .../__tests__/paragraphs.test.tsx | 83 ++++ .../paragraph_components/paragraphs.tsx | 3 - 3 files changed, 501 insertions(+), 3 deletions(-) diff --git a/public/components/notebooks/components/paragraph_components/__tests__/__snapshots__/paragraphs.test.tsx.snap b/public/components/notebooks/components/paragraph_components/__tests__/__snapshots__/paragraphs.test.tsx.snap index 03bce65939..0ea959b934 100644 --- a/public/components/notebooks/components/paragraph_components/__tests__/__snapshots__/paragraphs.test.tsx.snap +++ b/public/components/notebooks/components/paragraph_components/__tests__/__snapshots__/paragraphs.test.tsx.snap @@ -329,3 +329,421 @@ exports[` spec renders the component 1`] = ` `; + +exports[` spec use SavedObject find to fetch visualizations when dataSourceEnabled 1`] = ` +
+
+
+
+ [1] Visualization + +
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+ +
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+ +
+
+
+
+ Last successful run 11/01/2023 01:02 AM. +
+
+
+
+
+
+
+
+
+

+ Type your input here +

+
+
+
+
+
+`; diff --git a/public/components/notebooks/components/paragraph_components/__tests__/paragraphs.test.tsx b/public/components/notebooks/components/paragraph_components/__tests__/paragraphs.test.tsx index 666ca5bd1c..276898f019 100644 --- a/public/components/notebooks/components/paragraph_components/__tests__/paragraphs.test.tsx +++ b/public/components/notebooks/components/paragraph_components/__tests__/paragraphs.test.tsx @@ -18,6 +18,18 @@ jest.mock('../../../../../../../../src/plugins/embeddable/public', () => ({ }, })); +const mockFind = jest.fn().mockResolvedValue({ + savedObjects: [], +}); + +jest.mock('../../../../../framework/core_refs', () => ({ + coreRefs: { + savedObjectsClient: { + find: (options) => mockFind(options), + }, + }, +})); + describe(' spec', () => { configure({ adapter: new Adapter() }); @@ -71,4 +83,75 @@ describe(' spec', () => { utils.getByLabelText('Open paragraph menu').click(); utils.getByText('Delete').click(); }); + + it('use SavedObject find to fetch visualizations when dataSourceEnabled', () => { + const setPara = jest.fn(); + const paragraphSelector = jest.fn(); + const textValueEditor = jest.fn(); + const handleKeyPress = jest.fn(); + const addPara = jest.fn(); + const DashboardContainerByValueRenderer = jest.fn(); + const deleteVizualization = jest.fn(); + const setSelectedViewId = jest.fn(); + const deletePara = jest.fn(); + const runPara = jest.fn(); + const clonePara = jest.fn(); + const movePara = jest.fn(); + const para = { + uniqueId: 'paragraph_1a710988-ec19-4caa-83cc-38eb609427d1', + isRunning: false, + inQueue: false, + isSelected: false, + isInputHidden: false, + isOutputHidden: false, + showAddPara: false, + isVizualisation: true, + vizObjectInput: '{}', + id: 1, + inp: '# Type your input here', + isInputExpanded: false, + isOutputStale: false, + paraDivRef: undefined, + paraRef: undefined, + visEndTime: undefined, + visSavedObjId: undefined, + visStartTime: undefined, + lang: 'text/x-md', + editorLanguage: 'md', + typeOut: ['MARKDOWN'], + out: ['# Type your input here'], + }; + para.isInputExpanded = true; + const utils = render( + } }} + /> + ); + expect(utils.container.firstChild).toMatchSnapshot(); + expect(mockFind).toHaveBeenCalledWith({ + type: 'visualization', + }); + }); }); diff --git a/public/components/notebooks/components/paragraph_components/paragraphs.tsx b/public/components/notebooks/components/paragraph_components/paragraphs.tsx index a29bc0c05a..d981a282dd 100644 --- a/public/components/notebooks/components/paragraph_components/paragraphs.tsx +++ b/public/components/notebooks/components/paragraph_components/paragraphs.tsx @@ -170,9 +170,6 @@ export const Paragraphs = forwardRef((props: ParagraphProps, ref) => { let opts: EuiComboBoxOptionOption[] = []; const vizOptions: SavedObjectsFindOptions = { type: 'visualization', - ...(coreRefs.application?.capabilities?.workspaces?.enabled - ? { workspaces: coreRefs.workspaces?.currentWorkspace$.getValue()?.name } - : {}), }; await coreRefs.savedObjectsClient ?.find(vizOptions)