diff --git a/packages/core/admin/admin/src/content-manager/components/DynamicTable/BulkActionsBar/index.js b/packages/core/admin/admin/src/content-manager/components/DynamicTable/BulkActionsBar/index.js index bdded065b9..a2e64d784a 100644 --- a/packages/core/admin/admin/src/content-manager/components/DynamicTable/BulkActionsBar/index.js +++ b/packages/core/admin/admin/src/content-manager/components/DynamicTable/BulkActionsBar/index.js @@ -1,13 +1,10 @@ import React, { useState } from 'react'; -import { useSelector } from 'react-redux'; import PropTypes from 'prop-types'; import { Button } from '@strapi/design-system'; -import { useTracking, getYupInnerErrors } from '@strapi/helper-plugin'; +import { useTracking } from '@strapi/helper-plugin'; import { useIntl } from 'react-intl'; import ConfirmDialogDeleteAll from '../ConfirmDialogDeleteAll'; -import { createYupSchema } from '../../../utils'; -import { listViewDomain } from '../../../pages/ListView/selectors'; const BulkActionsBar = ({ showPublish, @@ -15,8 +12,8 @@ const BulkActionsBar = ({ onConfirmDeleteAll, selectedEntries, clearSelectedEntries, + handleBulkPublish, }) => { - const { data, contentType, components } = useSelector(listViewDomain()); const { formatMessage } = useIntl(); const { trackUsage } = useTracking(); @@ -43,50 +40,12 @@ const BulkActionsBar = ({ handleToggleShowDeleteAllModal(); } }; - /** - * @param {number[]} selectedIds - Array of ids to publish - * @returns {{validIds: number[], errors: Object.}} - Returns an object with the valid ids and the errors - */ - const validateEntriesToPublish = async () => { - const validations = { validIds: [], errors: {} }; - // Create the validation schema based on the contentType - const schema = createYupSchema(contentType, { components }, { isDraft: false }); - // Get the selected entries - const entries = data.filter((entry) => { - return selectedEntries.includes(entry.id); - }); - // Validate each entry and map the unresolved promises - const validationPromises = entries.map((entry) => - schema.validate(entry, { abortEarly: false }) - ); - // Resolve all the promises in one go - const resolvedPromises = await Promise.allSettled(validationPromises); - // Set the validations - resolvedPromises.forEach((promise) => { - if (promise.status === 'rejected') { - const entityId = promise.reason.value.id; - validations.errors[entityId] = getYupInnerErrors(promise.reason); - } - - if (promise.status === 'fulfilled') { - validations.validIds.push(promise.value.id); - } - }); - - return validations; - }; - - const handleBulkPublish = async () => { - const validations = await validateEntriesToPublish(); - // TODO: Remove log when we actually do something with the validations - console.log(validations); - }; return ( <> {showPublish && ( <> -