Skip to content

Commit

Permalink
draft: bulk release injection zone added
Browse files Browse the repository at this point in the history
  • Loading branch information
madhurisandbhor committed Mar 7, 2024
1 parent 0c3bbf6 commit 2d9e887
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 23 deletions.
5 changes: 4 additions & 1 deletion packages/core/admin/admin/src/components/InjectionZone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const INJECTION_ZONES = {
deleteModalAdditionalInfos: [],
publishModalAdditionalInfos: [],
unpublishModalAdditionalInfos: [],
bulkRelease: [],
},
},
} satisfies InjectionZones;
Expand Down Expand Up @@ -46,6 +47,7 @@ interface InjectionZones {
deleteModalAdditionalInfos: InjectionZoneComponent[];
publishModalAdditionalInfos: InjectionZoneComponent[];
unpublishModalAdditionalInfos: InjectionZoneComponent[];
bulkRelease: InjectionZoneComponent[];
};
};
}
Expand All @@ -58,7 +60,8 @@ type InjectionZoneArea =
| 'contentManager.listView.unpublishModalAdditionalInfos'
| 'contentManager.listView.deleteModalAdditionalInfos'
| 'contentManager.listView.publishModalAdditionalInfos'
| 'contentManager.listView.deleteModalAdditionalInfos';
| 'contentManager.listView.deleteModalAdditionalInfos'
| 'contentManager.listView.bulkRelease';

type InjectionZoneModule = InjectionZoneArea extends `${infer Word}.${string}` ? Word : never;
type InjectionZoneContainer = InjectionZoneArea extends `${string}.${infer Word}.${string}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { Button, Typography } from '@strapi/design-system';
import { useTracking, useTableContext } from '@strapi/helper-plugin';
import { Check, Trash } from '@strapi/icons';
import { Entity } from '@strapi/types';
import PropTypes from 'prop-types';
import { useIntl } from 'react-intl';

import { InjectionZone } from '../../../../../components/InjectionZone';
import { useTypedSelector } from '../../../../../core/store/hooks';
import { getTranslation } from '../../../../utils/translations';
import { InjectionZoneList } from '../InjectionZoneList';
Expand Down Expand Up @@ -205,6 +205,7 @@ const BulkActionButtons = ({
/>
</>
)}
<InjectionZone area="contentManager.listView.bulkRelease" />
{showDelete && (
<>
<Button variant="danger-light" onClick={toggleDeleteDialog}>
Expand All @@ -222,20 +223,4 @@ const BulkActionButtons = ({
);
};

BulkActionButtons.defaultProps = {
showPublish: false,
showDelete: false,
onConfirmDeleteAll() {},
onConfirmUnpublishAll() {},
refetchData() {},
};

BulkActionButtons.propTypes = {
showPublish: PropTypes.bool,
showDelete: PropTypes.bool,
onConfirmDeleteAll: PropTypes.func,
onConfirmUnpublishAll: PropTypes.func,
refetchData: PropTypes.func,
};

export { BulkActionButtons };
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as React from 'react';

import { Button } from '@strapi/design-system';
import { useCMEditViewDataManager, CheckPermissions } from '@strapi/helper-plugin';
import { Common } from '@strapi/types';
import { useIntl } from 'react-intl';

import { PERMISSIONS } from '../constants';

import { AddActionToReleaseModal } from './CMReleasesContainer';

export const CMBulkRelease = () => {
const [isModalOpen, setIsModalOpen] = React.useState(false);
const { formatMessage } = useIntl();
//TODO: find a way to get entryIds and contentTypeUid
const {
initialData: { id: entryId },
slug,
} = useCMEditViewDataManager();

const contentTypeUid = slug as Common.UID.ContentType;

const toggleAddToReleaseDialog = () => {
if (isModalOpen) {
setIsModalOpen(false);
} else {
setIsModalOpen(true);
}
};

return (
<CheckPermissions permissions={PERMISSIONS.createAction}>
<Button variant="tertiary" onClick={toggleAddToReleaseDialog}>
{formatMessage({
id: 'content-releases.content-manager-list-view.add-to-release',
defaultMessage: 'Add to release',
})}
</Button>
{isModalOpen && (
<AddActionToReleaseModal
handleClose={() => setIsModalOpen(false)}
contentTypeUid={contentTypeUid}
entryId={entryId}
/>
)}
</CheckPermissions>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ const AddActionToReleaseModal = ({
// Get all 'pending' releases that do not have the entry attached
const response = useGetReleasesForEntryQuery({
contentTypeUid,
entryId,
hasEntryAttached: false,
entryId, // TODO: there will be list of selectedEntries
hasEntryAttached: false, // TODO: for bulk releases hasEntryAttached should not be checked
});

const releases = response.data?.data;
Expand All @@ -121,7 +121,7 @@ const AddActionToReleaseModal = ({
locale,
};
const response = await createReleaseAction({
body: { type: values.type, entry: releaseActionEntry },
body: { type: values.type, entry: releaseActionEntry }, // TODO: there will be list of selectedEntries
params: { releaseId: values.releaseId },
});

Expand All @@ -134,6 +134,7 @@ const AddActionToReleaseModal = ({
defaultMessage: 'Entry added to release',
}),
});
// trackUsage('willBulkReleaseEntries'); //TODO: Do we need tracking event name "willBulkReleaseEntries"

handleClose();
return;
Expand Down Expand Up @@ -248,7 +249,7 @@ const AddActionToReleaseModal = ({
* CMReleasesContainer
* -----------------------------------------------------------------------------------------------*/

export const CMReleasesContainer = () => {
const CMReleasesContainer = () => {
const [isModalOpen, setIsModalOpen] = React.useState(false);
const { formatMessage, formatDate, formatTime } = useIntl();
const {
Expand Down Expand Up @@ -428,3 +429,5 @@ export const CMReleasesContainer = () => {
</CheckPermissions>
);
};

export { AddActionToReleaseModal, CMReleasesContainer };
6 changes: 6 additions & 0 deletions packages/core/content-releases/admin/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { prefixPluginTranslations } from '@strapi/helper-plugin';
import { PaperPlane } from '@strapi/icons';

import { CMBulkRelease } from './components/CMBulkRelease';
import { CMReleasesContainer } from './components/CMReleasesContainer';
import { PERMISSIONS } from './constants';
import { pluginId } from './pluginId';
Expand Down Expand Up @@ -42,6 +43,11 @@ const admin: Plugin.Config.AdminInput = {
name: `${pluginId}-link`,
Component: CMReleasesContainer,
});
// Insert the Releases container in the 'bulkRelease' zone of the Content Manager's list view
app.injectContentManagerComponent('listView', 'bulkRelease', {
name: `${pluginId}-link`,
Component: CMBulkRelease,
});
} else if (
!window.strapi.features.isEnabled('cms-content-releases') &&
window.strapi?.flags?.promoteEE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"content-releases.content-manager-edit-view.edit-entry": "Edit entry",
"content-manager-edit-view.remove-from-release.notification.success": "Entry removed from release",
"content-manager-edit-view.release-action-menu": "Release action options",
"content-manager-list-view.add-to-release": "Add to release",
"content-manager.notification.entry-error": "Failed to get entry data",
"plugin.name": "Releases",
"pages.Releases.title": "Releases",
Expand Down
3 changes: 2 additions & 1 deletion packages/core/helper-plugin/src/features/StrapiApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ type InjectionZoneArea =
| 'contentManager.listView.unpublishModalAdditionalInfos'
| 'contentManager.listView.deleteModalAdditionalInfos'
| 'contentManager.listView.publishModalAdditionalInfos'
| 'contentManager.listView.deleteModalAdditionalInfos';
| 'contentManager.listView.deleteModalAdditionalInfos'
| 'contentManager.listView.bulkRelease';

type InjectionZoneModule = InjectionZoneArea extends `${infer Word}.${string}` ? Word : never;
type InjectionZoneContainer = InjectionZoneArea extends `${string}.${infer Word}.${string}`
Expand Down

0 comments on commit 2d9e887

Please sign in to comment.