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] Update workspace list page table #7640

Merged
merged 18 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
41c8d00
the table basically works
Qxisylolo Aug 5, 2024
e76395c
the table basically works new
Qxisylolo Aug 6, 2024
d601e94
This time I achieve the functionality and apprearence of the workList…
Qxisylolo Aug 7, 2024
c77079f
This time I achieve the functionality and apprearence of the workList…
Qxisylolo Aug 7, 2024
c6323e8
This time I achieve the functionality and apprearence of the workList…
Qxisylolo Aug 7, 2024
2f03420
Achieve the functionality and apprearence of the workLists table, and…
Qxisylolo Aug 7, 2024
a577aa4
Changeset file for PR #7640 created/updated
opensearch-changeset-bot[bot] Aug 7, 2024
d368602
Changeset file for PR #7640 created/updated
opensearch-changeset-bot[bot] Aug 7, 2024
670b04c
Changeset file for PR #7640 created/updated
opensearch-changeset-bot[bot] Aug 7, 2024
220a4f0
Achieve the functionality and apprearence of the work List table page…
Qxisylolo Aug 8, 2024
3b3850d
Achieve the functionality and apprearence of the work List table page…
Qxisylolo Aug 8, 2024
9b3410f
Achieve the functionality and apprearence of the work List table page…
Qxisylolo Aug 8, 2024
86b4513
Achieve the functionality and apprearence of the work List table page…
Qxisylolo Aug 8, 2024
18ba7ca
Enable multiple deletion and correct the code based on comments
Qxisylolo Aug 8, 2024
62e451a
Enable multiple deletion and correct the code based on comments
Qxisylolo Aug 9, 2024
4b26196
set the advanced date format
Qxisylolo Aug 14, 2024
9fc525c
set advanced time format and tests
Qxisylolo Aug 14, 2024
94703a0
Merge main branch
Qxisylolo Aug 15, 2024
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/7640.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- [Workspace] Update workspace list page table ([#7640](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7640))

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 @@ -12,7 +12,7 @@ import { OpenSearchDashboardsContextProvider } from '../../../../../plugins/open

const defaultProps: DeleteWorkspaceModalProps = {
onClose: jest.fn(),
selectedWorkspace: null,
selectedWorkspaces: [],
onDeleteSuccess: jest.fn(),
};

Expand Down Expand Up @@ -63,10 +63,12 @@ describe('DeleteWorkspaceModal', () => {
const onDeleteSuccessFn = jest.fn();
const newProps = {
...defaultProps,
selectedWorkspace: {
id: 'test',
name: 'test',
},
selectedWorkspaces: [
{
id: 'test',
name: 'test',
},
],
onClose: onCloseFn,
onDeleteSuccess: onDeleteSuccessFn,
};
Expand Down Expand Up @@ -99,10 +101,10 @@ describe('DeleteWorkspaceModal', () => {
});
});

it('should not call deleteWorkspace if passed selectedWorkspace is null', async () => {
it('should not call deleteWorkspace modal if passed selectedWorkspace is null', async () => {
const newProps = {
...defaultProps,
selectedWorkspace: null,
selectedWorkspace: [],
};
const deleteFn = jest.fn().mockReturnValue({
success: true,
Expand All @@ -114,26 +116,20 @@ describe('DeleteWorkspaceModal', () => {
delete: deleteFn,
},
};
const { getByTestId, findByTestId } = render(
getWrapWorkspaceDeleteModalInContext(newProps, newServices)
);
await findByTestId('delete-workspace-modal-input');
const input = getByTestId('delete-workspace-modal-input');
fireEvent.change(input, {
target: { value: 'delete' },
});
const confirmButton = getByTestId('delete-workspace-modal-confirm');
fireEvent.click(confirmButton);
expect(deleteFn).not.toHaveBeenCalled();
const { queryByTestId } = render(getWrapWorkspaceDeleteModalInContext(newProps, newServices));
const input = queryByTestId('delete-workspace-modal-input');
expect(input).not.toBeInTheDocument();
});

it('should add danger is returned data is unsuccess', async () => {
it('should add danger if returned data is unsuccess', async () => {
const newProps = {
...defaultProps,
selectedWorkspace: {
id: 'test',
name: 'test',
},
selectedWorkspaces: [
{
id: 'test',
name: 'test',
},
],
};
const deleteFn = jest.fn().mockReturnValue({
success: false,
Expand Down Expand Up @@ -165,10 +161,12 @@ describe('DeleteWorkspaceModal', () => {
it('confirm button should be disabled if not input delete', async () => {
const newProps = {
...defaultProps,
selectedWorkspace: {
id: 'test',
name: 'test',
},
selectedWorkspaces: [
{
id: 'test',
name: 'test',
},
],
};
const deleteFn = jest.fn().mockReturnValue({
success: false,
Expand All @@ -186,7 +184,7 @@ describe('DeleteWorkspaceModal', () => {
await findByTestId('delete-workspace-modal-input');
const input = getByTestId('delete-workspace-modal-input');
fireEvent.change(input, {
target: { value: 'delet' },
target: { value: 'delete' },
});
const confirmButton = getByTestId('delete-workspace-modal-confirm');
expect(confirmButton.hasAttribute('disabled'));
Expand All @@ -196,10 +194,12 @@ describe('DeleteWorkspaceModal', () => {
const onCloseFn = jest.fn();
const newProps = {
...defaultProps,
selectedWorkspace: {
id: 'test',
name: 'test',
},
selectedWorkspaces: [
{
id: 'test',
name: 'test',
},
],
onclose: onCloseFn,
};
const deleteFn = jest.fn().mockImplementation(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,49 +23,53 @@ import { WorkspaceClient } from '../../workspace_client';

export interface DeleteWorkspaceModalProps {
onClose: () => void;
selectedWorkspace?: WorkspaceAttribute | null;
selectedWorkspaces?: WorkspaceAttribute[];
onDeleteSuccess?: () => void;
}

export function DeleteWorkspaceModal(props: DeleteWorkspaceModalProps) {
const [value, setValue] = useState('');
const { onClose, selectedWorkspace, onDeleteSuccess } = props;
const { onClose, selectedWorkspaces, onDeleteSuccess } = props;
const {
services: { notifications, workspaceClient },
} = useOpenSearchDashboards<{ workspaceClient: WorkspaceClient }>();

const deleteWorkspace = async () => {
if (selectedWorkspace?.id) {
let result;
try {
result = await workspaceClient.delete(selectedWorkspace?.id);
} catch (error) {
notifications?.toasts.addDanger({
title: i18n.translate('workspace.delete.failed', {
defaultMessage: 'Failed to delete workspace',
}),
text: error instanceof Error ? error.message : JSON.stringify(error),
});
return onClose();
}
if (result?.success) {
notifications?.toasts.addSuccess({
title: i18n.translate('workspace.delete.success', {
defaultMessage: 'Delete workspace successfully',
}),
});
onClose();
if (onDeleteSuccess) {
onDeleteSuccess();
const deleteWorkspaces = async () => {
if (selectedWorkspaces && selectedWorkspaces.length > 0) {
selectedWorkspaces.forEach(async (selectedWorkspace) => {
if (selectedWorkspace?.id) {
let result;
try {
result = await workspaceClient.delete(selectedWorkspace?.id);
} catch (error) {
notifications?.toasts.addDanger({
title: i18n.translate('workspace.delete.failed', {
defaultMessage: 'Failed to delete workspace',
}),
text: error instanceof Error ? error.message : JSON.stringify(error),
});
return onClose();
}
if (result?.success) {
notifications?.toasts.addSuccess({
title: i18n.translate('workspace.delete.success', {
defaultMessage: 'Delete workspace successfully',
}),
});
onClose();
if (onDeleteSuccess) {
onDeleteSuccess();
}
} else {
notifications?.toasts.addDanger({
title: i18n.translate('workspace.delete.failed', {
defaultMessage: 'Failed to delete workspace',
}),
text: result?.error,
});
}
}
} else {
notifications?.toasts.addDanger({
title: i18n.translate('workspace.delete.failed', {
defaultMessage: 'Failed to delete workspace',
}),
text: result?.error,
});
}
});
}
};

Expand All @@ -76,23 +80,31 @@ export function DeleteWorkspaceModal(props: DeleteWorkspaceModalProps) {
</EuiModalHeader>

<EuiModalBody data-test-subj="delete-workspace-modal-body">
<div style={{ lineHeight: 1.5 }}>
<p>The following workspace will be permanently deleted. This action cannot be undone.</p>
<ul style={{ listStyleType: 'disc', listStylePosition: 'inside' }}>
{selectedWorkspace?.name ? <li>{selectedWorkspace.name}</li> : null}
</ul>
<EuiSpacer />
<EuiText color="subdued">
To confirm your action, type <b>delete</b>.
</EuiText>
<EuiCompressedFieldText
placeholder="delete"
fullWidth
value={value}
data-test-subj="delete-workspace-modal-input"
onChange={(e) => setValue(e.target.value)}
/>
</div>
{selectedWorkspaces && selectedWorkspaces.length > 0 ? (
<div style={{ lineHeight: 1.5 }}>
<p>
The following workspace will be permanently deleted. This action cannot be undone.
</p>
<ul style={{ listStyleType: 'disc', listStylePosition: 'inside' }}>
{selectedWorkspaces.map((selectedWorkspace) => {
return selectedWorkspace?.name ? (
<li key={selectedWorkspace.id}>{selectedWorkspace.name}</li>
) : null;
})}
</ul>
<EuiSpacer />
<EuiText color="subdued">
To confirm your action, type <b>delete</b>.
</EuiText>
<EuiCompressedFieldText
placeholder="delete"
fullWidth
value={value}
data-test-subj="delete-workspace-modal-input"
onChange={(e) => setValue(e.target.value)}
/>
</div>
) : null}
</EuiModalBody>

<EuiModalFooter>
Expand All @@ -104,7 +116,7 @@ export function DeleteWorkspaceModal(props: DeleteWorkspaceModalProps) {
</EuiSmallButtonEmpty>
<EuiSmallButton
data-test-subj="delete-workspace-modal-confirm"
onClick={deleteWorkspace}
onClick={deleteWorkspaces}
fill
color="danger"
disabled={value !== 'delete'}
Expand Down
Loading
Loading