Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Workspace]Hide saved object import button when user is outside workspace #7989

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading