Skip to content

Commit

Permalink
Integrate workspace service into saved object management (opensearch-…
Browse files Browse the repository at this point in the history
…project#31)

* setup workspace plugin project skeleton

Signed-off-by: Yulong Ruan <ruanyl@amazon.com>

* test: add unit tests

add license header

Signed-off-by: Yulong Ruan <ruanyl@amazon.com>

* workspace template init commit

Signed-off-by: Hailong Cui <ihailong@amazon.com>

* refacter workspace template into hooks

Signed-off-by: Hailong Cui <ihailong@amazon.com>

* refacter workspace template hooks

Signed-off-by: Hailong Cui <ihailong@amazon.com>

* update coverImage comments

Signed-off-by: Hailong Cui <ihailong@amazon.com>

* feature: add public/workspaces service

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: add interfaces for workspaces client

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: add interfaces for workspaces client

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: add interfaces for workspaces client

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: implement workspaces service

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: changes to client type interface

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: changes to client implement

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: implement more for workspaces service

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: implement more for workspaces service

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: implement more for workspaces service

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

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

* feat: add workspace creator page

Signed-off-by: Lin Wang <wonglam@amazon.com>

* feat: integrate with application workspace template

Signed-off-by: Lin Wang <wonglam@amazon.com>

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

Signed-off-by: Lin Wang <wonglam@amazon.com>

* feat: update filter condition to align with collapsible nav

Signed-off-by: Lin Wang <wonglam@amazon.com>

---------

Signed-off-by: Lin Wang <wonglam@amazon.com>

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

* fix: validation & query

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: modify file name to reduce confusion

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: add landing logic to retrive workspace id

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: add worklist observable

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: add worklist observable

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: add worklist observable

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* fix: type error

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* fix: type error

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: make client more robust

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: use Subject

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

---------

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

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

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

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

* feat: integrate with workspace create API

Signed-off-by: Lin Wang <wonglam@amazon.com>

* feat: update to i18n text for toast

Signed-off-by: Lin Wang <wonglam@amazon.com>

---------

Signed-off-by: Lin Wang <wonglam@amazon.com>

* Add currentWorkspace$ (opensearch-project#15)

* feat: add currentWorkspace$

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* fix: type error

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: add emit on currentWorkspace$

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

---------

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

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

Signed-off-by: Hailong Cui <ihailong@amazon.com>

* workspace dropdown list (opensearch-project#9)

Add workspace dropdown list

---------

Signed-off-by: zhichao-aws <zhichaog@amazon.com>
Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>
Signed-off-by: suzhou <suzhou@amazon.com>
Co-authored-by: SuZhoue-Joe <suzhou@amazon.com>

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

* feat: init workspace menu stage 1

Signed-off-by: tygao <tygao@amazon.com>

* fix: remove port diff

Signed-off-by: tygao <tygao@amazon.com>

* feat: update menu logic

Signed-off-by: tygao <tygao@amazon.com>

---------

Signed-off-by: tygao <tygao@amazon.com>

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

* fix import error

Signed-off-by: Hailong Cui <ihailong@amazon.com>

* fix osd bootstrap failure

Signed-off-by: Hailong Cui <ihailong@amazon.com>

---------

Signed-off-by: Hailong Cui <ihailong@amazon.com>

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

* feat: add workspace overview page

Signed-off-by: Lin Wang <wonglam@amazon.com>

* refactor: move paths to common constants

Signed-off-by: Lin Wang <wonglam@amazon.com>

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

Signed-off-by: Lin Wang <wonglam@amazon.com>

* refactor: change to currentWorkspace$ in workspace client

Signed-off-by: Lin Wang <wonglam@amazon.com>

---------

Signed-off-by: Lin Wang <wonglam@amazon.com>

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

Signed-off-by: Lin Wang <wonglam@amazon.com>

* 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 <ruanyl@amazon.com>

---------

Signed-off-by: Yulong Ruan <ruanyl@amazon.com>

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

* change to currentWorkspace, wrap title using i18n

Signed-off-by: zhichao-aws <zhichaog@amazon.com>

* change import

Signed-off-by: zhichao-aws <zhichaog@amazon.com>

* directly return [] if currentWorkspace is null

Signed-off-by: zhichao-aws <zhichaog@amazon.com>

---------

Signed-off-by: zhichao-aws <zhichaog@amazon.com>

* add workspace switch (opensearch-project#17)

* feat: update workspace switch

Signed-off-by: tygao <tygao@amazon.com>

* fix: fix switch error

Signed-off-by: tygao <tygao@amazon.com>

* fix: fix prettier after merge

Signed-off-by: tygao <tygao@amazon.com>

* chore: remove extra code after merge

Signed-off-by: tygao <tygao@amazon.com>

---------

Signed-off-by: tygao <tygao@amazon.com>

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

Signed-off-by: gaobinlong <gbinlong@amazon.com>

* Delete Workspace (opensearch-project#24)

* add delete workspace modal

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* implement delete on workspace overview page

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* fix export on delete workspace modal

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* add try catch to handle errors for workspace delete

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* move visibility control to workspace overview page exlusively

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* remove unused import

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

---------

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

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

Signed-off-by: Lin Wang <wonglam@amazon.com>

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

* feat: update menu logic

Signed-off-by: tygao <tygao@amazon.com>

* fix: use navLinks to filter

Signed-off-by: tygao <tygao@amazon.com>

---------

Signed-off-by: tygao <tygao@amazon.com>

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

Signed-off-by: Lin Wang <wonglam@amazon.com>

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

* temp: save

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: make create/find support workspaces

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: extract management code

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* fix: type check

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* fix: build error

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: enable workspaces on saved client server side

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: some optimization

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: extract management code

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: merge fix

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: optimize code

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: reuse common function

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: optimize code when create

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: remove useless test code

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

---------

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* 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 <yuyezhu@amazon.com>

* implement delete on workspace overview page

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* fix export on delete workspace modal

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* add try catch to handle errors for workspace delete

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* move visibility control to workspace overview page exlusively

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* remove unused import

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* change workspace overview route to workspace update

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* move delete button from workspace overview page to update page

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* remove update button from workspace overview page

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* recover router to workspace overview page

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

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

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

---------

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* fix: linting error

Signed-off-by: Yulong Ruan <ruanyl@amazon.com>

* remove duplicate EuiPage (opensearch-project#34)

* remove duplicate EuiPage

Signed-off-by: Hailong Cui <ihailong@amazon.com>

* fix: remove duplicate workspace template

Signed-off-by: Hailong Cui <ihailong@amazon.com>

---------

Signed-off-by: Hailong Cui <ihailong@amazon.com>

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

Signed-off-by: zhichao-aws <zhichaog@amazon.com>

* rename OpenSearch Plugins to OpenSearch Features

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

Signed-off-by: Yulong Ruan <ruanyl@amazon.com>

* 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 <suzhou@amazon.com>

* fix: type check

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: update

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

---------

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* 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 <wonglam@amazon.com>

* add new fields to workspace form

Signed-off-by: Lin Wang <wonglam@amazon.com>

* feat: remove feature or group name hack

Signed-off-by: Lin Wang <wonglam@amazon.com>

---------

Signed-off-by: Lin Wang <wonglam@amazon.com>

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

Signed-off-by: tygao <tygao@amazon.com>

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

* feat: register library menus

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: some update

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: optimize code

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: optimize code

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

---------

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>
Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

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

* Exit workspace from left menu

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Show exit workspace button with small window size

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Remove recently viewed and workspace overview on left menu

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Add buttons for outside, inside workspace case

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

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

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Implement workspace dropdown list in left menu

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Add props on recently accessed and custom nav link

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

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

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

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

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Fix bugs for function createWorkspaceNavLink

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Remove unused constants

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Reuse method getWorkspaceUrl

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Remove recently accessed and custom nav props in test

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

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

This reverts commit 7895e5c.

* Wrap title with i18n

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

* Add redirect for workspace app

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

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

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

---------

Signed-off-by: yuye-aws <yuyezhu@amazon.com>

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

* feat: make url stateful

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: optimize code

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: remove useless change

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: optimize url listener

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: make formatUrlWithWorkspaceId extensible

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: modify to related components

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: modify the async format to be sync function

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: modify the async format to be sync function

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* fix: type check

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: use path to maintain workspace info

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: optimize code

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: optimize code

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: optimize code

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: optimize code

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: optimize code

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: optimize code

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

---------

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>
Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

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

* fix: fix build error and some ut

Signed-off-by: tygao <tygao@amazon.com>

* chore: remove saved object client test diff

Signed-off-by: tygao <tygao@amazon.com>

---------

Signed-off-by: tygao <tygao@amazon.com>

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

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

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

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

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

* feat: add workspace permission control interface

Signed-off-by: Lin Wang <wonglam@amazon.com>

* feat: add request parameter for workspace permission control

Signed-off-by: Lin Wang <wonglam@amazon.com>

---------

Signed-off-by: Lin Wang <wonglam@amazon.com>

* temp: save

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: make create/find support workspaces

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: extract management code

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* fix: type check

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* fix: build error

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: enable workspaces on saved client server side

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: extract management code

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: merge fix

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: optimize code

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: remove useless test code

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: integrate with saved object management page

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* Revert "feat: extract management code"

This reverts commit 9c765d2.

* Revert "feat: extract management code"

This reverts commit 526c28e.

* fix: type check

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: update

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: optimize code

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: optimize code

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: remove useless import

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: remove useless import

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: remove useless import

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: refractor workspacesServiceMock

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

* feat: make all test pass

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>

---------

Signed-off-by: Yulong Ruan <ruanyl@amazon.com>
Signed-off-by: Hailong Cui <ihailong@amazon.com>
Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>
Signed-off-by: Lin Wang <wonglam@amazon.com>
Signed-off-by: zhichao-aws <zhichaog@amazon.com>
Signed-off-by: suzhou <suzhou@amazon.com>
Signed-off-by: tygao <tygao@amazon.com>
Signed-off-by: gaobinlong <gbinlong@amazon.com>
Signed-off-by: yuye-aws <yuyezhu@amazon.com>
Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
Co-authored-by: Yulong Ruan <ruanyl@amazon.com>
Co-authored-by: Hailong Cui <ihailong@amazon.com>
Co-authored-by: Lin Wang <wonglam@amazon.com>
Co-authored-by: zhichao-aws <zhichaog@amazon.com>
Co-authored-by: raintygao <tygao@amazon.com>
Co-authored-by: gaobinlong <gbl_long@163.com>
Co-authored-by: Yuye Zhu <yuyezhu@amazon.com>
  • Loading branch information
8 people committed Sep 15, 2023
1 parent fe67d2c commit 58bf926
Show file tree
Hide file tree
Showing 25 changed files with 137 additions and 73 deletions.
2 changes: 1 addition & 1 deletion src/core/public/chrome/chrome_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { notificationServiceMock } from '../notifications/notifications_service.
import { uiSettingsServiceMock } from '../ui_settings/ui_settings_service.mock';
import { ChromeService } from './chrome_service';
import { getAppInfo } from '../application/utils';
import { workspacesServiceMock } from '../fatal_errors/fatal_errors_service.mock';
import { workspacesServiceMock } from '../workspace/workspaces_service.mock';

class FakeApp implements App {
public title = `${this.id} App`;
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/chrome/ui/header/collapsible_nav.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { httpServiceMock } from '../../../http/http_service.mock';
import { ChromeRecentlyAccessedHistoryItem } from '../../recently_accessed';
import { CollapsibleNav } from './collapsible_nav';
import { getLogos } from '../../../../common';
import { workspacesServiceMock } from '../../../fatal_errors/fatal_errors_service.mock';
import { workspacesServiceMock } from '../../../workspace/workspaces_service.mock';

jest.mock('@elastic/eui/lib/services/accessibility/html_id_generator', () => ({
htmlIdGenerator: () => () => 'mockId',
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/chrome/ui/header/header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { httpServiceMock } from '../../../http/http_service.mock';
import { applicationServiceMock, chromeServiceMock } from '../../../mocks';
import { Header } from './header';
import { StubBrowserStorage } from 'test_utils/stub_browser_storage';
import { workspacesServiceMock } from '../../../fatal_errors/fatal_errors_service.mock';
import { workspacesServiceMock } from '../../../workspace/workspaces_service.mock';

jest.mock('@elastic/eui/lib/services/accessibility/html_id_generator', () => ({
htmlIdGenerator: () => () => 'mockId',
Expand Down
34 changes: 0 additions & 34 deletions src/core/public/fatal_errors/fatal_errors_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@

import type { PublicMethodsOf } from '@osd/utility-types';
import { FatalErrorsService, FatalErrorsSetup } from './fatal_errors_service';
import { BehaviorSubject } from 'rxjs';
import { WorkspaceAttribute } from '../workspace';

const createSetupContractMock = () => {
const setupContract: jest.Mocked<FatalErrorsSetup> = {
Expand Down Expand Up @@ -60,35 +58,3 @@ export const fatalErrorsServiceMock = {
createSetupContract: createSetupContractMock,
createStartContract: createStartContractMock,
};

const currentWorkspaceId$ = new BehaviorSubject<string>('');
const workspaceList$ = new BehaviorSubject<WorkspaceAttribute[]>([]);
const currentWorkspace$ = new BehaviorSubject<WorkspaceAttribute | null>(null);

const createWorkspacesSetupContractMock = () => ({
client: {
currentWorkspaceId$,
workspaceList$,
currentWorkspace$,
init: jest.fn(),
stop: jest.fn(),
enterWorkspace: jest.fn(),
exitWorkspace: jest.fn(),
create: jest.fn(),
delete: jest.fn(),
list: jest.fn(),
getCurrentWorkspace: jest.fn(),
getCurrentWorkspaceId: jest.fn(),
get: jest.fn(),
update: jest.fn(),
},
formatUrlWithWorkspaceId: jest.fn(),
setFormatUrlWithWorkspaceId: jest.fn(),
});

const createWorkspacesStartContractMock = createWorkspacesSetupContractMock;

export const workspacesServiceMock = {
createSetupContractMock: createWorkspacesStartContractMock,
createStartContract: createWorkspacesStartContractMock,
};
4 changes: 4 additions & 0 deletions src/core/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock';
import { savedObjectsServiceMock } from './saved_objects/saved_objects_service.mock';
import { contextServiceMock } from './context/context_service.mock';
import { injectedMetadataServiceMock } from './injected_metadata/injected_metadata_service.mock';
import { workspacesServiceMock } from './workspace/workspaces_service.mock';

export { chromeServiceMock } from './chrome/chrome_service.mock';
export { docLinksServiceMock } from './doc_links/doc_links_service.mock';
Expand All @@ -60,6 +61,7 @@ export { uiSettingsServiceMock } from './ui_settings/ui_settings_service.mock';
export { savedObjectsServiceMock } from './saved_objects/saved_objects_service.mock';
export { scopedHistoryMock } from './application/scoped_history.mock';
export { applicationServiceMock } from './application/application_service.mock';
export { workspacesServiceMock } from './workspace/workspaces_service.mock';

function createCoreSetupMock({
basePath = '',
Expand All @@ -85,6 +87,7 @@ function createCoreSetupMock({
getInjectedVar: injectedMetadataServiceMock.createSetupContract().getInjectedVar,
getBranding: injectedMetadataServiceMock.createSetupContract().getBranding,
},
workspaces: workspacesServiceMock,
};

return mock;
Expand All @@ -106,6 +109,7 @@ function createCoreStartMock({ basePath = '' } = {}) {
getBranding: injectedMetadataServiceMock.createStartContract().getBranding,
},
fatalErrors: fatalErrorsServiceMock.createStartContract(),
workspaces: workspacesServiceMock.createStartContract(),
};

return mock;
Expand Down
6 changes: 2 additions & 4 deletions src/core/public/plugins/plugins_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,15 @@ import { applicationServiceMock } from '../application/application_service.mock'
import { i18nServiceMock } from '../i18n/i18n_service.mock';
import { overlayServiceMock } from '../overlays/overlay_service.mock';
import { chromeServiceMock } from '../chrome/chrome_service.mock';
import {
fatalErrorsServiceMock,
workspacesServiceMock,
} from '../fatal_errors/fatal_errors_service.mock';
import { fatalErrorsServiceMock } from '../fatal_errors/fatal_errors_service.mock';
import { uiSettingsServiceMock } from '../ui_settings/ui_settings_service.mock';
import { injectedMetadataServiceMock } from '../injected_metadata/injected_metadata_service.mock';
import { httpServiceMock } from '../http/http_service.mock';
import { CoreSetup, CoreStart, PluginInitializerContext } from '..';
import { docLinksServiceMock } from '../doc_links/doc_links_service.mock';
import { savedObjectsServiceMock } from '../saved_objects/saved_objects_service.mock';
import { contextServiceMock } from '../context/context_service.mock';
import { workspacesServiceMock } from '../workspace/workspaces_service.mock';

export let mockPluginInitializers: Map<PluginName, MockedPluginInitializer>;

Expand Down
39 changes: 39 additions & 0 deletions src/core/public/workspace/workspaces_service.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { BehaviorSubject } from 'rxjs';
import { WorkspaceAttribute } from '../workspace';

const currentWorkspaceId$ = new BehaviorSubject<string>('');
const workspaceList$ = new BehaviorSubject<WorkspaceAttribute[]>([]);
const currentWorkspace$ = new BehaviorSubject<WorkspaceAttribute | null>(null);

const createWorkspacesSetupContractMock = () => ({
client: {
currentWorkspaceId$,
workspaceList$,
currentWorkspace$,
init: jest.fn(),
stop: jest.fn(),
enterWorkspace: jest.fn(),
exitWorkspace: jest.fn(),
create: jest.fn(),
delete: jest.fn(),
list: jest.fn(),
getCurrentWorkspace: jest.fn(),
getCurrentWorkspaceId: jest.fn(),
get: jest.fn(),
update: jest.fn(),
},
formatUrlWithWorkspaceId: jest.fn(),
setFormatUrlWithWorkspaceId: jest.fn(),
});

const createWorkspacesStartContractMock = createWorkspacesSetupContractMock;

export const workspacesServiceMock = {
createSetupContractMock: createWorkspacesStartContractMock,
createStartContract: createWorkspacesStartContractMock,
};
2 changes: 2 additions & 0 deletions src/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,3 +508,5 @@ export const config = {
appenders: appendersSchema as Type<AppenderConfigType>,
},
};

export { formatWorkspaces, workspacesValidator } from './workspaces';
2 changes: 1 addition & 1 deletion src/core/server/saved_objects/routes/bulk_create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

import { schema } from '@osd/config-schema';
import { IRouter } from '../../http';
import { formatWorkspaces, workspacesValidator } from './utils';
import { formatWorkspaces, workspacesValidator } from '../../workspaces';

export const registerBulkCreateRoute = (router: IRouter) => {
router.post(
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/saved_objects/routes/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

import { schema } from '@osd/config-schema';
import { IRouter } from '../../http';
import { formatWorkspaces, workspacesValidator } from './utils';
import { formatWorkspaces, workspacesValidator } from '../../workspaces';

export const registerFindRoute = (router: IRouter) => {
router.get(
Expand Down
3 changes: 2 additions & 1 deletion src/core/server/saved_objects/routes/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import { schema } from '@osd/config-schema';
import { IRouter } from '../../http';
import { importSavedObjectsFromStream } from '../import';
import { SavedObjectConfig } from '../saved_objects_config';
import { createSavedObjectsStreamFromNdJson, formatWorkspaces, workspacesValidator } from './utils';
import { createSavedObjectsStreamFromNdJson } from './utils';
import { formatWorkspaces, workspacesValidator } from '../../workspaces';

interface FileStream extends Readable {
hapi: {
Expand Down
17 changes: 0 additions & 17 deletions src/core/server/saved_objects/routes/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* specific language governing permissions and limitations
* under the License.
*/
import { schema } from '@osd/config-schema';
import { Readable } from 'stream';
import { SavedObject, SavedObjectsExportResultDetails } from 'src/core/server';
import {
Expand Down Expand Up @@ -74,19 +73,3 @@ export function validateObjects(
.join(', ')}`;
}
}

export const workspacesValidator = schema.maybe(
schema.oneOf([schema.string(), schema.arrayOf(schema.string())])
);

export function formatWorkspaces(workspaces?: string | string[]): string[] | undefined {
if (Array.isArray(workspaces)) {
return workspaces;
}

if (!workspaces) {
return undefined;
}

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

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

import { schema } from '@osd/config-schema';

export const workspacesValidator = schema.maybe(
schema.oneOf([schema.string(), schema.arrayOf(schema.string())])
);

export function formatWorkspaces(workspaces?: string | string[]): string[] | undefined {
if (Array.isArray(workspaces)) {
return workspaces;
}

if (!workspaces) {
return undefined;
}

return [workspaces];
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ export async function fetchExportByTypeAndSearch(
http: HttpStart,
types: string[],
search: string | undefined,
includeReferencesDeep: boolean = false
includeReferencesDeep: boolean = false,
body?: Record<string, unknown>
): Promise<Blob> {
return http.post('/api/saved_objects/_export', {
body: JSON.stringify({
...body,
type: types,
search,
includeReferencesDeep,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ import { HttpStart } from 'src/core/public';
export async function fetchExportObjects(
http: HttpStart,
objects: any[],
includeReferencesDeep: boolean = false
includeReferencesDeep: boolean = false,
body?: Record<string, unknown>
): Promise<Blob> {
return http.post('/api/saved_objects/_export', {
body: JSON.stringify({
...body,
objects,
includeReferencesDeep,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface SavedObjectCountOptions {
typesToInclude: string[];
namespacesToInclude?: string[];
searchString?: string;
workspaces?: string[];
}

export async function getSavedObjectCounts(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ interface ImportResponse {
export async function importFile(
http: HttpStart,
file: File,
{ createNewCopies, overwrite }: ImportMode
{ createNewCopies, overwrite, workspaces }: ImportMode
) {
const formData = new FormData();
formData.append('file', file);
const query = createNewCopies ? { createNewCopies } : { overwrite };
const query = createNewCopies ? { createNewCopies, workspaces } : { overwrite, workspaces };
return await http.post<ImportResponse>('/api/saved_objects/_import', {
body: formData,
headers: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export interface FlyoutProps {
overlays: OverlayStart;
http: HttpStart;
search: DataPublicPluginStart['search'];
workspaces?: string[];
}

export interface FlyoutState {
Expand Down Expand Up @@ -183,13 +184,16 @@ export class Flyout extends Component<FlyoutProps, FlyoutState> {
* Does the initial import of a file, resolveImportErrors then handles errors and retries
*/
import = async () => {
const { http } = this.props;
const { http, workspaces } = this.props;
const { file, importMode } = this.state;
this.setState({ status: 'loading', error: undefined });

// Import the file
try {
const response = await importFile(http, file!, importMode);
const response = await importFile(http, file!, {
...importMode,
workspaces,
});
this.setState(processImportResponse(response), () => {
// Resolve import errors right away if there's no index patterns to match
// This will ask about overwriting each object, etc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export interface ImportModeControlProps {
export interface ImportMode {
createNewCopies: boolean;
overwrite: boolean;
workspaces?: string[];
}

const createNewCopiesDisabled = {
Expand Down
Loading

0 comments on commit 58bf926

Please sign in to comment.