Skip to content

Commit

Permalink
Merge branch 'main' into edit-object
Browse files Browse the repository at this point in the history
  • Loading branch information
SuZhou-Joe authored Sep 2, 2024
2 parents fed356c + 6bd64f2 commit 72748c3
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/7933.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- [Workspace]Redirect to use case landing page after workspace create ([#7933](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7933))
2 changes: 2 additions & 0 deletions changelogs/fragments/7954.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- [Workspace]dynamicConfigServiceMock not found in workspace routes UT ([#7954](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7954))
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const WorkspaceCreator = ({
},
},
navigateToApp,
getUrlForApp: jest.fn(() => '/app/workspace_detail'),
getUrlForApp: jest.fn((appId) => `/app/${appId}`),
applications$: new BehaviorSubject<Map<string, PublicAppInfo>>(PublicAPPInfoMap as any),
},
notifications: {
Expand Down Expand Up @@ -369,4 +369,20 @@ describe('WorkspaceCreator', () => {
expect(workspaceClientCreate).toHaveBeenCalledTimes(2);
});
});

it('should redirect to workspace use case landing page after created successfully', async () => {
const { getByTestId } = render(<WorkspaceCreator />);

// Ensure workspace create form rendered
await waitFor(() => {
expect(getByTestId('workspaceForm-bottomBar-createButton')).toBeInTheDocument();
});
fireEvent.click(getByTestId('workspaceForm-bottomBar-createButton'));
jest.useFakeTimers();
jest.runAllTimers();
await waitFor(() => {
expect(setHrefSpy).toHaveBeenCalledWith(expect.stringContaining('/app/discover'));
});
jest.useRealTimers();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { convertPermissionSettingsToPermissions } from '../workspace_form';
import { DataSource } from '../../../common/types';
import { DataSourceManagementPluginSetup } from '../../../../../plugins/data_source_management/public';
import { WorkspaceUseCase } from '../../types';
import { getFirstUseCaseOfFeatureConfigs } from '../../utils';
import { useFormAvailableUseCases } from '../workspace_form/use_form_available_use_cases';
import { NavigationPublicPluginStart } from '../../../../../plugins/navigation/public';
import { WorkspaceCreatorForm } from './workspace_creator_form';
Expand Down Expand Up @@ -87,10 +88,13 @@ export const WorkspaceCreator = (props: WorkspaceCreatorProps) => {
});
if (application && http) {
const newWorkspaceId = result.result.id;
const useCaseId = getFirstUseCaseOfFeatureConfigs(attributes.features);
const useCaseLandingAppId = availableUseCases?.find(({ id }) => useCaseId === id)
?.features[0].id;
// Redirect page after one second, leave one second time to show create successful toast.
window.setTimeout(() => {
window.location.href = formatUrlWithWorkspaceId(
application.getUrlForApp(WORKSPACE_DETAIL_APP_ID, {
application.getUrlForApp(useCaseLandingAppId || WORKSPACE_DETAIL_APP_ID, {
absolute: true,
}),
newWorkspaceId,
Expand All @@ -114,7 +118,7 @@ export const WorkspaceCreator = (props: WorkspaceCreatorProps) => {
setIsFormSubmitting(false);
}
},
[notifications?.toasts, http, application, workspaceClient, isFormSubmitting]
[notifications?.toasts, http, application, workspaceClient, isFormSubmitting, availableUseCases]
);

const isFormReadyToRender =
Expand Down
4 changes: 1 addition & 3 deletions src/plugins/workspace/server/routes/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import supertest from 'supertest';
import { UnwrapPromise } from '@osd/utility-types';

import { setupServer } from '../../../../core/server/test_utils';
import { loggingSystemMock } from '../../../../core/server/mocks';
// eslint-disable-next-line @osd/eslint/no-restricted-paths
import { dynamicConfigServiceMock } from '../../../../core/server/config';
import { loggingSystemMock, dynamicConfigServiceMock } from '../../../../core/server/mocks';

import { workspaceClientMock } from '../workspace_client.mock';

Expand Down

0 comments on commit 72748c3

Please sign in to comment.