Skip to content

Commit

Permalink
[Workspace]Hide saved object import button when user is outside works…
Browse files Browse the repository at this point in the history
…pace (#7989) (#8014)

* Hide saved object import button when user is outside workpace

* Changeset file for PR #7989 created/updated

---------

(cherry picked from commit 35be041)

Signed-off-by: yubonluo <yubonluo@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Co-authored-by: Yulong Ruan <ruanyl@amazon.com>
(cherry picked from commit 81ccf48)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Sep 6, 2024
1 parent 263cf25 commit b737f60
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 22 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/7989.yml
Original file line number Diff line number Diff line change
@@ -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))

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const defaultProps = {
useUpdatedUX: false,
navigationUI: { HeaderControl: () => null, TopNavMenu: () => null },
applications: applicationServiceMock.createStartContract(),
showImportButton: true,
};

describe('Header', () => {
Expand Down Expand Up @@ -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(<Header {...props} />);

expect(component.find('EuiButtonEmpty[data-test-subj="importObjects"]').exists()).toBe(true);

const newUxProps = {
...defaultProps,
showImportButton: true,
useUpdatedUX: true,
};

const newUxComponent = shallow(<Header {...newUxProps} />);

expect(newUxComponent).toMatchSnapshot();
});

it('should not render `Import` button outside a workspace', () => {
const props = {
...defaultProps,
showImportButton: false,
};

const component = shallow(<Header {...props} />);

expect(component.find('EuiButtonEmpty[data-test-subj="importObjects"]').exists()).toBe(false);

const newUxProps = {
...defaultProps,
showImportButton: true,
useUpdatedUX: false,
};

const newUxComponent = shallow(<Header {...newUxProps} />);

expect(newUxComponent.find('EuiButtonEmpty[data-test-subj="importObjects"]').exists()).toBe(
true
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const Header = ({
navigationUI: { HeaderControl },
applications,
currentWorkspaceName,
showImportButton,
}: {
onExportAll: () => void;
onImport: () => void;
Expand All @@ -67,6 +68,7 @@ export const Header = ({
navigationUI: NavigationPublicPluginStart['ui'];
applications: ApplicationStart;
currentWorkspaceName: string;
showImportButton: boolean;
}) => {
const title = useUpdatedUX ? null : (
<EuiFlexItem grow={false}>
Expand Down Expand Up @@ -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}
/>
Expand Down Expand Up @@ -187,19 +196,21 @@ export const Header = ({
/>
</EuiButtonEmpty>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButtonEmpty
size="s"
iconType="importAction"
data-test-subj="importObjects"
onClick={onImport}
>
<FormattedMessage
id="savedObjectsManagement.objectsTable.header.importButtonLabel"
defaultMessage="Import"
/>
</EuiButtonEmpty>
</EuiFlexItem>
{showImportButton && (
<EuiFlexItem grow={false}>
<EuiButtonEmpty
size="s"
iconType="importAction"
data-test-subj="importObjects"
onClick={onImport}
>
<FormattedMessage
id="savedObjectsManagement.objectsTable.header.importButtonLabel"
defaultMessage="Import"
/>
</EuiButtonEmpty>
</EuiFlexItem>
)}
<EuiFlexItem grow={false}>
<EuiButtonEmpty size="s" iconType="refresh" onClick={onRefresh}>
<FormattedMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,7 @@ export class SavedObjectsTable extends Component<SavedObjectsTableProps, SavedOb
navigationUI={navigationUI}
applications={applications}
currentWorkspaceName={currentWorkspace?.name}
showImportButton={!workspaceEnabled || !!currentWorkspace}
/>
{!useUpdatedUX && <EuiSpacer size="xs" />}
<RedirectAppLinks application={applications}>
Expand Down

0 comments on commit b737f60

Please sign in to comment.