Skip to content

Commit afa373a

Browse files
authored
Saved objects page change (opensearch-project#123)
* hide import for application home page Signed-off-by: Hailong Cui <[email protected]> * add workpspace into gotoApp link Signed-off-by: Hailong Cui <[email protected]> * remove special logic for management workspace Signed-off-by: Hailong Cui <[email protected]> * variable name change and more UTs Signed-off-by: Hailong Cui <[email protected]> --------- Signed-off-by: Hailong Cui <[email protected]>
1 parent 56c8971 commit afa373a

File tree

9 files changed

+248
-145
lines changed

9 files changed

+248
-145
lines changed

src/plugins/saved_objects_management/public/management_section/objects_table/__snapshots__/saved_objects_table.test.tsx.snap

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/header.test.tsx.snap

Lines changed: 3 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/table.test.tsx.snap

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/plugins/saved_objects_management/public/management_section/objects_table/components/header.test.tsx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,57 @@ describe('Header', () => {
3838
onExportAll: () => {},
3939
onImport: () => {},
4040
onRefresh: () => {},
41+
onCopy: () => {},
42+
title: 'Saved Objects',
43+
selectedCount: 0,
4144
totalCount: 4,
4245
filteredCount: 2,
46+
showDuplicateAll: false,
47+
hideImport: false,
4348
};
4449

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

4752
expect(component).toMatchSnapshot();
4853
});
4954
});
55+
56+
describe('Header - workspace enabled', () => {
57+
it('should render `Duplicate All` button when workspace enabled', () => {
58+
const props = {
59+
onExportAll: () => {},
60+
onImport: () => {},
61+
onRefresh: () => {},
62+
onCopy: () => {},
63+
title: 'Saved Objects',
64+
selectedCount: 0,
65+
totalCount: 4,
66+
filteredCount: 2,
67+
showDuplicateAll: true,
68+
hideImport: false,
69+
};
70+
71+
const component = shallow(<Header {...props} />);
72+
73+
expect(component.find('EuiButtonEmpty[data-test-subj="copyObjects"]').exists()).toBe(true);
74+
});
75+
76+
it('should hide `Import` button for application home state', () => {
77+
const props = {
78+
onExportAll: () => {},
79+
onImport: () => {},
80+
onRefresh: () => {},
81+
onCopy: () => {},
82+
title: 'Saved Objects',
83+
selectedCount: 0,
84+
totalCount: 4,
85+
filteredCount: 2,
86+
showDuplicateAll: true,
87+
hideImport: true,
88+
};
89+
90+
const component = shallow(<Header {...props} />);
91+
92+
expect(component.find('EuiButtonEmpty[data-test-subj="importObjects"]').exists()).toBe(false);
93+
});
94+
});

src/plugins/saved_objects_management/public/management_section/objects_table/components/header.tsx

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ export const Header = ({
4848
filteredCount,
4949
title,
5050
selectedCount,
51+
hideImport = false,
52+
showDuplicateAll = false,
5153
}: {
5254
onExportAll: () => void;
5355
onImport: () => void;
@@ -56,6 +58,8 @@ export const Header = ({
5658
filteredCount: number;
5759
title: string;
5860
selectedCount: number;
61+
hideImport: boolean;
62+
showDuplicateAll: boolean;
5963
}) => (
6064
<Fragment>
6165
<EuiFlexGroup justifyContent="spaceBetween" alignItems="baseline">
@@ -67,19 +71,21 @@ export const Header = ({
6771

6872
<EuiFlexItem grow={false}>
6973
<EuiFlexGroup alignItems="baseline" gutterSize="m" responsive={false}>
70-
<EuiFlexItem grow={false}>
71-
<EuiButtonEmpty
72-
size="s"
73-
data-test-subj="copyObjects"
74-
onClick={onCopy}
75-
disabled={selectedCount === 0}
76-
>
77-
<FormattedMessage
78-
id="savedObjectsManagement.objectsTable.header.duplicateAllButtonLabel"
79-
defaultMessage="Duplicate All"
80-
/>
81-
</EuiButtonEmpty>
82-
</EuiFlexItem>
74+
{showDuplicateAll && (
75+
<EuiFlexItem grow={false}>
76+
<EuiButtonEmpty
77+
size="s"
78+
data-test-subj="copyObjects"
79+
onClick={onCopy}
80+
disabled={selectedCount === 0}
81+
>
82+
<FormattedMessage
83+
id="savedObjectsManagement.objectsTable.header.duplicateAllButtonLabel"
84+
defaultMessage="Duplicate All"
85+
/>
86+
</EuiButtonEmpty>
87+
</EuiFlexItem>
88+
)}
8389
<EuiFlexItem grow={false}>
8490
<EuiButtonEmpty
8591
size="s"
@@ -96,19 +102,21 @@ export const Header = ({
96102
/>
97103
</EuiButtonEmpty>
98104
</EuiFlexItem>
99-
<EuiFlexItem grow={false}>
100-
<EuiButtonEmpty
101-
size="s"
102-
iconType="importAction"
103-
data-test-subj="importObjects"
104-
onClick={onImport}
105-
>
106-
<FormattedMessage
107-
id="savedObjectsManagement.objectsTable.header.importButtonLabel"
108-
defaultMessage="Import"
109-
/>
110-
</EuiButtonEmpty>
111-
</EuiFlexItem>
105+
{!hideImport && (
106+
<EuiFlexItem grow={false}>
107+
<EuiButtonEmpty
108+
size="s"
109+
iconType="importAction"
110+
data-test-subj="importObjects"
111+
onClick={onImport}
112+
>
113+
<FormattedMessage
114+
id="savedObjectsManagement.objectsTable.header.importButtonLabel"
115+
defaultMessage="Import"
116+
/>
117+
</EuiButtonEmpty>
118+
</EuiFlexItem>
119+
)}
112120
<EuiFlexItem grow={false}>
113121
<EuiButtonEmpty size="s" iconType="refresh" onClick={onRefresh}>
114122
<FormattedMessage

src/plugins/saved_objects_management/public/management_section/objects_table/components/table.test.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { actionServiceMock } from '../../../services/action_service.mock';
3737
import { columnServiceMock } from '../../../services/column_service.mock';
3838
import { SavedObjectsManagementAction } from '../../..';
3939
import { Table, TableProps } from './table';
40+
import { WorkspaceAttribute } from 'opensearch-dashboards/public';
4041

4142
const defaultProps: TableProps = {
4243
basePath: httpServiceMock.createSetupContract().basePath,
@@ -115,6 +116,36 @@ describe('Table', () => {
115116
expect(component).toMatchSnapshot();
116117
});
117118

119+
it('should render gotoApp link correctly for workspace', () => {
120+
const item = {
121+
id: 'dashboard-1',
122+
type: 'dashboard',
123+
workspaces: ['ws-1'],
124+
attributes: {},
125+
references: [],
126+
meta: {
127+
title: `My-Dashboard-test`,
128+
icon: 'indexPatternApp',
129+
editUrl: '/management/opensearch-dashboards/objects/savedDashboards/dashboard-1',
130+
inAppUrl: {
131+
path: '/app/dashboards#/view/dashboard-1',
132+
uiCapabilitiesPath: 'dashboard.show',
133+
},
134+
},
135+
};
136+
const props = {
137+
...defaultProps,
138+
availableWorkspaces: [{ id: 'ws-1', name: 'My workspace' } as WorkspaceAttribute],
139+
items: [item],
140+
};
141+
const component = shallowWithI18nProvider(<Table {...props} />);
142+
143+
const table = component.find('EuiBasicTable');
144+
const columns = table.prop('columns') as any[];
145+
const content = columns[1].render('My-Dashboard-test', item);
146+
expect(content.props.href).toEqual('/w/ws-1/app/dashboards#/view/dashboard-1');
147+
});
148+
118149
it('should handle query parse error', () => {
119150
const onQueryChangeMock = jest.fn();
120151
const customizedProps = {

0 commit comments

Comments
 (0)