Skip to content

Commit b612f70

Browse files
opensearch-trigger-bot[bot]github-actions[bot]opensearch-changeset-bot[bot]SuZhou-Joe
authored
[Workspace]Redirect to use case landing page after workspace create (opensearch-project#7933) (opensearch-project#7993) (opensearch-project#8047)
* Redirect to use case landing page after workspace create * Changeset file for PR opensearch-project#7933 created/updated --------- (cherry picked from commit 6bd64f2) (cherry picked from commit 624c692) Signed-off-by: Lin Wang <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> Co-authored-by: SuZhou-Joe <[email protected]>
1 parent 52e3800 commit b612f70

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

changelogs/fragments/7933.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
feat:
2+
- [Workspace]Redirect to use case landing page after workspace create ([#7933](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7933))

src/plugins/workspace/public/components/workspace_creator/workspace_creator.test.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const WorkspaceCreator = ({
6767
},
6868
},
6969
navigateToApp,
70-
getUrlForApp: jest.fn(() => '/app/workspace_detail'),
70+
getUrlForApp: jest.fn((appId) => `/app/${appId}`),
7171
applications$: new BehaviorSubject<Map<string, PublicAppInfo>>(PublicAPPInfoMap as any),
7272
},
7373
notifications: {
@@ -369,4 +369,20 @@ describe('WorkspaceCreator', () => {
369369
expect(workspaceClientCreate).toHaveBeenCalledTimes(2);
370370
});
371371
});
372+
373+
it('should redirect to workspace use case landing page after created successfully', async () => {
374+
const { getByTestId } = render(<WorkspaceCreator />);
375+
376+
// Ensure workspace create form rendered
377+
await waitFor(() => {
378+
expect(getByTestId('workspaceForm-bottomBar-createButton')).toBeInTheDocument();
379+
});
380+
fireEvent.click(getByTestId('workspaceForm-bottomBar-createButton'));
381+
jest.useFakeTimers();
382+
jest.runAllTimers();
383+
await waitFor(() => {
384+
expect(setHrefSpy).toHaveBeenCalledWith(expect.stringContaining('/app/discover'));
385+
});
386+
jest.useRealTimers();
387+
});
372388
});

src/plugins/workspace/public/components/workspace_creator/workspace_creator.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { convertPermissionSettingsToPermissions } from '../workspace_form';
1818
import { DataSource } from '../../../common/types';
1919
import { DataSourceManagementPluginSetup } from '../../../../../plugins/data_source_management/public';
2020
import { WorkspaceUseCase } from '../../types';
21+
import { getFirstUseCaseOfFeatureConfigs } from '../../utils';
2122
import { useFormAvailableUseCases } from '../workspace_form/use_form_available_use_cases';
2223
import { NavigationPublicPluginStart } from '../../../../../plugins/navigation/public';
2324
import { WorkspaceCreatorForm } from './workspace_creator_form';
@@ -87,10 +88,13 @@ export const WorkspaceCreator = (props: WorkspaceCreatorProps) => {
8788
});
8889
if (application && http) {
8990
const newWorkspaceId = result.result.id;
91+
const useCaseId = getFirstUseCaseOfFeatureConfigs(attributes.features);
92+
const useCaseLandingAppId = availableUseCases?.find(({ id }) => useCaseId === id)
93+
?.features[0].id;
9094
// Redirect page after one second, leave one second time to show create successful toast.
9195
window.setTimeout(() => {
9296
window.location.href = formatUrlWithWorkspaceId(
93-
application.getUrlForApp(WORKSPACE_DETAIL_APP_ID, {
97+
application.getUrlForApp(useCaseLandingAppId || WORKSPACE_DETAIL_APP_ID, {
9498
absolute: true,
9599
}),
96100
newWorkspaceId,
@@ -114,7 +118,7 @@ export const WorkspaceCreator = (props: WorkspaceCreatorProps) => {
114118
setIsFormSubmitting(false);
115119
}
116120
},
117-
[notifications?.toasts, http, application, workspaceClient, isFormSubmitting]
121+
[notifications?.toasts, http, application, workspaceClient, isFormSubmitting, availableUseCases]
118122
);
119123

120124
const isFormReadyToRender =

0 commit comments

Comments
 (0)