From f37b0d85bb7558b6dbf99ef25c1a2ff5d1cb4692 Mon Sep 17 00:00:00 2001 From: tygao Date: Thu, 28 Nov 2024 11:18:47 +0800 Subject: [PATCH 1/3] fix: fix fetching workspace visualizations error Signed-off-by: tygao --- .../notebooks/components/paragraph_components/paragraphs.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/public/components/notebooks/components/paragraph_components/paragraphs.tsx b/public/components/notebooks/components/paragraph_components/paragraphs.tsx index a29bc0c05..d981a282d 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) From dc05feb423f7617dd68a5dc64e8c808cd4a09874 Mon Sep 17 00:00:00 2001 From: tygao Date: Thu, 28 Nov 2024 11:18:47 +0800 Subject: [PATCH 2/3] fix: fix fetching workspace visualizations error Signed-off-by: tygao --- .../notebooks/components/paragraph_components/paragraphs.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/public/components/notebooks/components/paragraph_components/paragraphs.tsx b/public/components/notebooks/components/paragraph_components/paragraphs.tsx index a29bc0c05..d981a282d 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) From 38d44d2730fd721d1929b477e37f2fccafe529a0 Mon Sep 17 00:00:00 2001 From: tygao Date: Thu, 5 Dec 2024 18:08:01 +0800 Subject: [PATCH 3/3] test: add unit tests Signed-off-by: tygao --- .../__snapshots__/paragraphs.test.tsx.snap | 418 ++++++++++++++++++ .../__tests__/paragraphs.test.tsx | 83 ++++ 2 files changed, 501 insertions(+) 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 03bce6593..0ea959b93 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 666ca5bd1..276898f01 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', + }); + }); });