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

[Backport 2.x] [Workspace][Bug]Fix workspace detail page issues #8387

Merged
merged 1 commit into from
Sep 30, 2024
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/8317.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Fix workspace detail page issues ([#8317](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8317))
4 changes: 2 additions & 2 deletions src/core/public/application/application_leave.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import {
} from './types';

const appLeaveActionFactory: AppLeaveActionFactory = {
confirm(text: string, title?: string) {
return { type: AppLeaveActionType.confirm, text, title };
confirm(text: string, title?: string, callback?: () => void) {
return { type: AppLeaveActionType.confirm, text, title, callback };
},
default() {
return { type: AppLeaveActionType.default };
Expand Down
3 changes: 3 additions & 0 deletions src/core/public/application/application_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,9 @@
if (!confirmed) {
return false;
}
if (action?.callback) {
action.callback();

Check warning on line 521 in src/core/public/application/application_service.tsx

View check run for this annotation

Codecov / codecov/patch

src/core/public/application/application_service.tsx#L521

Added line #L521 was not covered by tests
}
}
return true;
}
Expand Down
4 changes: 3 additions & 1 deletion src/core/public/application/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ export interface AppLeaveConfirmAction {
type: AppLeaveActionType.confirm;
text: string;
title?: string;
callback?: () => void;
}

/**
Expand All @@ -624,8 +625,9 @@ export interface AppLeaveActionFactory {
*
* @param text The text to display in the confirmation message
* @param title (optional) title to display in the confirmation message
* @param callback (optional) function to execute in the confirmation message
*/
confirm(text: string, title?: string): AppLeaveConfirmAction;
confirm(text: string, title?: string, callback?: () => void): AppLeaveConfirmAction;
/**
* Returns a default action, resulting on executing the default behavior when
* the user tries to leave an application
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/workspace/public/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const renderListApp = (
};

export const renderDetailApp = (
{ element }: AppMountParameters,
{ element, onAppLeave }: AppMountParameters,
services: Services,
props: WorkspaceDetailProps
) => {
Expand All @@ -76,7 +76,7 @@ export const renderDetailApp = (
<Router>
<Switch>
<Route>
<WorkspaceDetailApp {...props} />
<WorkspaceDetailApp {...props} onAppLeave={onAppLeave} />
</Route>
</Switch>
</Router>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ export const UseCaseCardTitle = ({ filterWorkspaces, useCase, core }: UseCaseCar

const iconButton = (
<EuiButtonIcon
aria-label={i18n.translate(`workspace.getStartCard.${useCase.id}.icon.button`, {
defaultMessage: `show available workspace menu for ${useCase}`,
aria-label={i18n.translate(`workspace.getStartCard.{useCaseId}.icon.button`, {
defaultMessage: `show available workspace menu for {useCaseId}`,
values: { useCaseId: useCase.id },
})}
size="xs"
iconType="arrowDown"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,9 @@ describe('SelectDataSourceDetailPanel', () => {
});
const removeButton = getByTestId('workspace-detail-dataSources-table-actions-remove');
fireEvent.click(removeButton);
const confirButton = getByRole('button', { name: 'Remove association(s)' });
expect(confirButton).toBeInTheDocument();
fireEvent.click(confirButton);
const confirmButton = getByRole('button', { name: 'Remove 1 association' });
expect(confirmButton).toBeInTheDocument();
fireEvent.click(confirmButton);
await waitFor(() => {
expect(notificationToastsAddSuccess).toHaveBeenCalled();
});
Expand All @@ -357,9 +357,9 @@ describe('SelectDataSourceDetailPanel', () => {
});
const removeButton = getByTestId('workspace-detail-dataSources-table-actions-remove');
fireEvent.click(removeButton);
const confirButton = getByRole('button', { name: 'Remove association(s)' });
expect(confirButton).toBeInTheDocument();
fireEvent.click(confirButton);
const confirmButton = getByRole('button', { name: 'Remove 1 association' });
expect(confirmButton).toBeInTheDocument();
fireEvent.click(confirmButton);
await waitFor(() => {
expect(notificationToastsAddDanger).toHaveBeenCalled();
});
Expand All @@ -381,9 +381,9 @@ describe('SelectDataSourceDetailPanel', () => {

// Simulate clicking the checkbox
fireEvent.click(checkbox);
expect(getByText('Remove 1 association(s)')).toBeInTheDocument();
fireEvent.click(getByText('Remove 1 association(s)'));
fireEvent.click(getByRole('button', { name: 'Remove association(s)' }));
expect(getByText('Remove 1 association')).toBeInTheDocument();
fireEvent.click(getByText('Remove 1 association'));
fireEvent.click(getByRole('button', { name: 'Remove 1 association' }));
await waitFor(() => {
expect(notificationToastsAddSuccess).toHaveBeenCalled();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,21 @@ export const SelectDataSourceDetailPanel = ({
if (result?.success) {
notifications?.toasts.addSuccess({
title: i18n.translate('workspace.detail.dataSources.assign.success', {
defaultMessage: 'Associate OpenSearch connections successfully',
defaultMessage:
'{numberOfAssignedDataSources, plural, one {The data source has} other {# data sources have}} been associated to the workspace.',
values: { numberOfAssignedDataSources: newAssignedDataSourceConnections.length },
}),
});
setSelectedDataSourceConnections(savedDataSourceConnections);
} else {
throw new Error(result?.error ? result?.error : 'Associate OpenSearch connections failed');
throw new Error(result?.error ? result?.error : 'Associate OpenSearch connections failed.');
}
} catch (error) {
notifications?.toasts.addDanger({
title: i18n.translate('workspace.detail.dataSources.assign.failed', {
defaultMessage: 'Failed to associate OpenSearch connections',
defaultMessage:
'Failed to associate {numberOfAssignedDataSources, plural, one {the data source} other {# data sources}} to the workspace.',
values: { numberOfAssignedDataSources: newAssignedDataSourceConnections.length },
}),
text: error instanceof Error ? error.message : JSON.stringify(error),
});
Expand Down Expand Up @@ -159,19 +163,23 @@ export const SelectDataSourceDetailPanel = ({
if (result?.success) {
notifications?.toasts.addSuccess({
title: i18n.translate('workspace.detail.dataSources.unassign.success', {
defaultMessage: 'The association has been removed',
defaultMessage:
'{numberOfUnAssignedDataSources, plural, one {# association has} other {# associations have}} been removed.',
values: { numberOfUnAssignedDataSources: unAssignedDataSources.length },
}),
});
setSelectedDataSourceConnections(savedDataSourceConnections);
} else {
throw new Error(
result?.error ? result?.error : 'Remove associated OpenSearch connections failed'
result?.error ? result?.error : 'Remove associated OpenSearch connections failed.'
);
}
} catch (error) {
notifications?.toasts.addDanger({
title: i18n.translate('workspace.detail.dataSources.unassign.failed', {
defaultMessage: 'Failed to remove associated OpenSearch connections',
defaultMessage:
'Failed to remove {numberOfUnAssignedDataSources, plural, one {# associated OpenSearch association} other {# associated OpenSearch associations}}.',
values: { numberOfUnAssignedDataSources: unAssignedDataSources.length },
}),
text: error instanceof Error ? error.message : JSON.stringify(error),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { WorkspaceDetail } from './workspace_detail';
import { WorkspaceFormProvider, WorkspaceOperationType } from '../workspace_form';
import { DataSourceConnectionType } from '../../../common/types';
import * as utilsExports from '../../utils';
import { IntlProvider } from 'react-intl';

// all applications
const PublicAPPInfoMap = new Map([
Expand Down Expand Up @@ -136,21 +137,24 @@ const WorkspaceDetailPage = (props: any) => {
const registeredUseCases$ = createMockedRegisteredUseCases$();

return (
<MemoryRouter>
<WorkspaceFormProvider
application={mockCoreStart.application}
savedObjects={mockCoreStart.savedObjects}
operationType={WorkspaceOperationType.Update}
permissionEnabled={true}
onSubmit={jest.fn()}
defaultValues={values}
availableUseCases={[]}
>
<Provider>
<WorkspaceDetail registeredUseCases$={registeredUseCases$} {...props} />
</Provider>
</WorkspaceFormProvider>
</MemoryRouter>
<IntlProvider locale="en">
<MemoryRouter>
<WorkspaceFormProvider
application={mockCoreStart.application}
savedObjects={mockCoreStart.savedObjects}
operationType={WorkspaceOperationType.Update}
permissionEnabled={true}
onSubmit={jest.fn()}
defaultValues={values}
availableUseCases={[]}
onAppLeave={jest.fn()}
>
<Provider>
<WorkspaceDetail registeredUseCases$={registeredUseCases$} {...props} />
</Provider>
</WorkspaceFormProvider>
</MemoryRouter>
</IntlProvider>
);
};

Expand Down Expand Up @@ -254,7 +258,7 @@ describe('WorkspaceDetail', () => {
fireEvent.click(getByText('Cancel'));
expect(queryByText('Any unsaved changes will be lost.')).toBeNull();
fireEvent.click(getByText('Collaborators'));
const button = getByText('Navigate away');
const button = getByText('Confirm');
fireEvent.click(button);
expect(document.querySelector('#collaborators')).toHaveClass('euiTab-isSelected');
});
Expand All @@ -276,7 +280,7 @@ describe('WorkspaceDetail', () => {
fireEvent.click(getByText('+1 more'));
expect(getByText('Any unsaved changes will be lost.')).toBeInTheDocument();

fireEvent.click(getByText('Navigate away'));
fireEvent.click(getByText('Confirm'));
expect(document.querySelector('#collaborators')).toHaveClass('euiTab-isSelected');
});

Expand Down
Loading
Loading