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)

* Redirect to use case landing page after workspace create

Signed-off-by: Lin Wang <[email protected]>

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

---------

Signed-off-by: Lin Wang <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Co-authored-by: SuZhou-Joe <[email protected]>
  • Loading branch information
3 people committed Sep 3, 2024
1 parent b1d7ee6 commit 7450e2e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 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 @@ -17,7 +17,7 @@ import { convertPermissionSettingsToPermissions } from '../workspace_form';
import { DataSource } from '../../../common/types';
import { DataSourceManagementPluginSetup } from '../../../../../plugins/data_source_management/public';
import { WorkspaceUseCase } from '../../types';
import { getUseCaseFeatureConfig } from '../../utils';
import { getUseCaseFeatureConfig, 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 +87,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 +117,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 7450e2e

Please sign in to comment.