Skip to content

Commit

Permalink
default workspace
Browse files Browse the repository at this point in the history
Signed-off-by: Hailong Cui <[email protected]>
  • Loading branch information
Hailong-am committed Mar 7, 2024
1 parent 40425c1 commit 2243734
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/core/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,4 +354,4 @@ export { __osdBootstrap__ } from './osd_bootstrap';

export { WorkspacesStart, WorkspacesSetup, WorkspacesService } from './workspace';

export { WORKSPACE_TYPE } from '../utils';
export { WORKSPACE_TYPE, DEFAULT_WORKSPACE_ID } from '../utils';
1 change: 1 addition & 0 deletions src/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ export {
MANAGEMENT_WORKSPACE_ID,
WORKSPACE_TYPE,
PERSONAL_WORKSPACE_ID_PREFIX,
DEFAULT_WORKSPACE_ID,
} from '../utils';

export {
Expand Down
6 changes: 6 additions & 0 deletions src/core/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ export const WORKSPACE_PATH_PREFIX = '/w';

export const PUBLIC_WORKSPACE_ID = 'public';

/**
* default workspace is virtual workspace,
* saved objects that don't have workspaces/permissions field are belongs to default workspace
*/
export const DEFAULT_WORKSPACE_ID = 'default';

export const MANAGEMENT_WORKSPACE_ID = 'management';

export const PERSONAL_WORKSPACE_ID_PREFIX = 'personal';
1 change: 1 addition & 0 deletions src/core/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ export {
MANAGEMENT_WORKSPACE_ID,
WORKSPACE_TYPE,
PERSONAL_WORKSPACE_ID_PREFIX,
DEFAULT_WORKSPACE_ID,
} from './constants';
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import {
WorkspaceAttribute,
} from 'src/core/public';
import { Subscription } from 'rxjs';
import { DEFAULT_WORKSPACE_ID } from '../../../../../core/public';
import { RedirectAppLinks } from '../../../../opensearch_dashboards_react/public';
import { IndexPatternsContract } from '../../../../data/public';
import {
Expand Down Expand Up @@ -192,7 +193,7 @@ export class SavedObjectsTable extends Component<SavedObjectsTableProps, SavedOb
} else {
// application home
if (!currentWorkspaceId) {
return availableWorkspaces?.map((ws) => ws.id);
return availableWorkspaces?.map((ws) => ws.id).concat(DEFAULT_WORKSPACE_ID);
} else {
return [currentWorkspaceId];
}
Expand All @@ -201,10 +202,13 @@ export class SavedObjectsTable extends Component<SavedObjectsTableProps, SavedOb

private get wsNameIdLookup() {
const { availableWorkspaces } = this.state;
const workspaceNameIdMap = new Map<string, string>();
workspaceNameIdMap.set(DEFAULT_WORKSPACE_ID, DEFAULT_WORKSPACE_ID);
// Assumption: workspace name is unique across the system
return availableWorkspaces?.reduce((map, ws) => {
availableWorkspaces?.reduce((map, ws) => {
return map.set(ws.name, ws.id);
}, new Map<string, string>());
}, workspaceNameIdMap);
return workspaceNameIdMap;
}

private formatWorkspaceIdParams<T extends { workspaces?: string[] }>(
Expand Down Expand Up @@ -352,6 +356,13 @@ export class SavedObjectsTable extends Component<SavedObjectsTableProps, SavedOb
findOptions.workspaces = workspaceIds;
}

if (findOptions.workspaces) {
if (findOptions.workspaces.indexOf(DEFAULT_WORKSPACE_ID) !== -1) {
// search both saved objects with workspace and without workspace
findOptions.workspacesSearchOperator = 'OR';
}
}

if (findOptions.type.length > 1) {
findOptions.sortField = 'type';
}
Expand Down Expand Up @@ -962,6 +973,14 @@ export class SavedObjectsTable extends Component<SavedObjectsTableProps, SavedOb
};
});

if (!currentWorkspaceId) {
wsFilterOptions.push({
name: DEFAULT_WORKSPACE_ID,
value: DEFAULT_WORKSPACE_ID,
view: `Default (${wsCounts[DEFAULT_WORKSPACE_ID] || 0})`,
});
}

filters.push({
type: 'field_value_selection',
field: 'workspaces',
Expand Down
1 change: 1 addition & 0 deletions src/plugins/saved_objects_management/server/routes/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const registerFindRoute = (
workspaces: schema.maybe(
schema.oneOf([schema.string(), schema.arrayOf(schema.string())])
),
workspacesSearchOperator: schema.maybe(schema.string()),
}),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import { schema } from '@osd/config-schema';
import { IRouter, SavedObjectsFindOptions } from 'src/core/server';
import { DEFAULT_WORKSPACE_ID } from '../../../../core/server';
import { findAll } from '../lib';

export const registerScrollForCountRoute = (router: IRouter) => {
Expand Down Expand Up @@ -69,6 +70,10 @@ export const registerScrollForCountRoute = (router: IRouter) => {
if (requestHasWorkspaces) {
counts.workspaces = {};
findOptions.workspaces = req.body.workspaces;
if (findOptions.workspaces.indexOf(DEFAULT_WORKSPACE_ID) !== -1) {
// search both saved objects with workspace and without workspace
findOptions.workspacesSearchOperator = 'OR';
}
}

if (req.body.searchString) {
Expand All @@ -91,7 +96,7 @@ export const registerScrollForCountRoute = (router: IRouter) => {
});
}
if (requestHasWorkspaces) {
const resultWorkspaces = result.workspaces || [];
const resultWorkspaces = result.workspaces || [DEFAULT_WORKSPACE_ID];
resultWorkspaces.forEach((ws) => {
counts.workspaces[ws] = counts.workspaces[ws] || 0;
counts.workspaces[ws]++;
Expand Down

0 comments on commit 2243734

Please sign in to comment.