Fix: bulk publish modal and related issues (#20386)

* fix: added bulk actions

* chore: migrate bulk publish & unpublish to v5

* chore: change findLocales type to accept arrays

* chore: fix lint error

* chore: migrate bulkDelete to v5 (#20161)

* chore: migrate bulkDelete to v5

* chore: change findLocales type to accept strings array

* fix: docs prettier styles

* chore: remove console.log

* enhancement: migrate countManyDraftRelations to v5

* feat: bulk delete with locale selection option

* fix: bulk unpublish working without locale support

* test: e2e tests updated

* fix: documents api change, deleteMany tags updated, test skipped

* chore: renaming

* test: reverting e2e tests for delete action changes

* feat: publish action changes

* fix: reverting publish action changes

* fix: hide add to release as its not ready to be migrated

* fix: error message updated

* fix: tests updated for useDocumentAction

* fix: updated request params

* fix: publish action added

* fix: publish action changes with documentId

* fix: reverting wrong commit message

Co-authored-by: Josh <37798644+joshuaellis@users.noreply.github.com>

* fix: comments updated

* chore: renaming

* chore: add type to bulk action actions (#20256)

* chore: actionType renamed to just type

* fix: added missing import

* test: fixed

* fix(content-manager): edit entry button on bulk publish modal

* fix: validationError message type is not as expected

* fix: ts error

* only fetch entries when modal is opened

* fix(content-releases): use status to show the published instead of publishedAt

* fix: alignment fix, update selectedEntries to reflect count, reset selectedEntries on locale change

* fix: fixed type error

---------

Co-authored-by: Fernando Chavez <fernando.chavez@strapi.io>
Co-authored-by: Josh <37798644+joshuaellis@users.noreply.github.com>
This commit is contained in:
Madhuri Sandbhor 2024-05-29 15:01:55 +02:00 committed by GitHub
parent 7b7a51fc89
commit adfa9612c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 11 deletions

View File

@ -13,6 +13,7 @@ import {
useQueryParams, useQueryParams,
useRBAC, useRBAC,
Layouts, Layouts,
useTable,
} from '@strapi/admin/strapi-admin'; } from '@strapi/admin/strapi-admin';
import { Button, Flex, Typography, ButtonProps } from '@strapi/design-system'; import { Button, Flex, Typography, ButtonProps } from '@strapi/design-system';
import { Plus } from '@strapi/icons'; import { Plus } from '@strapi/icons';
@ -239,9 +240,7 @@ const ListViewPage = () => {
<Layouts.Content> <Layouts.Content>
<Flex gap={4} direction="column" alignItems="stretch"> <Flex gap={4} direction="column" alignItems="stretch">
<Table.Root rows={results} headers={tableHeaders} isLoading={isLoading}> <Table.Root rows={results} headers={tableHeaders} isLoading={isLoading}>
<Table.ActionBar> <TableActionsBar />
<BulkActionsRenderer />
</Table.ActionBar>
<Table.Content> <Table.Content>
<Table.Head> <Table.Head>
<Table.HeaderCheckboxCell /> <Table.HeaderCheckboxCell />
@ -330,6 +329,30 @@ const ActionsCell = styled(Table.Cell)`
justify-content: flex-end; justify-content: flex-end;
`; `;
/* -------------------------------------------------------------------------------------------------
* TableActionsBar
* -----------------------------------------------------------------------------------------------*/
const TableActionsBar = () => {
const selectRow = useTable('TableActionsBar', (state) => state.selectRow);
const [{ query }] = useQueryParams<{ plugins: { i18n: { locale: string } } }>();
const locale = query?.plugins?.i18n?.locale;
const prevLocale = usePrev(locale);
// TODO: find a better way to reset the selected rows when the locale changes across all the app
React.useEffect(() => {
if (prevLocale !== locale) {
selectRow([]);
}
}, [selectRow, prevLocale, locale]);
return (
<Table.ActionBar>
<BulkActionsRenderer />
</Table.ActionBar>
);
};
/* ------------------------------------------------------------------------------------------------- /* -------------------------------------------------------------------------------------------------
* CreateButton * CreateButton
* -----------------------------------------------------------------------------------------------*/ * -----------------------------------------------------------------------------------------------*/

View File

@ -155,7 +155,7 @@ const ConfirmDialogPublishAll = ({
{schema?.pluginOptions && {schema?.pluginOptions &&
'i18n' in schema.pluginOptions && 'i18n' in schema.pluginOptions &&
schema?.pluginOptions.i18n && ( schema?.pluginOptions.i18n && (
<Typography textColor="danger500"> <Typography textColor="danger500" textAlign="center">
{formatMessage( {formatMessage(
{ {
id: getTranslation('Settings.list.actions.publishAdditionalInfos'), id: getTranslation('Settings.list.actions.publishAdditionalInfos'),

View File

@ -333,15 +333,16 @@ const SelectedEntriesModalContent = ({
const { publishMany: bulkPublishAction } = useDocumentActions(); const { publishMany: bulkPublishAction } = useDocumentActions();
const [, { isLoading: isSubmittingForm }] = usePublishManyDocumentsMutation(); const [, { isLoading: isSubmittingForm }] = usePublishManyDocumentsMutation();
const selectedEntries = useTable('publishAction', (state) => state.selectedRows); const selectedRows = useTable('publishAction', (state) => state.selectedRows);
const entriesToPublish = selectedEntries.reduce((acc, entry) => { // Filter selected entries from the updated modal table rows
if (!validationErrors[entry.documentId]) { const selectedEntries = rows.filter((entry) =>
acc.push(entry.documentId); selectedRows.some((selectedEntry) => selectedEntry.documentId === entry.documentId)
} );
return acc; const entriesToPublish = selectedEntries
}, []); .filter((entry) => !validationErrors[entry.documentId])
.map((entry) => entry.documentId);
const selectedEntriesWithErrorsCount = selectedEntries.filter( const selectedEntriesWithErrorsCount = selectedEntries.filter(
({ documentId }) => validationErrors[documentId] ({ documentId }) => validationErrors[documentId]
@ -433,6 +434,7 @@ const SelectedEntriesModalContent = ({
disabled={ disabled={
selectedEntries.length === 0 || selectedEntries.length === 0 ||
selectedEntries.length === selectedEntriesWithErrorsCount || selectedEntries.length === selectedEntriesWithErrorsCount ||
selectedEntriesPublished === selectedEntries.length ||
isLoading isLoading
} }
loading={isSubmittingForm} loading={isSubmittingForm}