Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Workspace]Redirect to use case landing page after workspace create #7933

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading