Skip to content

Commit

Permalink
[Workspace]Redirect to use case landing page after workspace create (o…
Browse files Browse the repository at this point in the history
…pensearch-project#7933) (opensearch-project#7993)

* Redirect to use case landing page after workspace create



* Changeset file for PR opensearch-project#7933 created/updated

---------




(cherry picked from commit 6bd64f2)

Signed-off-by: Lin Wang <wonglam@amazon.com>
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 <suzhou@amazon.com>
  • Loading branch information
4 people authored Sep 4, 2024
1 parent 3d7b9ed commit 624c692
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 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))
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

0 comments on commit 624c692

Please sign in to comment.