Skip to content

Commit

Permalink
Refactor workspace datasource association (#8545)
Browse files Browse the repository at this point in the history
* refactor: add data source association button to data source management page

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

* feat: add action button to dissociate data source from data source table

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

* Changeset file for PR #8545 created/updated

* fix: automatically set a default data source if default data source been dissociated

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

* feat: implement bulk dissociate in data source management page

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

* fix lint

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

---------

Signed-off-by: Yulong Ruan <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
  • Loading branch information
ruanyl and opensearch-changeset-bot[bot] authored Oct 12, 2024
1 parent c4049eb commit fc03639
Show file tree
Hide file tree
Showing 22 changed files with 1,346 additions and 172 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/8545.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Refactor data source list page to include data source association features for workspace ([#8545](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8545))
1 change: 1 addition & 0 deletions src/core/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ export {
WorkspacesService,
WorkspaceObject,
IWorkspaceClient,
IWorkspaceResponse,
} from './workspace';

export { debounce } from './utils';
10 changes: 3 additions & 7 deletions src/core/public/workspace/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

export {
WorkspacesStart,
WorkspacesService,
WorkspacesSetup,
WorkspaceObject,
IWorkspaceClient,
} from './workspaces_service';
export { WorkspacesStart, WorkspacesService, WorkspacesSetup } from './workspaces_service';

export { IWorkspaceClient, IWorkspaceResponse, WorkspaceObject } from './types';
87 changes: 87 additions & 0 deletions src/core/public/workspace/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { WorkspaceAttribute } from '../../types';

export type WorkspaceObject = WorkspaceAttribute & { readonly?: boolean };

export type IWorkspaceResponse<T> =
| {
result: T;
success: true;
}
| {
success: false;
error?: string;
};

export interface AssociationResult {
id: string;
error?: string;
}

/**
* This interface representing a client for managing workspace-related operations.
* Workspace client should implement this interface.
*
* TODO: Refactor the current workspace client implementation in workspace plugin to add the missing operations to this interface
*/
export interface IWorkspaceClient {
/**
* copy saved objects to target workspace
*
* @param {Array<{ id: string; type: string }>} objects
* @param {string} targetWorkspace
* @param {boolean} includeReferencesDeep
* @returns {Promise<IResponse<any>>} result for this operation
*/
copy(objects: any[], targetWorkspace: string, includeReferencesDeep?: boolean): Promise<any>;

/**
* Associates a list of objects with the given workspace ID.
*
* This method takes a workspace ID and an array of objects, where each object contains
* an `id` and `type`. It attempts to associate each object with the specified workspace.
* If the association succeeds, the object is included in the result without an error.
* If there is an issue associating an object, an error message is returned for that object.
*
* @returns A promise that resolves to a response object containing an array of results for each object.
* Each result will include the object's `id` and, if there was an error during association, an `error` field
* with the error message.
*/
associate(
savedObjects: Array<{ id: string; type: string }>,
workspaceId: string
): Promise<IWorkspaceResponse<AssociationResult[]>>;

/**
* Dissociates a list of objects from the given workspace ID.
*
* This method takes a workspace ID and an array of objects, where each object contains
* an `id` and `type`. It attempts to dissociate each object from the specified workspace.
* If the dissociation succeeds, the object is included in the result without an error.
* If there is an issue dissociating an object, an error message is returned for that object.
*
* @returns A promise that resolves to a response object containing an array of results for each object.
* Each result will include the object's `id` and, if there was an error during dissociation, an `error` field
* with the error message.
*/
dissociate(
savedObjects: Array<{ id: string; type: string }>,
workspaceId: string
): Promise<IWorkspaceResponse<AssociationResult[]>>;

ui(): WorkspaceUI;
}

interface DataSourceAssociationProps {
excludedDataSourceIds: string[];
onComplete?: () => void;
onError?: () => void;
}

export interface WorkspaceUI {
DataSourceAssociation: (props: DataSourceAssociationProps) => JSX.Element;
}
3 changes: 2 additions & 1 deletion src/core/public/workspace/workspaces_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import { BehaviorSubject } from 'rxjs';
import type { PublicMethodsOf } from '@osd/utility-types';

import { WorkspacesService, WorkspaceObject, IWorkspaceClient } from './workspaces_service';
import { IWorkspaceClient, WorkspaceObject } from './types';
import { WorkspacesService } from './workspaces_service';

const createWorkspacesSetupContractMock = () => {
const currentWorkspaceId$ = new BehaviorSubject<string>('');
Expand Down
15 changes: 8 additions & 7 deletions src/core/public/workspace/workspaces_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

import {
WorkspacesService,
WorkspacesSetup,
WorkspacesStart,
IWorkspaceClient,
} from './workspaces_service';
import { IWorkspaceClient } from './types';
import { WorkspacesService, WorkspacesSetup, WorkspacesStart } from './workspaces_service';

describe('WorkspacesService', () => {
let workspaces: WorkspacesService;
Expand Down Expand Up @@ -43,7 +39,12 @@ describe('WorkspacesService', () => {
});

it('client is updated when set client', () => {
const client: IWorkspaceClient = { copy: jest.fn() };
const client: IWorkspaceClient = {
copy: jest.fn(),
associate: jest.fn(),
dissociate: jest.fn(),
ui: jest.fn(),
};
workspacesSetUp.setClient(client);
expect(workspacesStart.client$.value).toEqual(client);
});
Expand Down
9 changes: 2 additions & 7 deletions src/core/public/workspace/workspaces_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@
import { BehaviorSubject, combineLatest } from 'rxjs';
import { isEqual } from 'lodash';

import { CoreService, WorkspaceAttribute } from '../../types';

export type WorkspaceObject = WorkspaceAttribute & { readonly?: boolean };

export interface IWorkspaceClient {
copy(objects: any[], targetWorkspace: string, includeReferencesDeep?: boolean): Promise<any>;
}
import { CoreService } from '../../types';
import { IWorkspaceClient, WorkspaceObject } from './types';

interface WorkspaceObservables {
/**
Expand Down
Loading

0 comments on commit fc03639

Please sign in to comment.