mirror of
https://github.com/strapi/strapi.git
synced 2025-07-25 18:05:07 +00:00
delete all + test confirmation dialog
This commit is contained in:
parent
4a49fc57a3
commit
cd43b8949f
@ -15,14 +15,14 @@ import {
|
|||||||
useFocusWhenNavigate,
|
useFocusWhenNavigate,
|
||||||
SettingsPageTitle,
|
SettingsPageTitle,
|
||||||
} from '@strapi/helper-plugin';
|
} from '@strapi/helper-plugin';
|
||||||
import { HeaderLayout, Layout, ContentLayout } from '@strapi/parts/Layout';
|
import { HeaderLayout, Layout, ContentLayout, ActionLayout } from '@strapi/parts/Layout';
|
||||||
import { EmptyStateLayout } from '@strapi/parts/EmptyStateLayout';
|
import { EmptyStateLayout } from '@strapi/parts/EmptyStateLayout';
|
||||||
import { Row } from '@strapi/parts/Row';
|
import { Row } from '@strapi/parts/Row';
|
||||||
import { Stack } from '@strapi/parts/Stack';
|
import { Stack } from '@strapi/parts/Stack';
|
||||||
import { IconButton } from '@strapi/parts/IconButton';
|
import { IconButton } from '@strapi/parts/IconButton';
|
||||||
import { BaseCheckbox } from '@strapi/parts/BaseCheckbox';
|
import { BaseCheckbox } from '@strapi/parts/BaseCheckbox';
|
||||||
import { Table, Thead, Tr, Th, Tbody, Td, TFooter } from '@strapi/parts/Table';
|
import { Table, Thead, Tr, Th, Tbody, Td, TFooter } from '@strapi/parts/Table';
|
||||||
import { Text, TableLabel } from '@strapi/parts/Text';
|
import { Text, TableLabel, Subtitle } from '@strapi/parts/Text';
|
||||||
import { Button } from '@strapi/parts/Button';
|
import { Button } from '@strapi/parts/Button';
|
||||||
import { VisuallyHidden } from '@strapi/parts/VisuallyHidden';
|
import { VisuallyHidden } from '@strapi/parts/VisuallyHidden';
|
||||||
import { Switch } from '@strapi/parts/Switch';
|
import { Switch } from '@strapi/parts/Switch';
|
||||||
@ -56,6 +56,7 @@ const ListView = () => {
|
|||||||
const { push } = useHistory();
|
const { push } = useHistory();
|
||||||
const { pathname } = useLocation();
|
const { pathname } = useLocation();
|
||||||
const rowsCount = webhooks.length;
|
const rowsCount = webhooks.length;
|
||||||
|
const webhooksToDeleteLength = webhooksToDelete.length;
|
||||||
const getWebhookIndex = id => webhooks.findIndex(webhook => webhook.id === id);
|
const getWebhookIndex = id => webhooks.findIndex(webhook => webhook.id === id);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -166,10 +167,12 @@ const ListView = () => {
|
|||||||
const handleDeleteClick = id => {
|
const handleDeleteClick = id => {
|
||||||
setShowModal(true);
|
setShowModal(true);
|
||||||
|
|
||||||
dispatch({
|
if (id !== 'all') {
|
||||||
type: 'SET_WEBHOOK_TO_DELETE',
|
dispatch({
|
||||||
id,
|
type: 'SET_WEBHOOK_TO_DELETE',
|
||||||
});
|
id,
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEnabledChange = async (value, id) => {
|
const handleEnabledChange = async (value, id) => {
|
||||||
@ -256,6 +259,32 @@ const ListView = () => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
{webhooksToDeleteLength > 0 && canDelete && (
|
||||||
|
<ActionLayout
|
||||||
|
startActions={
|
||||||
|
<>
|
||||||
|
<Subtitle textColor="neutral600">
|
||||||
|
{formatMessage(
|
||||||
|
{
|
||||||
|
id: 'Settings.webhooks.to.delete',
|
||||||
|
defaultMessage:
|
||||||
|
'{webhooksToDeleteLength, plural, one {# asset} other {# assets}} selected',
|
||||||
|
},
|
||||||
|
{ webhooksToDeleteLength }
|
||||||
|
)}
|
||||||
|
</Subtitle>
|
||||||
|
<Button
|
||||||
|
onClick={() => handleDeleteClick('all')}
|
||||||
|
startIcon={<DeleteIcon />}
|
||||||
|
size="L"
|
||||||
|
variant="danger-light"
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{isLoading || loadingWebhooks ? (
|
{isLoading || loadingWebhooks ? (
|
||||||
<LoadingIndicatorPage />
|
<LoadingIndicatorPage />
|
||||||
) : (
|
) : (
|
||||||
@ -286,9 +315,9 @@ const ListView = () => {
|
|||||||
defaultMessage: 'Select all entries',
|
defaultMessage: 'Select all entries',
|
||||||
})}
|
})}
|
||||||
indeterminate={
|
indeterminate={
|
||||||
webhooksToDelete.length > 0 && webhooksToDelete.length < rowsCount
|
webhooksToDeleteLength > 0 && webhooksToDeleteLength < rowsCount
|
||||||
}
|
}
|
||||||
value={webhooksToDelete.length === rowsCount}
|
value={webhooksToDeleteLength === rowsCount}
|
||||||
onValueChange={handleSelectAllCheckbox}
|
onValueChange={handleSelectAllCheckbox}
|
||||||
/>
|
/>
|
||||||
</Th>
|
</Th>
|
||||||
@ -394,6 +423,7 @@ const ListView = () => {
|
|||||||
})}
|
})}
|
||||||
icon={<DeleteIcon />}
|
icon={<DeleteIcon />}
|
||||||
noBorder
|
noBorder
|
||||||
|
id={`delete-${webhook.id}`}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
@ -461,6 +491,7 @@ const ListView = () => {
|
|||||||
onClick={handleConfirmDelete}
|
onClick={handleConfirmDelete}
|
||||||
variant="danger-light"
|
variant="danger-light"
|
||||||
startIcon={<DeleteIcon />}
|
startIcon={<DeleteIcon />}
|
||||||
|
id="confirm-delete"
|
||||||
>
|
>
|
||||||
{formatMessage({ id: 'app.components.Button.confirm', defaultMessage: 'Confirm' })}
|
{formatMessage({ id: 'app.components.Button.confirm', defaultMessage: 'Confirm' })}
|
||||||
</Button>
|
</Button>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { render, screen, waitFor } from '@testing-library/react';
|
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
||||||
import { IntlProvider } from 'react-intl';
|
import { IntlProvider } from 'react-intl';
|
||||||
import { ThemeProvider, lightTheme } from '@strapi/parts';
|
import { ThemeProvider, lightTheme } from '@strapi/parts';
|
||||||
import { Router } from 'react-router-dom';
|
import { Router } from 'react-router-dom';
|
||||||
@ -263,4 +263,21 @@ describe('Admin | containers | ListView', () => {
|
|||||||
expect(screen.getByText('http:://strapi.io')).toBeInTheDocument();
|
expect(screen.getByText('http:://strapi.io')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should show confirmation delete modal', async () => {
|
||||||
|
useRBAC.mockImplementation(() => ({
|
||||||
|
isLoading: false,
|
||||||
|
allowedActions: { canUpdate: true, canCreate: true, canRead: true, canDelete: true },
|
||||||
|
}));
|
||||||
|
|
||||||
|
const { container } = render(App);
|
||||||
|
await waitFor(() => {
|
||||||
|
screen.getByText('http:://strapi.io');
|
||||||
|
});
|
||||||
|
|
||||||
|
fireEvent.click(container.querySelector('#delete-1'));
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText('Are you sure you want to delete this?')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -185,6 +185,7 @@
|
|||||||
"Settings.webhooks.list.th.status": "status",
|
"Settings.webhooks.list.th.status": "status",
|
||||||
"Settings.webhooks.singular": "webhook",
|
"Settings.webhooks.singular": "webhook",
|
||||||
"Settings.webhooks.title": "Webhooks",
|
"Settings.webhooks.title": "Webhooks",
|
||||||
|
"Settings.webhooks.to.delete": "{webhooksToDeleteLength, plural, one {# asset} other {# assets}} selected",
|
||||||
"Settings.webhooks.trigger": "Trigger",
|
"Settings.webhooks.trigger": "Trigger",
|
||||||
"Settings.webhooks.trigger.cancel": "Cancel trigger",
|
"Settings.webhooks.trigger.cancel": "Cancel trigger",
|
||||||
"Settings.webhooks.trigger.pending": "Pending…",
|
"Settings.webhooks.trigger.pending": "Pending…",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user