From ea44d259b104106a3a23e2348c284db161cc45dd Mon Sep 17 00:00:00 2001 From: yubonluo Date: Wed, 4 Sep 2024 17:43:17 +0800 Subject: [PATCH 1/2] Hide saved object import button when user is outside workpace Signed-off-by: yubonluo --- .../saved_objects_table.test.tsx.snap | 1 + .../__snapshots__/header.test.tsx.snap | 44 +++++++++++++++ .../objects_table/components/header.test.tsx | 45 +++++++++++++++ .../objects_table/components/header.tsx | 55 +++++++++++-------- .../objects_table/saved_objects_table.tsx | 1 + 5 files changed, 124 insertions(+), 22 deletions(-) diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/__snapshots__/saved_objects_table.test.tsx.snap b/src/plugins/saved_objects_management/public/management_section/objects_table/__snapshots__/saved_objects_table.test.tsx.snap index 799535aec1c7..c3ba3dfea905 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/__snapshots__/saved_objects_table.test.tsx.snap +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/__snapshots__/saved_objects_table.test.tsx.snap @@ -1042,6 +1042,7 @@ exports[`SavedObjectsTable should render normally 1`] = ` onExportAll={[Function]} onImport={[Function]} onRefresh={[Function]} + showImportButton={true} /> + + + + + + +`; + exports[`Header should render normally 1`] = ` null, TopNavMenu: () => null }, applications: applicationServiceMock.createStartContract(), + showImportButton: true, }; describe('Header', () => { @@ -92,4 +93,48 @@ describe('Header - workspace enabled', () => { expect(component.find('EuiButtonEmpty[data-test-subj="duplicateObjects"]').exists()).toBe(true); }); + + it('should render `Import` button inside a workspace', () => { + const props = { + ...defaultProps, + showImportButton: true, + }; + + const component = shallow(
); + + expect(component.find('EuiButtonEmpty[data-test-subj="importObjects"]').exists()).toBe(true); + + const newUxProps = { + ...defaultProps, + showImportButton: true, + useUpdatedUX: true, + }; + + const newUxComponent = shallow(
); + + expect(newUxComponent).toMatchSnapshot(); + }); + + it('should not render `Import` button outside a workspace', () => { + const props = { + ...defaultProps, + showImportButton: false, + }; + + const component = shallow(
); + + expect(component.find('EuiButtonEmpty[data-test-subj="importObjects"]').exists()).toBe(false); + + const newUxProps = { + ...defaultProps, + showImportButton: true, + useUpdatedUX: false, + }; + + const newUxComponent = shallow(
); + + expect(newUxComponent.find('EuiButtonEmpty[data-test-subj="importObjects"]').exists()).toBe( + true + ); + }); }); diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/header.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/components/header.tsx index 911db61be704..9ac49f007057 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/header.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/header.tsx @@ -56,6 +56,7 @@ export const Header = ({ navigationUI: { HeaderControl }, applications, currentWorkspaceName, + showImportButton, }: { onExportAll: () => void; onImport: () => void; @@ -67,6 +68,7 @@ export const Header = ({ navigationUI: NavigationPublicPluginStart['ui']; applications: ApplicationStart; currentWorkspaceName: string; + showImportButton: boolean; }) => { const title = useUpdatedUX ? null : ( @@ -143,15 +145,22 @@ export const Header = ({ defaultMessage: 'Export all objects', }), } as TopNavControlButtonData, - { - testId: 'importObjects', - run: onImport, - controlType: 'button', - iconType: 'importAction', - label: i18n.translate('savedObjectsManagement.objectsTable.header.importButtonLabel', { - defaultMessage: 'Import', - }), - } as TopNavControlButtonData, + ...(showImportButton + ? [ + { + testId: 'importObjects', + run: onImport, + controlType: 'button', + iconType: 'importAction', + label: i18n.translate( + 'savedObjectsManagement.objectsTable.header.importButtonLabel', + { + defaultMessage: 'Import', + } + ), + } as TopNavControlButtonData, + ] + : []), ]} setMountPoint={applications.setAppRightControls} /> @@ -187,19 +196,21 @@ export const Header = ({ /> - - - - - + {showImportButton && ( + + + + + + )} {!useUpdatedUX && } From ab6f9420022371e2d80da0418f3ba750c5160394 Mon Sep 17 00:00:00 2001 From: "opensearch-changeset-bot[bot]" <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> Date: Wed, 4 Sep 2024 09:48:09 +0000 Subject: [PATCH 2/2] Changeset file for PR #7989 created/updated --- changelogs/fragments/7989.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/7989.yml diff --git a/changelogs/fragments/7989.yml b/changelogs/fragments/7989.yml new file mode 100644 index 000000000000..401774e8b711 --- /dev/null +++ b/changelogs/fragments/7989.yml @@ -0,0 +1,2 @@ +refactor: +- Hide saved object import button when user is outside workspace ([#7989](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7989)) \ No newline at end of file