Skip to content

Commit

Permalink
Feature: hide workspace from saved objects management page. (opensear…
Browse files Browse the repository at this point in the history
…ch-project#45)

* setup workspace plugin project skeleton

Signed-off-by: Yulong Ruan <[email protected]>

* test: add unit tests

add license header

Signed-off-by: Yulong Ruan <[email protected]>

* workspace template init commit

Signed-off-by: Hailong Cui <[email protected]>

* refacter workspace template into hooks

Signed-off-by: Hailong Cui <[email protected]>

* refacter workspace template hooks

Signed-off-by: Hailong Cui <[email protected]>

* update coverImage comments

Signed-off-by: Hailong Cui <[email protected]>

* feature: add public/workspaces service

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: add interfaces for workspaces client

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: add interfaces for workspaces client

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: add interfaces for workspaces client

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: implement workspaces service

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: changes to client type interface

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: changes to client implement

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: implement more for workspaces service

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: implement more for workspaces service

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: implement more for workspaces service

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: add workspace creator page (opensearch-project#5)

* feat: add workspace creator page

Signed-off-by: Lin Wang <[email protected]>

* feat: integrate with application workspace template

Signed-off-by: Lin Wang <[email protected]>

* feat: add max-width and remove image wrapper if not exists

Signed-off-by: Lin Wang <[email protected]>

* feat: update filter condition to align with collapsible nav

Signed-off-by: Lin Wang <[email protected]>

---------

Signed-off-by: Lin Wang <[email protected]>

* Add validation when load page (opensearch-project#8)

* fix: validation & query

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: modify file name to reduce confusion

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: add landing logic to retrive workspace id

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: add worklist observable

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: add worklist observable

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: add worklist observable

Signed-off-by: SuZhoue-Joe <[email protected]>

* fix: type error

Signed-off-by: SuZhoue-Joe <[email protected]>

* fix: type error

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: make client more robust

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: use Subject

Signed-off-by: SuZhoue-Joe <[email protected]>

---------

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: use BehaviorObject and optimize code (opensearch-project#14)

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: integrate with workspace create API (opensearch-project#13)

* feat: integrate with workspace create API

Signed-off-by: Lin Wang <[email protected]>

* feat: update to i18n text for toast

Signed-off-by: Lin Wang <[email protected]>

---------

Signed-off-by: Lin Wang <[email protected]>

* Add currentWorkspace$ (opensearch-project#15)

* feat: add currentWorkspace$

Signed-off-by: SuZhoue-Joe <[email protected]>

* fix: type error

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: add emit on currentWorkspace$

Signed-off-by: SuZhoue-Joe <[email protected]>

---------

Signed-off-by: SuZhoue-Joe <[email protected]>

* register plugin with workspace template (opensearch-project#16)

Signed-off-by: Hailong Cui <[email protected]>

* workspace dropdown list (opensearch-project#9)

Add workspace dropdown list 

---------

Signed-off-by: zhichao-aws <[email protected]>
Signed-off-by: SuZhoue-Joe <[email protected]>
Signed-off-by: suzhou <[email protected]>
Co-authored-by: SuZhoue-Joe <[email protected]>

* init workspace menu stage 1 (opensearch-project#12)

* feat: init workspace menu stage 1

Signed-off-by: tygao <[email protected]>

* fix: remove port diff

Signed-off-by: tygao <[email protected]>

* feat: update menu logic

Signed-off-by: tygao <[email protected]>

---------

Signed-off-by: tygao <[email protected]>

* Fix template registration import error (opensearch-project#21)

* fix import error

Signed-off-by: Hailong Cui <[email protected]>

* fix osd bootstrap failure

Signed-off-by: Hailong Cui <[email protected]>

---------

Signed-off-by: Hailong Cui <[email protected]>

* Add workspace overview page (opensearch-project#19)

* feat: add workspace overview page

Signed-off-by: Lin Wang <[email protected]>

* refactor: move paths to common constants

Signed-off-by: Lin Wang <[email protected]>

* feat: add workspace overview item by custom nav in start phase

Signed-off-by: Lin Wang <[email protected]>

* refactor: change to currentWorkspace$ in workspace client

Signed-off-by: Lin Wang <[email protected]>

---------

Signed-off-by: Lin Wang <[email protected]>

* feat: navigate to workspace create page after button clicked (opensearch-project#23)

Signed-off-by: Lin Wang <[email protected]>

* fix failed test snapshots (opensearch-project#22)

fix failed test snapshots

temporary fix: fetch functional test from main branch

fixed git error which cannot find ref due to feature branch `workspace`
not exists on repo opensearch-dashboards-functional-test

Signed-off-by: Yulong Ruan <[email protected]>

---------

Signed-off-by: Yulong Ruan <[email protected]>

* change to currentWorkspace, wrap title using i18n (opensearch-project#20)

* change to currentWorkspace, wrap title using i18n

Signed-off-by: zhichao-aws <[email protected]>

* change import

Signed-off-by: zhichao-aws <[email protected]>

* directly return [] if currentWorkspace is null

Signed-off-by: zhichao-aws <[email protected]>

---------

Signed-off-by: zhichao-aws <[email protected]>

* add workspace switch (opensearch-project#17)

* feat: update workspace switch

Signed-off-by: tygao <[email protected]>

* fix: fix switch error

Signed-off-by: tygao <[email protected]>

* fix: fix prettier after merge

Signed-off-by: tygao <[email protected]>

* chore: remove extra code after merge

Signed-off-by: tygao <[email protected]>

---------

Signed-off-by: tygao <[email protected]>

* Add update workspace page (opensearch-project#25)

Signed-off-by: gaobinlong <[email protected]>

* Delete Workspace (opensearch-project#24)

* add delete workspace modal

Signed-off-by: yuye-aws <[email protected]>

* implement delete on workspace overview page

Signed-off-by: yuye-aws <[email protected]>

* fix export on delete workspace modal

Signed-off-by: yuye-aws <[email protected]>

* add try catch to handle errors for workspace delete

Signed-off-by: yuye-aws <[email protected]>

* move visibility control to workspace overview page exlusively

Signed-off-by: yuye-aws <[email protected]>

* remove unused import

Signed-off-by: yuye-aws <[email protected]>

---------

Signed-off-by: yuye-aws <[email protected]>

* feat: redirect to overview page after workspace switch (opensearch-project#26)

Signed-off-by: Lin Wang <[email protected]>

* update menu filter logic (opensearch-project#28)

* feat: update menu logic

Signed-off-by: tygao <[email protected]>

* fix: use navLinks to filter

Signed-off-by: tygao <[email protected]>

---------

Signed-off-by: tygao <[email protected]>

* feat: redirect to workspace overview page after created success (opensearch-project#29)

Signed-off-by: Lin Wang <[email protected]>

* [Feature] Complied saved_objects create/find (opensearch-project#18)

* temp: save

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: make create/find support workspaces

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: extract management code

Signed-off-by: SuZhoue-Joe <[email protected]>

* fix: type check

Signed-off-by: SuZhoue-Joe <[email protected]>

* fix: build error

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: enable workspaces on saved client server side

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: some optimization

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: extract management code

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: merge fix

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: optimize code

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: reuse common function

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: optimize code when create

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: remove useless test code

Signed-off-by: SuZhoue-Joe <[email protected]>

---------

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: redirect to workspace update page after workspace switch (opensearch-project#30)

* Move delete button to update page (opensearch-project#27)

* add delete workspace modal

Signed-off-by: yuye-aws <[email protected]>

* implement delete on workspace overview page

Signed-off-by: yuye-aws <[email protected]>

* fix export on delete workspace modal

Signed-off-by: yuye-aws <[email protected]>

* add try catch to handle errors for workspace delete

Signed-off-by: yuye-aws <[email protected]>

* move visibility control to workspace overview page exlusively

Signed-off-by: yuye-aws <[email protected]>

* remove unused import

Signed-off-by: yuye-aws <[email protected]>

* change workspace overview route to workspace update

Signed-off-by: yuye-aws <[email protected]>

* move delete button from workspace overview page to update page

Signed-off-by: yuye-aws <[email protected]>

* remove update button from workspace overview page

Signed-off-by: yuye-aws <[email protected]>

* recover router to workspace overview page

Signed-off-by: yuye-aws <[email protected]>

* change navigation url for workspace overview button on left side panel

Signed-off-by: yuye-aws <[email protected]>

---------

Signed-off-by: yuye-aws <[email protected]>

* fix: linting error

Signed-off-by: Yulong Ruan <[email protected]>

* remove duplicate EuiPage (opensearch-project#34)

* remove duplicate EuiPage

Signed-off-by: Hailong Cui <[email protected]>

* fix: remove duplicate workspace template

Signed-off-by: Hailong Cui <[email protected]>

---------

Signed-off-by: Hailong Cui <[email protected]>

* remove clear button, add the width of create button (opensearch-project#33)

Signed-off-by: zhichao-aws <[email protected]>

* rename OpenSearch Plugins to OpenSearch Features

this is a temporary fix just for demo, should be reverted later

Signed-off-by: Yulong Ruan <[email protected]>

* Add some logic check when overwrite a saved object (opensearch-project#32)

* feat: add some logic check when overwrite a saved object

Signed-off-by: SuZhoue-Joe <[email protected]>

* fix: type check

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: update

Signed-off-by: SuZhoue-Joe <[email protected]>

---------

Signed-off-by: SuZhoue-Joe <[email protected]>

* Add color, icon and defaultVISTheme for workspace (opensearch-project#36)

* feat: add color, icon and defaultVISTheme field for workspace saved object

Signed-off-by: Lin Wang <[email protected]>

* add new fields to workspace form

Signed-off-by: Lin Wang <[email protected]>

* feat: remove feature or group name hack

Signed-off-by: Lin Wang <[email protected]>

---------

Signed-off-by: Lin Wang <[email protected]>

* feat: add workspace list (opensearch-project#39)

Signed-off-by: tygao <[email protected]>

* Feature/menu change (opensearch-project#37)

* feat: register library menus

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: some update

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: optimize code

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: optimize code

Signed-off-by: SuZhou-Joe <[email protected]>

---------

Signed-off-by: SuZhoue-Joe <[email protected]>
Signed-off-by: SuZhou-Joe <[email protected]>

* feat: different left menu and exit workspace (opensearch-project#38)

* Exit workspace from left menu

Signed-off-by: yuye-aws <[email protected]>

* Show exit workspace button with small window size

Signed-off-by: yuye-aws <[email protected]>

* Remove recently viewed and workspace overview on left menu

Signed-off-by: yuye-aws <[email protected]>

* Add buttons for outside, inside workspace case

Signed-off-by: yuye-aws <[email protected]>

* Implement home button and workspace over view button on left menu

Signed-off-by: yuye-aws <[email protected]>

* Implement workspace dropdown list in left menu

Signed-off-by: yuye-aws <[email protected]>

* Add props on recently accessed and custom nav link

Signed-off-by: yuye-aws <[email protected]>

* Add three props to mock props for collapsible nav: exitWorkspace, getWorkspaceUrl, workspaceList$

Signed-off-by: yuye-aws <[email protected]>

* Add three props to mock props for header: exitWorkspace, getWorkspaceUrl, workspaceList$

Signed-off-by: yuye-aws <[email protected]>

* Fix bugs for function createWorkspaceNavLink

Signed-off-by: yuye-aws <[email protected]>

* Remove unused constants

Signed-off-by: yuye-aws <[email protected]>

* Reuse method getWorkspaceUrl

Signed-off-by: yuye-aws <[email protected]>

* Remove recently accessed and custom nav props in test

Signed-off-by: yuye-aws <[email protected]>

* Revert "Remove recently accessed and custom nav props in test"

This reverts commit 7895e5c.

* Wrap title with i18n

Signed-off-by: yuye-aws <[email protected]>

* Add redirect for workspace app

Signed-off-by: yuye-aws <[email protected]>

* Enable users to go to workspace lists page via see more under workspaces in left menu

Signed-off-by: yuye-aws <[email protected]>

---------

Signed-off-by: yuye-aws <[email protected]>

* feat: make url stateful (opensearch-project#35)

* feat: make url stateful

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: optimize code

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: remove useless change

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: optimize url listener

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: make formatUrlWithWorkspaceId extensible

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: modify to related components

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: modify the async format to be sync function

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: modify the async format to be sync function

Signed-off-by: SuZhoue-Joe <[email protected]>

* fix: type check

Signed-off-by: SuZhoue-Joe <[email protected]>

* feat: use path to maintain workspace info

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: optimize code

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: optimize code

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: optimize code

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: optimize code

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: optimize code

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: optimize code

Signed-off-by: SuZhou-Joe <[email protected]>

---------

Signed-off-by: SuZhoue-Joe <[email protected]>
Signed-off-by: SuZhou-Joe <[email protected]>

* Fix build error and part of test error (opensearch-project#42)

* fix: fix build error and some ut

Signed-off-by: tygao <[email protected]>

* chore: remove saved object client test diff

Signed-off-by: tygao <[email protected]>

---------

Signed-off-by: tygao <[email protected]>

* feat: optimize code (opensearch-project#40)

Signed-off-by: SuZhou-Joe <[email protected]>

* fix: bootstrap error (opensearch-project#43)

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: add workspace permission control interface (opensearch-project#41)

* feat: add workspace permission control interface

Signed-off-by: Lin Wang <[email protected]>

* feat: add request parameter for workspace permission control

Signed-off-by: Lin Wang <[email protected]>

---------

Signed-off-by: Lin Wang <[email protected]>

* allow user to turn on/off workspace from advance settings (opensearch-project#46)

return 404 if accessing a workspace path when workspace is disabled

---------

Signed-off-by: Yulong Ruan <[email protected]>

* fix: unit test failure (opensearch-project#50)

Signed-off-by: SuZhou-Joe <[email protected]>

* 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]>

* feat: make edit url clickable

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: add ui capability path

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: add ui capability path

Signed-off-by: SuZhou-Joe <[email protected]>

* fet: remove useless jump code

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: hide workspace from saved objects management page

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: hide workspace from saved objects management page

Signed-off-by: SuZhou-Joe <[email protected]>

---------

Signed-off-by: Yulong Ruan <[email protected]>
Signed-off-by: Hailong Cui <[email protected]>
Signed-off-by: SuZhoue-Joe <[email protected]>
Signed-off-by: Lin Wang <[email protected]>
Signed-off-by: zhichao-aws <[email protected]>
Signed-off-by: suzhou <[email protected]>
Signed-off-by: tygao <[email protected]>
Signed-off-by: gaobinlong <[email protected]>
Signed-off-by: yuye-aws <[email protected]>
Signed-off-by: SuZhou-Joe <[email protected]>
Co-authored-by: Yulong Ruan <[email protected]>
Co-authored-by: Hailong Cui <[email protected]>
Co-authored-by: Lin Wang <[email protected]>
Co-authored-by: zhichao-aws <[email protected]>
Co-authored-by: raintygao <[email protected]>
Co-authored-by: gaobinlong <[email protected]>
Co-authored-by: Yuye Zhu <[email protected]>
  • Loading branch information
8 people authored Jul 21, 2023
1 parent 2e7b7c1 commit ad29881
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 49 deletions.
16 changes: 10 additions & 6 deletions src/core/public/http/base_path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*/

import { modifyUrl } from '@osd/std';
import type { PrependOptions } from './types';

export class BasePath {
constructor(
Expand All @@ -45,7 +46,8 @@ export class BasePath {
return this.basePath;
};

public prepend = (path: string, withoutWorkspace: boolean = false): string => {
public prepend = (path: string, prependOptions?: PrependOptions): string => {
const { withoutWorkspace } = prependOptions || {};
const basePath = withoutWorkspace ? this.basePath : this.get();
if (!basePath) return path;
return modifyUrl(path, (parts) => {
Expand All @@ -55,17 +57,19 @@ export class BasePath {
});
};

public remove = (path: string): string => {
if (!this.get()) {
public remove = (path: string, prependOptions?: PrependOptions): string => {
const { withoutWorkspace } = prependOptions || {};
const basePath = withoutWorkspace ? this.basePath : this.get();
if (!basePath) {
return path;
}

if (path === this.get()) {
if (path === basePath) {
return '/';
}

if (path.startsWith(`${this.get()}/`)) {
return path.slice(this.get().length);
if (path.startsWith(`${basePath}/`)) {
return path.slice(basePath.length);
}

return path;
Expand Down
3 changes: 2 additions & 1 deletion src/core/public/http/http_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { LoadingCountService } from './loading_count_service';
import { Fetch } from './fetch';
import { CoreService } from '../../types';
import { getWorkspaceIdFromUrl } from '../utils';
import { WORKSPACE_PATH_PREFIX } from '../../utils/constants';

interface HttpDeps {
injectedMetadata: InjectedMetadataSetup;
Expand All @@ -54,7 +55,7 @@ export class HttpService implements CoreService<HttpSetup, HttpStart> {
let workspaceBasePath = '';
const workspaceId = getWorkspaceIdFromUrl(window.location.href);
if (workspaceId) {
workspaceBasePath = `/w/${workspaceId}`;
workspaceBasePath = `${WORKSPACE_PATH_PREFIX}/${workspaceId}`;
}
const basePath = new BasePath(
injectedMetadata.getBasePath(),
Expand Down
14 changes: 12 additions & 2 deletions src/core/public/http/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ export interface HttpSetup {
*/
export type HttpStart = HttpSetup;

/**
* prepend options
*
* withoutWorkspace option will prepend a relative url with only basePath
* workspaceId will rewrite the /w/{workspaceId} part, if workspace id is an empty string, prepend will remove the workspaceId part
*/
export interface PrependOptions {
withoutWorkspace?: boolean;
}

/**
* APIs for manipulating the basePath on URL segments.
* @public
Expand All @@ -105,12 +115,12 @@ export interface IBasePath {
/**
* Prepends `path` with the basePath + workspace.
*/
prepend: (url: string) => string;
prepend: (url: string, prependOptions?: PrependOptions) => string;

/**
* Removes the prepended basePath + workspace from the `path`.
*/
remove: (url: string) => string;
remove: (url: string, prependOptions?: PrependOptions) => string;

/**
* Returns the server's root basePath as configured, without any namespace prefix.
Expand Down
2 changes: 2 additions & 0 deletions src/core/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,3 +357,5 @@ export {
WorkspaceAttribute,
WorkspaceFindOptions,
} from './workspace';

export { getWorkspaceIdFromUrl, WORKSPACE_TYPE } from './utils';
3 changes: 2 additions & 1 deletion src/core/public/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@
export { shareWeakReplay } from './share_weak_replay';
export { Sha256 } from './crypto';
export { MountWrapper, mountReactNode } from './mount';
export { getWorkspaceIdFromUrl } from './workspace';
export { getWorkspaceIdFromUrl, WORKSPACE_TYPE } from './workspace';
export { WORKSPACE_PATH_PREFIX } from '../../utils';
2 changes: 2 additions & 0 deletions src/core/public/utils/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ export const getWorkspaceIdFromUrl = (url: string): string => {

return '';
};

export const WORKSPACE_TYPE = 'workspace';
2 changes: 1 addition & 1 deletion src/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,4 +509,4 @@ export const config = {
},
};

export { formatWorkspaces, workspacesValidator } from './workspaces';
export { formatWorkspaces, workspacesValidator, WORKSPACE_TYPE } from './workspaces';
6 changes: 6 additions & 0 deletions src/core/server/workspaces/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export const WORKSPACE_TYPE = 'workspace';
1 change: 1 addition & 0 deletions src/core/server/workspaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export { WorkspaceAttribute, WorkspaceFindOptions } from './types';

export { WorkspacePermissionControl } from './workspace_permission_control';
export { workspacesValidator, formatWorkspaces } from './utils';
export { WORKSPACE_TYPE } from './constants';
23 changes: 5 additions & 18 deletions src/core/server/workspaces/saved_objects/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,15 @@
*/

import { SavedObjectsType } from 'opensearch-dashboards/server';
import { WORKSPACE_TYPE } from '../constants';

export const workspace: SavedObjectsType = {
name: 'workspace',
name: WORKSPACE_TYPE,
namespaceType: 'agnostic',
hidden: false,
management: {
icon: 'apps', // todo: pending ux #2034
defaultSearchField: 'title',
importableAndExportable: true,
getTitle(obj) {
return obj.attributes.title;
},
getEditUrl(obj) {
return `/management/opensearch-dashboards/dataSources/${encodeURIComponent(obj.id)}`;
},
getInAppUrl(obj) {
return {
path: `/app/management/opensearch-dashboards/dataSources/${encodeURIComponent(obj.id)}`,
uiCapabilitiesPath: 'management.opensearchDashboards.dataSources',
};
},
},
/**
* workspace won't appear in management page.
*/
mappings: {
dynamic: false,
properties: {
Expand Down
16 changes: 6 additions & 10 deletions src/core/server/workspaces/workspaces_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import {
} from './types';
import { WorkspacesSetupDeps } from './workspaces_service';
import { workspace } from './saved_objects';

export const WORKSPACES_TYPE_FOR_SAVED_OBJECT = 'workspace';
import { WORKSPACE_TYPE } from './constants';

export class WorkspacesClientWithSavedObject implements IWorkspaceDBImpl {
private setupDep: WorkspacesSetupDeps;
Expand Down Expand Up @@ -50,7 +49,7 @@ export class WorkspacesClientWithSavedObject implements IWorkspaceDBImpl {
try {
const result = await this.getSavedObjectClientsFromRequestDetail(requestDetail).create<
Omit<WorkspaceAttribute, 'id'>
>(WORKSPACES_TYPE_FOR_SAVED_OBJECT, payload);
>(WORKSPACE_TYPE, payload);
return {
success: true,
result: {
Expand All @@ -75,7 +74,7 @@ export class WorkspacesClientWithSavedObject implements IWorkspaceDBImpl {
} = await this.getSavedObjectClientsFromRequestDetail(requestDetail).find<WorkspaceAttribute>(
{
...options,
type: WORKSPACES_TYPE_FOR_SAVED_OBJECT,
type: WORKSPACE_TYPE,
}
);
return {
Expand All @@ -99,7 +98,7 @@ export class WorkspacesClientWithSavedObject implements IWorkspaceDBImpl {
try {
const result = await this.getSavedObjectClientsFromRequestDetail(requestDetail).get<
WorkspaceAttribute
>(WORKSPACES_TYPE_FOR_SAVED_OBJECT, id);
>(WORKSPACE_TYPE, id);
return {
success: true,
result: this.getFlatternedResultWithSavedObject(result),
Expand All @@ -119,7 +118,7 @@ export class WorkspacesClientWithSavedObject implements IWorkspaceDBImpl {
try {
await this.getSavedObjectClientsFromRequestDetail(requestDetail).update<
Omit<WorkspaceAttribute, 'id'>
>(WORKSPACES_TYPE_FOR_SAVED_OBJECT, id, payload);
>(WORKSPACE_TYPE, id, payload);
return {
success: true,
result: true,
Expand All @@ -133,10 +132,7 @@ export class WorkspacesClientWithSavedObject implements IWorkspaceDBImpl {
}
public async delete(requestDetail: IRequestDetail, id: string): Promise<IResponse<boolean>> {
try {
await this.getSavedObjectClientsFromRequestDetail(requestDetail).delete(
WORKSPACES_TYPE_FOR_SAVED_OBJECT,
id
);
await this.getSavedObjectClientsFromRequestDetail(requestDetail).delete(WORKSPACE_TYPE, id);
return {
success: true,
result: true,
Expand Down
6 changes: 6 additions & 0 deletions src/core/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export const WORKSPACE_PATH_PREFIX = '/w';
1 change: 1 addition & 0 deletions src/core/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +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 } from './constants';
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { ManagementAppMountParams } from 'src/plugins/management/public';
import { StartDependencies, SavedObjectsManagementPluginStart } from '../plugin';
import { ISavedObjectsManagementServiceRegistry } from '../services';
import { getAllowedTypes } from './../lib';
import { WORKSPACE_TYPE } from '../../../../core/public';

interface MountParams {
core: CoreSetup<StartDependencies, SavedObjectsManagementPluginStart>;
Expand Down Expand Up @@ -67,7 +68,12 @@ export const mountManagementSection = async ({
const setBreadcrumbs = mountParams?.setBreadcrumbs || chrome.setBreadcrumbs;
let finalAllowedObjectTypes = allowedObjectTypes;
if (finalAllowedObjectTypes === undefined) {
finalAllowedObjectTypes = await getAllowedTypes(coreStart.http);
/**
* Workspace needs to be filtered out since it is a concept with higher level than normal saved objects.
*/
finalAllowedObjectTypes = (await getAllowedTypes(coreStart.http)).filter(
(item) => item !== WORKSPACE_TYPE
);
}

coreStart.chrome.docTitle.change(title);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ function WorkspaceColumn({ coreSetup, workspaces, record }: WorkspaceColumnProps
});
wsLookUp?.set('public', publicWsName);

if (record.type === 'workspace') {
return null;
}

if (!workspaces) {
return <EuiText>{publicWsName}</EuiText>;
}
Expand Down
13 changes: 8 additions & 5 deletions src/plugins/workspace/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import {
} from '../../../core/public';
import { WORKSPACE_APP_ID } from '../common/constants';
import { mountDropdownList } from './mount';
import { getWorkspaceIdFromUrl } from '../../../core/public/utils';
import { SavedObjectsManagementPluginSetup } from '../../saved_objects_management/public';
import { getWorkspaceColumn } from './components/utils/workspace_column';
import { getWorkspaceIdFromUrl, WORKSPACE_PATH_PREFIX } from '../../../core/public/utils';

interface WorkspacesPluginSetupDeps {
savedObjectsManagement?: SavedObjectsManagementPluginSetup;
Expand All @@ -36,13 +36,16 @@ export class WorkspacesPlugin implements Plugin<{}, {}, WorkspacesPluginSetupDep
*/
newUrl.pathname = this.coreSetup?.http.basePath.remove(newUrl.pathname) || '';
if (workspaceId) {
newUrl.pathname = `${this.coreSetup?.http.basePath.serverBasePath || ''}/w/${workspaceId}${
newUrl.pathname
}`;
newUrl.pathname = `${WORKSPACE_PATH_PREFIX}/${workspaceId}${newUrl.pathname}`;
} else {
newUrl.pathname = `${this.coreSetup?.http.basePath.serverBasePath || ''}${newUrl.pathname}`;
newUrl.pathname = newUrl.pathname.replace(/^\/w\/([^\/]*)/, '');
}

newUrl.pathname =
this.coreSetup?.http.basePath.prepend(newUrl.pathname, {
withoutWorkspace: true,
}) || '';

return newUrl.toString();
};
public async setup(core: CoreSetup, { savedObjectsManagement }: WorkspacesPluginSetupDeps) {
Expand Down

0 comments on commit ad29881

Please sign in to comment.