From adfa9612c96a06b83cb4d14f7022ace09e993769 Mon Sep 17 00:00:00 2001 From: Madhuri Sandbhor Date: Wed, 29 May 2024 15:01:55 +0200 Subject: [PATCH] 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 Co-authored-by: Josh <37798644+joshuaellis@users.noreply.github.com> --- .../admin/src/pages/ListView/ListViewPage.tsx | 29 +++++++++++++++++-- .../BulkActions/ConfirmBulkActionDialog.tsx | 2 +- .../components/BulkActions/PublishAction.tsx | 16 +++++----- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/packages/core/content-manager/admin/src/pages/ListView/ListViewPage.tsx b/packages/core/content-manager/admin/src/pages/ListView/ListViewPage.tsx index 3885c11985..4bf3fffc3b 100644 --- a/packages/core/content-manager/admin/src/pages/ListView/ListViewPage.tsx +++ b/packages/core/content-manager/admin/src/pages/ListView/ListViewPage.tsx @@ -13,6 +13,7 @@ import { useQueryParams, useRBAC, Layouts, + useTable, } from '@strapi/admin/strapi-admin'; import { Button, Flex, Typography, ButtonProps } from '@strapi/design-system'; import { Plus } from '@strapi/icons'; @@ -239,9 +240,7 @@ const ListViewPage = () => { - - - + @@ -330,6 +329,30 @@ const ActionsCell = styled(Table.Cell)` 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 ( + + + + ); +}; + /* ------------------------------------------------------------------------------------------------- * CreateButton * -----------------------------------------------------------------------------------------------*/ diff --git a/packages/core/content-manager/admin/src/pages/ListView/components/BulkActions/ConfirmBulkActionDialog.tsx b/packages/core/content-manager/admin/src/pages/ListView/components/BulkActions/ConfirmBulkActionDialog.tsx index fec77ed1bd..5dda28fee8 100644 --- a/packages/core/content-manager/admin/src/pages/ListView/components/BulkActions/ConfirmBulkActionDialog.tsx +++ b/packages/core/content-manager/admin/src/pages/ListView/components/BulkActions/ConfirmBulkActionDialog.tsx @@ -155,7 +155,7 @@ const ConfirmDialogPublishAll = ({ {schema?.pluginOptions && 'i18n' in schema.pluginOptions && schema?.pluginOptions.i18n && ( - + {formatMessage( { id: getTranslation('Settings.list.actions.publishAdditionalInfos'), diff --git a/packages/core/content-manager/admin/src/pages/ListView/components/BulkActions/PublishAction.tsx b/packages/core/content-manager/admin/src/pages/ListView/components/BulkActions/PublishAction.tsx index a5219c6b14..eb42f20fdd 100644 --- a/packages/core/content-manager/admin/src/pages/ListView/components/BulkActions/PublishAction.tsx +++ b/packages/core/content-manager/admin/src/pages/ListView/components/BulkActions/PublishAction.tsx @@ -333,15 +333,16 @@ const SelectedEntriesModalContent = ({ const { publishMany: bulkPublishAction } = useDocumentActions(); const [, { isLoading: isSubmittingForm }] = usePublishManyDocumentsMutation(); - const selectedEntries = useTable('publishAction', (state) => state.selectedRows); + const selectedRows = useTable('publishAction', (state) => state.selectedRows); - const entriesToPublish = selectedEntries.reduce((acc, entry) => { - if (!validationErrors[entry.documentId]) { - acc.push(entry.documentId); - } + // Filter selected entries from the updated modal table rows + const selectedEntries = rows.filter((entry) => + 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( ({ documentId }) => validationErrors[documentId] @@ -433,6 +434,7 @@ const SelectedEntriesModalContent = ({ disabled={ selectedEntries.length === 0 || selectedEntries.length === selectedEntriesWithErrorsCount || + selectedEntriesPublished === selectedEntries.length || isLoading } loading={isSubmittingForm}