Skip to content

Commit

Permalink
[Workspace] Update workspace list page table (#7640)
Browse files Browse the repository at this point in the history
* the table basically works

Signed-off-by: Qxisylolo <qianxisy@amazon.com>

* the table basically works new

Signed-off-by: Qxisylolo <qianxisy@amazon.com>

* This time I achieve the functionality and apprearence of the workLists table

Signed-off-by: Qxisylolo <qianxisy@amazon.com>

* This time I achieve the functionality and apprearence of the workLists table, add tests

Signed-off-by: Qxisylolo <qianxisy@amazon.com>

* This time I achieve the functionality and apprearence of the workLists table, add tests

Signed-off-by: Qxisylolo <qianxisy@amazon.com>

* Achieve the functionality and apprearence of the workLists table, and add tests

Signed-off-by: Qxisylolo <qianxisy@amazon.com>

* Changeset file for PR #7640 created/updated

* Changeset file for PR #7640 created/updated

* Changeset file for PR #7640 created/updated

* Achieve the functionality and apprearence of the work List table page, add tests, and refine based the comments

Signed-off-by: Qxisylolo <qianxisy@amazon.com>

* Achieve the functionality and apprearence of the work List table page, add tests, and update based the comments

Signed-off-by: Qxisylolo <qianxisy@amazon.com>

* Achieve the functionality and apprearence of the work List table page, add tests, and update based the comment-1

Signed-off-by: Qxisylolo <qianxisy@amazon.com>

* Achieve the functionality and apprearence of the work List table page, add tests, and update based the comment-1

Signed-off-by: Qxisylolo <qianxisy@amazon.com>

* Enable multiple deletion and correct the code based on comments

Signed-off-by: Qxisylolo <qianxisy@amazon.com>

* Enable multiple deletion and correct the code based on comments

Signed-off-by: Qxisylolo <qianxisy@amazon.com>

* set the advanced date format

Signed-off-by: Qxisylolo <qianxisy@amazon.com>

* set advanced time format and tests

Signed-off-by: Qxisylolo <qianxisy@amazon.com>

---------

Signed-off-by: Qxisylolo <qianxisy@amazon.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
(cherry picked from commit e70bfad)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and SuZhou-Joe committed Aug 26, 2024
1 parent ccec03d commit 361be76
Show file tree
Hide file tree
Showing 7 changed files with 805 additions and 410 deletions.
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

0 comments on commit 361be76

Please sign in to comment.