Skip to content

Commit

Permalink
Saved objects page change (opensearch-project#123)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
Hailong-am authored and ruanyl committed Sep 15, 2023
1 parent 2d3800b commit c1d6ec2
Show file tree
Hide file tree
Showing 9 changed files with 248 additions and 145 deletions.

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.

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 @@ -38,12 +38,57 @@ describe('Header', () => {
onExportAll: () => {},
onImport: () => {},
onRefresh: () => {},
onCopy: () => {},
title: 'Saved Objects',
selectedCount: 0,
totalCount: 4,
filteredCount: 2,
showDuplicateAll: false,
hideImport: false,
};

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

expect(component).toMatchSnapshot();
});
});

describe('Header - workspace enabled', () => {
it('should render `Duplicate All` button when workspace enabled', () => {
const props = {
onExportAll: () => {},
onImport: () => {},
onRefresh: () => {},
onCopy: () => {},
title: 'Saved Objects',
selectedCount: 0,
totalCount: 4,
filteredCount: 2,
showDuplicateAll: true,
hideImport: false,
};

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

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

it('should hide `Import` button for application home state', () => {
const props = {
onExportAll: () => {},
onImport: () => {},
onRefresh: () => {},
onCopy: () => {},
title: 'Saved Objects',
selectedCount: 0,
totalCount: 4,
filteredCount: 2,
showDuplicateAll: true,
hideImport: true,
};

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

expect(component.find('EuiButtonEmpty[data-test-subj="importObjects"]').exists()).toBe(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export const Header = ({
filteredCount,
title,
selectedCount,
hideImport = false,
showDuplicateAll = false,
}: {
onExportAll: () => void;
onImport: () => void;
Expand All @@ -56,6 +58,8 @@ export const Header = ({
filteredCount: number;
title: string;
selectedCount: number;
hideImport: boolean;
showDuplicateAll: boolean;
}) => (
<Fragment>
<EuiFlexGroup justifyContent="spaceBetween" alignItems="baseline">
Expand All @@ -67,19 +71,21 @@ export const Header = ({

<EuiFlexItem grow={false}>
<EuiFlexGroup alignItems="baseline" gutterSize="m" responsive={false}>
<EuiFlexItem grow={false}>
<EuiButtonEmpty
size="s"
data-test-subj="copyObjects"
onClick={onCopy}
disabled={selectedCount === 0}
>
<FormattedMessage
id="savedObjectsManagement.objectsTable.header.duplicateAllButtonLabel"
defaultMessage="Duplicate All"
/>
</EuiButtonEmpty>
</EuiFlexItem>
{showDuplicateAll && (
<EuiFlexItem grow={false}>
<EuiButtonEmpty
size="s"
data-test-subj="copyObjects"
onClick={onCopy}
disabled={selectedCount === 0}
>
<FormattedMessage
id="savedObjectsManagement.objectsTable.header.duplicateAllButtonLabel"
defaultMessage="Duplicate All"
/>
</EuiButtonEmpty>
</EuiFlexItem>
)}
<EuiFlexItem grow={false}>
<EuiButtonEmpty
size="s"
Expand All @@ -96,19 +102,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>
{!hideImport && (
<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 @@ -37,6 +37,7 @@ import { actionServiceMock } from '../../../services/action_service.mock';
import { columnServiceMock } from '../../../services/column_service.mock';
import { SavedObjectsManagementAction } from '../../..';
import { Table, TableProps } from './table';
import { WorkspaceAttribute } from 'opensearch-dashboards/public';

const defaultProps: TableProps = {
basePath: httpServiceMock.createSetupContract().basePath,
Expand Down Expand Up @@ -115,6 +116,36 @@ describe('Table', () => {
expect(component).toMatchSnapshot();
});

it('should render gotoApp link correctly for workspace', () => {
const item = {
id: 'dashboard-1',
type: 'dashboard',
workspaces: ['ws-1'],
attributes: {},
references: [],
meta: {
title: `My-Dashboard-test`,
icon: 'indexPatternApp',
editUrl: '/management/opensearch-dashboards/objects/savedDashboards/dashboard-1',
inAppUrl: {
path: '/app/dashboards#/view/dashboard-1',
uiCapabilitiesPath: 'dashboard.show',
},
},
};
const props = {
...defaultProps,
availableWorkspaces: [{ id: 'ws-1', name: 'My workspace' } as WorkspaceAttribute],
items: [item],
};
const component = shallowWithI18nProvider(<Table {...props} />);

const table = component.find('EuiBasicTable');
const columns = table.prop('columns') as any[];
const content = columns[1].render('My-Dashboard-test', item);
expect(content.props.href).toEqual('/w/ws-1/app/dashboards#/view/dashboard-1');
});

it('should handle query parse error', () => {
const onQueryChangeMock = jest.fn();
const customizedProps = {
Expand Down
Loading

0 comments on commit c1d6ec2

Please sign in to comment.