forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add workspace column into saved objects table (opensearch-project#44)
* Add workspace column into saved management page Signed-off-by: Hailong Cui <[email protected]> * savedObjectsManagement as optional dependency Signed-off-by: Hailong Cui <[email protected]> * i18n for column title Signed-off-by: Hailong Cui <[email protected]> --------- Signed-off-by: Hailong Cui <[email protected]>
- Loading branch information
1 parent
94fa082
commit 124896c
Showing
3 changed files
with
80 additions
and
3 deletions.
There are no files selected for viewing
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
66 changes: 66 additions & 0 deletions
66
src/plugins/workspace/public/components/utils/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,66 @@ | ||
/* | ||
* 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, | ||
SavedObjectsManagementRecord, | ||
} from '../../../../saved_objects_management/public'; | ||
|
||
interface WorkspaceColumnProps { | ||
coreSetup: CoreSetup; | ||
workspaces?: string[]; | ||
record: SavedObjectsManagementRecord; | ||
} | ||
|
||
function WorkspaceColumn({ coreSetup, workspaces, record }: WorkspaceColumnProps) { | ||
const workspaceList = useObservable(coreSetup.workspaces.client.workspaceList$); | ||
|
||
const wsLookUp = workspaceList?.reduce((map, ws) => { | ||
return map.set(ws.id, ws.name); | ||
}, new Map<string, string>()); | ||
|
||
const publicWsName = i18n.translate('workspace.public.name', { | ||
defaultMessage: 'public', | ||
}); | ||
wsLookUp?.set('public', publicWsName); | ||
|
||
if (record.type === 'workspace') { | ||
return null; | ||
} | ||
|
||
if (!workspaces) { | ||
return <EuiText>{publicWsName}</EuiText>; | ||
} | ||
|
||
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[], record: SavedObjectsManagementRecord) => { | ||
return <WorkspaceColumn coreSetup={coreSetup} workspaces={workspaces} record={record} />; | ||
}, | ||
}, | ||
loadData: () => { | ||
return Promise.resolve(undefined); | ||
}, | ||
}; | ||
} |
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