From b737f600f51e0432c188f9991e80468612cc818b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 6 Sep 2024 02:49:20 +0000 Subject: [PATCH] [Workspace]Hide saved object import button when user is outside workspace (#7989) (#8014) * Hide saved object import button when user is outside workpace * Changeset file for PR #7989 created/updated --------- (cherry picked from commit 35be04155e80253364deb829197a224a3b49be3c) Signed-off-by: yubonluo Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> Co-authored-by: Yulong Ruan (cherry picked from commit 81ccf4859f3ef6b7f3ed92e4cd4cc8bdfcc183d4) Signed-off-by: github-actions[bot] --- changelogs/fragments/7989.yml | 2 + .../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 + 6 files changed, 126 insertions(+), 22 deletions(-) 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 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 && }