diff --git a/src/plugins/workspace/public/application.tsx b/src/plugins/workspace/public/application.tsx
index 98ddb6610864..5440d98e6945 100644
--- a/src/plugins/workspace/public/application.tsx
+++ b/src/plugins/workspace/public/application.tsx
@@ -9,6 +9,7 @@ import { AppMountParameters, ScopedHistory } from '../../../core/public';
import { OpenSearchDashboardsContextProvider } from '../../opensearch_dashboards_react/public';
import { WorkspaceFatalError } from './components/workspace_fatal_error';
import { WorkspaceCreatorApp } from './components/workspace_creator_app';
+import { WorkspaceUpdaterApp } from './components/workspace_updater_app';
import { WorkspaceListApp } from './components/workspace_list_app';
import { Services } from './types';
@@ -25,6 +26,19 @@ export const renderCreatorApp = ({ element }: AppMountParameters, services: Serv
};
};
+export const renderUpdaterApp = ({ element }: AppMountParameters, services: Services) => {
+ ReactDOM.render(
+
+
+ ,
+ element
+ );
+
+ return () => {
+ ReactDOM.unmountComponentAtNode(element);
+ };
+};
+
export const renderFatalErrorApp = (params: AppMountParameters, services: Services) => {
const { element } = params;
const history = params.history as ScopedHistory<{ error?: string }>;
diff --git a/src/plugins/workspace/public/components/workspace_creator/workspace_creator.tsx b/src/plugins/workspace/public/components/workspace_creator/workspace_creator.tsx
index 83d0f6675fe6..0ba7ca9947df 100644
--- a/src/plugins/workspace/public/components/workspace_creator/workspace_creator.tsx
+++ b/src/plugins/workspace/public/components/workspace_creator/workspace_creator.tsx
@@ -22,6 +22,29 @@ export const WorkspaceCreator = () => {
let result;
try {
result = await workspaceClient.create(data);
+ if (result?.success) {
+ notifications?.toasts.addSuccess({
+ title: i18n.translate('workspace.create.success', {
+ defaultMessage: 'Create workspace successfully',
+ }),
+ });
+ if (application && http) {
+ const newWorkspaceId = result.result.id;
+ // Redirect page after one second, leave one second time to show create successful toast.
+ window.setTimeout(() => {
+ window.location.href = formatUrlWithWorkspaceId(
+ application.getUrlForApp(WORKSPACE_OVERVIEW_APP_ID, {
+ absolute: true,
+ }),
+ newWorkspaceId,
+ http.basePath
+ );
+ }, 1000);
+ }
+ return;
+ } else {
+ throw new Error(result?.error ? result?.error : 'create workspace failed');
+ }
} catch (error) {
notifications?.toasts.addDanger({
title: i18n.translate('workspace.create.failed', {
@@ -31,33 +54,6 @@ export const WorkspaceCreator = () => {
});
return;
}
- if (result?.success) {
- notifications?.toasts.addSuccess({
- title: i18n.translate('workspace.create.success', {
- defaultMessage: 'Create workspace successfully',
- }),
- });
- if (application && http) {
- const newWorkspaceId = result.result.id;
- // Redirect page after one second, leave one second time to show create successful toast.
- window.setTimeout(() => {
- window.location.href = formatUrlWithWorkspaceId(
- application.getUrlForApp(WORKSPACE_OVERVIEW_APP_ID, {
- absolute: true,
- }),
- newWorkspaceId,
- http.basePath
- );
- }, 1000);
- }
- return;
- }
- notifications?.toasts.addDanger({
- title: i18n.translate('workspace.create.failed', {
- defaultMessage: 'Failed to create workspace',
- }),
- text: result?.error,
- });
},
[notifications?.toasts, http, application, workspaceClient]
);
diff --git a/src/plugins/workspace/public/components/workspace_form/workspace_bottom_bar.tsx b/src/plugins/workspace/public/components/workspace_form/workspace_bottom_bar.tsx
index 7e528d2214ee..34d5ca6359e1 100644
--- a/src/plugins/workspace/public/components/workspace_form/workspace_bottom_bar.tsx
+++ b/src/plugins/workspace/public/components/workspace_form/workspace_bottom_bar.tsx
@@ -92,7 +92,13 @@ export const WorkspaceBottomBar = ({
)}
{operationType === WorkspaceOperationType.Update && (
-
+
{i18n.translate('workspace.form.bottomBar.saveChanges', {
defaultMessage: 'Save changes',
})}
diff --git a/src/plugins/workspace/public/components/workspace_updater/index.tsx b/src/plugins/workspace/public/components/workspace_updater/index.tsx
new file mode 100644
index 000000000000..711f19fd25f6
--- /dev/null
+++ b/src/plugins/workspace/public/components/workspace_updater/index.tsx
@@ -0,0 +1,6 @@
+/*
+ * Copyright OpenSearch Contributors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+export { WorkspaceUpdater } from './workspace_updater';
diff --git a/src/plugins/workspace/public/components/workspace_updater/workspace_updater.test.tsx b/src/plugins/workspace/public/components/workspace_updater/workspace_updater.test.tsx
new file mode 100644
index 000000000000..d829154426dd
--- /dev/null
+++ b/src/plugins/workspace/public/components/workspace_updater/workspace_updater.test.tsx
@@ -0,0 +1,239 @@
+/*
+ * Copyright OpenSearch Contributors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import React from 'react';
+import { PublicAppInfo, WorkspaceObject } from 'opensearch-dashboards/public';
+import { fireEvent, render, waitFor } from '@testing-library/react';
+import { BehaviorSubject } from 'rxjs';
+import { WorkspaceUpdater as WorkspaceCreatorComponent } from './workspace_updater';
+import { coreMock, workspacesServiceMock } from '../../../../../core/public/mocks';
+import { createOpenSearchDashboardsReactContext } from '../../../../opensearch_dashboards_react/public';
+
+const workspaceClientUpdate = jest.fn().mockReturnValue({ result: true, success: true });
+
+const navigateToApp = jest.fn();
+const notificationToastsAddSuccess = jest.fn();
+const notificationToastsAddDanger = jest.fn();
+const PublicAPPInfoMap = new Map([
+ ['app1', { id: 'app1', title: 'app1' }],
+ ['app2', { id: 'app2', title: 'app2', category: { id: 'category1', label: 'category1' } }],
+ ['app3', { id: 'app3', category: { id: 'category1', label: 'category1' } }],
+ ['app4', { id: 'app4', category: { id: 'category2', label: 'category2' } }],
+ ['app5', { id: 'app5', category: { id: 'category2', label: 'category2' } }],
+]);
+const createWorkspacesSetupContractMockWithValue = () => {
+ const currentWorkspaceId$ = new BehaviorSubject('abljlsds');
+ const currentWorkspace: WorkspaceObject = {
+ id: 'abljlsds',
+ name: 'test1',
+ description: 'test1',
+ features: [],
+ color: '',
+ icon: '',
+ reserved: false,
+ };
+ const workspaceList$ = new BehaviorSubject([currentWorkspace]);
+ const currentWorkspace$ = new BehaviorSubject(currentWorkspace);
+ const initialized$ = new BehaviorSubject(false);
+ return {
+ currentWorkspaceId$,
+ workspaceList$,
+ currentWorkspace$,
+ initialized$,
+ };
+};
+
+const mockCoreStart = coreMock.createStart();
+
+const WorkspaceUpdater = (props: any) => {
+ const workspacesService = props.workspacesService || createWorkspacesSetupContractMockWithValue();
+ const { Provider } = createOpenSearchDashboardsReactContext({
+ ...mockCoreStart,
+ ...{
+ application: {
+ ...mockCoreStart.application,
+ capabilities: {
+ ...mockCoreStart.application.capabilities,
+ },
+ navigateToApp,
+ getUrlForApp: jest.fn(() => '/app/workspace_overview'),
+ applications$: new BehaviorSubject