From 6eaefa820c2513b5afcaf848d6d5ca0bed69fa52 Mon Sep 17 00:00:00 2001 From: markkaylor Date: Fri, 8 Dec 2023 10:44:49 +0100 Subject: [PATCH] feat(content-releases): list releases with content type entry (#18999) --- .../src/components/CMReleasesContainer.tsx | 81 +++++++++++++++++-- .../src/components/ReleaseActionOptions.tsx | 5 ++ .../tests/CMReleasesContainer.test.tsx | 34 ++++++-- .../admin/src/services/release.ts | 2 +- .../admin/src/translations/en.json | 1 + .../server/src/services/release.ts | 3 +- 6 files changed, 110 insertions(+), 16 deletions(-) diff --git a/packages/core/content-releases/admin/src/components/CMReleasesContainer.tsx b/packages/core/content-releases/admin/src/components/CMReleasesContainer.tsx index 76921e3eb5..121dd2f7f7 100644 --- a/packages/core/content-releases/admin/src/components/CMReleasesContainer.tsx +++ b/packages/core/content-releases/admin/src/components/CMReleasesContainer.tsx @@ -1,5 +1,6 @@ import * as React from 'react'; +import { skipToken } from '@reduxjs/toolkit/query'; import { Box, Button, @@ -206,15 +207,25 @@ export const CMReleasesContainer = () => { isCreatingEntry, allLayoutData: { contentType }, } = useCMEditViewDataManager(); - const params = useParams<{ id?: string }>(); + const params = useParams<{ id: string }>(); - const toggleAddActionToReleaseModal = () => setShowModal((prev) => !prev); + const canFetch = params?.id != null && contentType?.uid != null; + const fetchParams = canFetch + ? { + contentTypeUid: contentType.uid, + entryId: params.id, + hasEntryAttached: true, + } + : skipToken; + // Get all 'pending' releases that have the entry attached + const response = useGetReleasesForEntryQuery(fetchParams); + const releases = response.data?.data; /** - * If we don't have a contentType.uid or params.id no use showing the injection zone + * If we don't have a contentType.uid or params.id then the data was never fetched * TODO: Should we handle this with an error message in the UI or just not show the container? */ - if (!contentType?.uid || !params.id) { + if (!canFetch) { return null; } @@ -223,10 +234,23 @@ export const CMReleasesContainer = () => { * - Content types without draft and publish cannot add entries to release * TODO v5: All contentTypes will have draft and publish enabled */ - if (isCreatingEntry || !contentType.options?.draftAndPublish) { + if (isCreatingEntry || !contentType?.options?.draftAndPublish) { return null; } + const toggleAddActionToReleaseModal = () => setShowModal((prev) => !prev); + + const getReleaseColorVariant = ( + actionType: 'publish' | 'unpublish', + shade: '100' | '200' | '600' + ) => { + if (actionType === 'unpublish') { + return `secondary${shade}`; + } + + return `success${shade}`; + }; + return ( { padding={4} shadow="tableShadow" > - + {formatMessage({ id: 'content-releases.plugin.name', - defaultMessage: 'RELEASES', + defaultMessage: 'Releases', })} + {releases?.map((release) => { + return ( + + + + {formatMessage( + { + id: 'content-releases.content-manager-edit-view.list-releases.title', + defaultMessage: + '{isPublish, select, true {Will be published in} other {Will be unpublished in}}', + }, + { isPublish: release.action.type === 'publish' } + )} + + + + + {release.name} + + + + ); + })}