Skip to content

Commit

Permalink
feat: update public workspace
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhou-Joe <[email protected]>
  • Loading branch information
SuZhou-Joe committed Aug 1, 2023
1 parent 2996177 commit 03b1122
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/core/public/saved_objects/saved_objects_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {

import { SimpleSavedObject } from './simple_saved_object';
import { HttpFetchOptions, HttpSetup } from '../http';
import { PUBLIC_WORKSPACE } from '../../utils';

type SavedObjectsFindOptions = Omit<
SavedObjectFindOptionsServer,
Expand Down Expand Up @@ -367,7 +368,7 @@ export class SavedObjectsClient {

const workspaces = [
...(options.workspaces || [await this._getCurrentWorkspace()]),
'public',
PUBLIC_WORKSPACE,
].filter((item) => item);

const renamedQuery = renameKeys<SavedObjectsFindOptions, any>(renameMap, {
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ export { shareWeakReplay } from './share_weak_replay';
export { Sha256 } from './crypto';
export { MountWrapper, mountReactNode } from './mount';
export { getWorkspaceIdFromUrl, WORKSPACE_TYPE } from './workspace';
export { WORKSPACE_PATH_PREFIX } from '../../utils';
export { WORKSPACE_PATH_PREFIX, PUBLIC_WORKSPACE } from '../../utils';
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type KueryNode = any;

import { ISavedObjectTypeRegistry } from '../../../saved_objects_type_registry';
import { ALL_NAMESPACES_STRING, DEFAULT_NAMESPACE_STRING } from '../utils';
import { PUBLIC_WORKSPACE } from '../../../../../utils';

/**
* Gets the types based on the type. Uses mappings to support
Expand Down Expand Up @@ -142,7 +143,7 @@ function getClauseForWorkspace(workspace: string) {
};
}

if (workspace === 'public') {
if (workspace === PUBLIC_WORKSPACE) {
return {
bool: {
must_not: [{ exists: { field: 'workspaces' } }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from 'opensearch-dashboards/server';
import { SavedObjectsPermissionControlContract } from '../../saved_objects/permission_control/client';
import { WORKSPACE_TYPE } from '../constants';
import { PermissionMode } from '../../../utils';
import { PUBLIC_WORKSPACE, PermissionMode } from '../../../utils';

// Can't throw unauthorized for now, the page will be refreshed if unauthorized
const generateWorkspacePermissionError = () =>
Expand Down Expand Up @@ -186,7 +186,7 @@ export class WorkspaceSavedObjectsClientWrapper {
);
} else {
options.workspaces = [
'public',
PUBLIC_WORKSPACE,
...(await this.permissionControl.getPermittedWorkspaceIds(wrapperOptions.request, [
PermissionMode.Read,
])),
Expand Down
2 changes: 2 additions & 0 deletions src/core/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ export enum PermissionMode {
LibraryRead = 'library_read',
LibraryWrite = 'library_write',
}

export const PUBLIC_WORKSPACE = 'public';
2 changes: 1 addition & 1 deletion src/core/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ export {
} from './context';
export { DEFAULT_APP_CATEGORIES } from './default_app_categories';
export { DEFAULT_WORKSPACE_TEMPLATES } from './default_workspace_templates';
export { WORKSPACE_PATH_PREFIX, PermissionMode } from './constants';
export { WORKSPACE_PATH_PREFIX, PermissionMode, PUBLIC_WORKSPACE } from './constants';
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ import {
import { Header, Table, Flyout, Relationships } from './components';
import { DataPublicPluginStart } from '../../../../../plugins/data/public';
import { SavedObjectsCopyModal } from './components/copy_modal';
import { PUBLIC_WORKSPACE } from '../../../../../core/public/utils';

interface ExportAllOption {
id: string;
Expand Down Expand Up @@ -179,7 +180,7 @@ export class SavedObjectsTable extends Component<SavedObjectsTableProps, SavedOb
}

private get workspaceIdQuery() {
return this.state.workspaceId ? ['public', this.state.workspaceId] : ['public'];
return this.state.workspaceId ? [PUBLIC_WORKSPACE, this.state.workspaceId] : [PUBLIC_WORKSPACE];
}

componentDidMount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
SavedObjectsManagementColumn,
SavedObjectsManagementRecord,
} from '../../../../saved_objects_management/public';
import { PUBLIC_WORKSPACE } from '../../../../../core/public/utils';

interface WorkspaceColumnProps {
coreSetup: CoreSetup;
Expand All @@ -31,7 +32,7 @@ function WorkspaceColumn({ coreSetup, workspaces, record }: WorkspaceColumnProps
});
wsLookUp?.set('public', publicWsName);

if (!workspaces) {
if (!workspaces || workspaces?.includes(PUBLIC_WORKSPACE)) {
return <EuiText>{publicWsName}</EuiText>;
}

Expand Down

0 comments on commit 03b1122

Please sign in to comment.