-
Notifications
You must be signed in to change notification settings - Fork 901
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add workspace column into saved objects page Signed-off-by: Hailong Cui <[email protected]> * fix unit test Signed-off-by: Hailong Cui <[email protected]> * add workspaceStart Signed-off-by: Hailong Cui <[email protected]> * merge main Signed-off-by: Hailong Cui <[email protected]> * add changelog Signed-off-by: Hailong Cui <[email protected]> * address review comments Signed-off-by: Hailong Cui <[email protected]> * address review comments Signed-off-by: Hailong Cui <[email protected]> * address review comments Signed-off-by: Hailong Cui <[email protected]> --------- Signed-off-by: Hailong Cui <[email protected]> (cherry picked from commit 7352365) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> # Conflicts: # CHANGELOG.md Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
157f6db
commit cbf7f91
Showing
12 changed files
with
245 additions
and
13 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
...t/public/management_section/objects_table/__snapshots__/saved_objects_table.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/plugins/workspace/public/components/workspace_column/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export { getWorkspaceColumn, WorkspaceColumn } from './workspace_column'; |
59 changes: 59 additions & 0 deletions
59
src/plugins/workspace/public/components/workspace_column/workspace_colum.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import React from 'react'; | ||
import { coreMock } from '../../../../../core/public/mocks'; | ||
import { render } from '@testing-library/react'; | ||
import { WorkspaceColumn } from './workspace_column'; | ||
|
||
describe('workspace column in saved objects page', () => { | ||
const coreSetup = coreMock.createSetup(); | ||
const workspaceList = [ | ||
{ | ||
id: 'ws-1', | ||
name: 'foo', | ||
}, | ||
{ | ||
id: 'ws-2', | ||
name: 'bar', | ||
}, | ||
]; | ||
coreSetup.workspaces.workspaceList$.next(workspaceList); | ||
|
||
it('should show workspace name correctly', () => { | ||
const workspaces = ['ws-1', 'ws-2']; | ||
const { container } = render(<WorkspaceColumn coreSetup={coreSetup} workspaces={workspaces} />); | ||
expect(container).toMatchInlineSnapshot(` | ||
<div> | ||
<div | ||
class="euiText euiText--medium" | ||
> | ||
foo | bar | ||
</div> | ||
</div> | ||
`); | ||
}); | ||
|
||
it('show empty when no workspace', () => { | ||
const { container } = render(<WorkspaceColumn coreSetup={coreSetup} />); | ||
expect(container).toMatchInlineSnapshot(` | ||
<div> | ||
<div | ||
class="euiText euiText--medium" | ||
/> | ||
</div> | ||
`); | ||
}); | ||
|
||
it('show empty when workspace can not found', () => { | ||
const { container } = render(<WorkspaceColumn coreSetup={coreSetup} workspaces={['ws-404']} />); | ||
expect(container).toMatchInlineSnapshot(` | ||
<div> | ||
<div | ||
class="euiText euiText--medium" | ||
/> | ||
</div> | ||
`); | ||
}); | ||
}); |
49 changes: 49 additions & 0 deletions
49
src/plugins/workspace/public/components/workspace_column/workspace_column.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { EuiText } from '@elastic/eui'; | ||
import useObservable from 'react-use/lib/useObservable'; | ||
import { i18n } from '@osd/i18n'; | ||
import { WorkspaceAttribute, CoreSetup } from '../../../../../core/public'; | ||
import { SavedObjectsManagementColumn } from '../../../../saved_objects_management/public'; | ||
|
||
interface WorkspaceColumnProps { | ||
coreSetup: CoreSetup; | ||
workspaces?: string[]; | ||
} | ||
|
||
export function WorkspaceColumn({ coreSetup, workspaces }: WorkspaceColumnProps) { | ||
const workspaceList = useObservable(coreSetup.workspaces.workspaceList$); | ||
|
||
const wsLookUp = workspaceList?.reduce((map, ws) => { | ||
return map.set(ws.id, ws.name); | ||
}, new Map<string, string>()); | ||
|
||
const workspaceNames = workspaces?.map((wsId) => wsLookUp?.get(wsId)).join(' | '); | ||
|
||
return <EuiText>{workspaceNames}</EuiText>; | ||
} | ||
|
||
export function getWorkspaceColumn( | ||
coreSetup: CoreSetup | ||
): SavedObjectsManagementColumn<WorkspaceAttribute | undefined> { | ||
return { | ||
id: 'workspace_column', | ||
euiColumn: { | ||
align: 'left', | ||
field: 'workspaces', | ||
name: i18n.translate('savedObjectsManagement.objectsTable.table.columnWorkspacesName', { | ||
defaultMessage: 'Workspaces', | ||
}), | ||
render: (workspaces: string[]) => { | ||
return <WorkspaceColumn coreSetup={coreSetup} workspaces={workspaces} />; | ||
}, | ||
}, | ||
loadData: () => { | ||
return Promise.resolve(undefined); | ||
}, | ||
}; | ||
} |
Oops, something went wrong.