@strapi/content-releases 0.0.0-experimental.check-license → 0.0.0-experimental.ee4d311a5e6a131fad03cf07e4696f49fdd9c2e6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,887 @@
1
+ import { getFetchClient, useNotification, useAPIErrorHandler, CheckPermissions, useCMEditViewDataManager, NoContent, prefixPluginTranslations } from "@strapi/helper-plugin";
2
+ import { Cross, Pencil, More, Plus, PaperPlane } from "@strapi/icons";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+ import * as React from "react";
5
+ import { skipToken } from "@reduxjs/toolkit/query";
6
+ import { IconButton, Flex, Icon, Typography, Field, FieldLabel, VisuallyHidden, FieldInput, Box, Button, ModalLayout, ModalHeader, ModalBody, SingleSelect, SingleSelectOption, ModalFooter } from "@strapi/design-system";
7
+ import { Menu, Link, LinkButton } from "@strapi/design-system/v2";
8
+ import { isAxiosError as isAxiosError$1 } from "axios";
9
+ import { Formik, Form } from "formik";
10
+ import { useIntl } from "react-intl";
11
+ import { NavLink, useParams, Link as Link$1 } from "react-router-dom";
12
+ import * as yup from "yup";
13
+ import { createApi } from "@reduxjs/toolkit/query/react";
14
+ import styled from "styled-components";
15
+ import { useDispatch, useSelector } from "react-redux";
16
+ const __variableDynamicImportRuntimeHelper = (glob, path) => {
17
+ const v = glob[path];
18
+ if (v) {
19
+ return typeof v === "function" ? v() : Promise.resolve(v);
20
+ }
21
+ return new Promise((_, reject) => {
22
+ (typeof queueMicrotask === "function" ? queueMicrotask : setTimeout)(reject.bind(null, new Error("Unknown variable dynamic import: " + path)));
23
+ });
24
+ };
25
+ const PERMISSIONS = {
26
+ main: [
27
+ {
28
+ action: "plugin::content-releases.read",
29
+ subject: null,
30
+ id: "",
31
+ actionParameters: {},
32
+ properties: {},
33
+ conditions: []
34
+ }
35
+ ],
36
+ create: [
37
+ {
38
+ action: "plugin::content-releases.create",
39
+ subject: null,
40
+ id: "",
41
+ actionParameters: {},
42
+ properties: {},
43
+ conditions: []
44
+ }
45
+ ],
46
+ update: [
47
+ {
48
+ action: "plugin::content-releases.update",
49
+ subject: null,
50
+ id: "",
51
+ actionParameters: {},
52
+ properties: {},
53
+ conditions: []
54
+ }
55
+ ],
56
+ delete: [
57
+ {
58
+ action: "plugin::content-releases.delete",
59
+ subject: null,
60
+ id: "",
61
+ actionParameters: {},
62
+ properties: {},
63
+ conditions: []
64
+ }
65
+ ],
66
+ createAction: [
67
+ {
68
+ action: "plugin::content-releases.create-action",
69
+ subject: null,
70
+ id: "",
71
+ actionParameters: {},
72
+ properties: {},
73
+ conditions: []
74
+ }
75
+ ],
76
+ deleteAction: [
77
+ {
78
+ action: "plugin::content-releases.delete-action",
79
+ subject: null,
80
+ id: "",
81
+ actionParameters: {},
82
+ properties: {},
83
+ conditions: []
84
+ }
85
+ ],
86
+ publish: [
87
+ {
88
+ action: "plugin::content-releases.publish",
89
+ subject: null,
90
+ id: "",
91
+ actionParameters: {},
92
+ properties: {},
93
+ conditions: []
94
+ }
95
+ ]
96
+ };
97
+ const pluginId = "content-releases";
98
+ const axiosBaseQuery = async ({
99
+ url,
100
+ method,
101
+ data,
102
+ config
103
+ }) => {
104
+ try {
105
+ const { get, post, del, put } = getFetchClient();
106
+ if (method === "POST") {
107
+ const result2 = await post(url, data, config);
108
+ return { data: result2.data };
109
+ }
110
+ if (method === "DELETE") {
111
+ const result2 = await del(url, config);
112
+ return { data: result2.data };
113
+ }
114
+ if (method === "PUT") {
115
+ const result2 = await put(url, data, config);
116
+ return { data: result2.data };
117
+ }
118
+ const result = await get(url, config);
119
+ return { data: result.data };
120
+ } catch (error) {
121
+ const err = error;
122
+ return {
123
+ error: {
124
+ status: err.response?.status,
125
+ code: err.code,
126
+ response: {
127
+ data: err.response?.data
128
+ }
129
+ }
130
+ };
131
+ }
132
+ };
133
+ const isAxiosError = (err) => {
134
+ return typeof err === "object" && err !== null && "response" in err && typeof err.response === "object" && err.response !== null && "data" in err.response;
135
+ };
136
+ const releaseApi = createApi({
137
+ reducerPath: pluginId,
138
+ baseQuery: axiosBaseQuery,
139
+ tagTypes: ["Release", "ReleaseAction"],
140
+ endpoints: (build) => {
141
+ return {
142
+ getReleasesForEntry: build.query({
143
+ query(params) {
144
+ return {
145
+ url: "/content-releases",
146
+ method: "GET",
147
+ config: {
148
+ params
149
+ }
150
+ };
151
+ },
152
+ providesTags: (result) => result ? [
153
+ ...result.data.map(({ id }) => ({ type: "Release", id })),
154
+ { type: "Release", id: "LIST" }
155
+ ] : []
156
+ }),
157
+ getReleases: build.query({
158
+ query({ page, pageSize, filters } = {
159
+ page: 1,
160
+ pageSize: 16,
161
+ filters: {
162
+ releasedAt: {
163
+ $notNull: false
164
+ }
165
+ }
166
+ }) {
167
+ return {
168
+ url: "/content-releases",
169
+ method: "GET",
170
+ config: {
171
+ params: {
172
+ page: page || 1,
173
+ pageSize: pageSize || 16,
174
+ filters: filters || {
175
+ releasedAt: {
176
+ $notNull: false
177
+ }
178
+ }
179
+ }
180
+ }
181
+ };
182
+ },
183
+ transformResponse(response, meta, arg) {
184
+ const releasedAtValue = arg?.filters?.releasedAt?.$notNull;
185
+ const isActiveDoneTab = releasedAtValue === "true";
186
+ const newResponse = {
187
+ ...response,
188
+ meta: {
189
+ ...response.meta,
190
+ activeTab: isActiveDoneTab ? "done" : "pending"
191
+ }
192
+ };
193
+ return newResponse;
194
+ },
195
+ providesTags: (result) => result ? [
196
+ ...result.data.map(({ id }) => ({ type: "Release", id })),
197
+ { type: "Release", id: "LIST" }
198
+ ] : [{ type: "Release", id: "LIST" }]
199
+ }),
200
+ getRelease: build.query({
201
+ query({ id }) {
202
+ return {
203
+ url: `/content-releases/${id}`,
204
+ method: "GET"
205
+ };
206
+ },
207
+ providesTags: (result, error, arg) => [{ type: "Release", id: arg.id }]
208
+ }),
209
+ getReleaseActions: build.query({
210
+ query({ releaseId, ...params }) {
211
+ return {
212
+ url: `/content-releases/${releaseId}/actions`,
213
+ method: "GET",
214
+ config: {
215
+ params
216
+ }
217
+ };
218
+ },
219
+ providesTags: [{ type: "ReleaseAction", id: "LIST" }]
220
+ }),
221
+ createRelease: build.mutation({
222
+ query(data) {
223
+ return {
224
+ url: "/content-releases",
225
+ method: "POST",
226
+ data
227
+ };
228
+ },
229
+ invalidatesTags: [{ type: "Release", id: "LIST" }]
230
+ }),
231
+ updateRelease: build.mutation({
232
+ query({ id, ...data }) {
233
+ return {
234
+ url: `/content-releases/${id}`,
235
+ method: "PUT",
236
+ data
237
+ };
238
+ },
239
+ invalidatesTags: (result, error, arg) => [{ type: "Release", id: arg.id }]
240
+ }),
241
+ createReleaseAction: build.mutation({
242
+ query({ body, params }) {
243
+ return {
244
+ url: `/content-releases/${params.releaseId}/actions`,
245
+ method: "POST",
246
+ data: body
247
+ };
248
+ },
249
+ invalidatesTags: [
250
+ { type: "Release", id: "LIST" },
251
+ { type: "ReleaseAction", id: "LIST" }
252
+ ]
253
+ }),
254
+ updateReleaseAction: build.mutation({
255
+ query({ body, params }) {
256
+ return {
257
+ url: `/content-releases/${params.releaseId}/actions/${params.actionId}`,
258
+ method: "PUT",
259
+ data: body
260
+ };
261
+ },
262
+ invalidatesTags: () => [{ type: "ReleaseAction", id: "LIST" }]
263
+ }),
264
+ deleteReleaseAction: build.mutation({
265
+ query({ params }) {
266
+ return {
267
+ url: `/content-releases/${params.releaseId}/actions/${params.actionId}`,
268
+ method: "DELETE"
269
+ };
270
+ },
271
+ invalidatesTags: [
272
+ { type: "Release", id: "LIST" },
273
+ { type: "ReleaseAction", id: "LIST" }
274
+ ]
275
+ }),
276
+ publishRelease: build.mutation({
277
+ query({ id }) {
278
+ return {
279
+ url: `/content-releases/${id}/publish`,
280
+ method: "POST"
281
+ };
282
+ },
283
+ invalidatesTags: (result, error, arg) => [{ type: "Release", id: arg.id }]
284
+ }),
285
+ deleteRelease: build.mutation({
286
+ query({ id }) {
287
+ return {
288
+ url: `/content-releases/${id}`,
289
+ method: "DELETE"
290
+ };
291
+ },
292
+ invalidatesTags: (result, error, arg) => [{ type: "Release", id: arg.id }]
293
+ })
294
+ };
295
+ }
296
+ });
297
+ const {
298
+ useGetReleasesQuery,
299
+ useGetReleasesForEntryQuery,
300
+ useGetReleaseQuery,
301
+ useGetReleaseActionsQuery,
302
+ useCreateReleaseMutation,
303
+ useCreateReleaseActionMutation,
304
+ useUpdateReleaseMutation,
305
+ useUpdateReleaseActionMutation,
306
+ usePublishReleaseMutation,
307
+ useDeleteReleaseActionMutation,
308
+ useDeleteReleaseMutation
309
+ } = releaseApi;
310
+ const useTypedDispatch = useDispatch;
311
+ const useTypedSelector = useSelector;
312
+ const StyledMenuItem = styled(Menu.Item)`
313
+ &:hover {
314
+ background: ${({ theme, variant = "neutral" }) => theme.colors[`${variant}100`]};
315
+
316
+ svg {
317
+ path {
318
+ fill: ${({ theme, variant = "neutral" }) => theme.colors[`${variant}600`]};
319
+ }
320
+ }
321
+
322
+ a {
323
+ color: ${({ theme }) => theme.colors.neutral800};
324
+ }
325
+ }
326
+
327
+ svg {
328
+ path {
329
+ fill: ${({ theme, variant = "neutral" }) => theme.colors[`${variant}600`]};
330
+ }
331
+ }
332
+
333
+ a {
334
+ color: ${({ theme }) => theme.colors.neutral800};
335
+ }
336
+
337
+ span,
338
+ a {
339
+ width: 100%;
340
+ }
341
+ `;
342
+ const StyledIconButton = styled(IconButton)`
343
+ /* Setting this style inline with borderColor will not apply the style */
344
+ border: ${({ theme }) => `1px solid ${theme.colors.neutral200}`};
345
+ `;
346
+ const DeleteReleaseActionItem = ({ releaseId, actionId }) => {
347
+ const { formatMessage } = useIntl();
348
+ const toggleNotification = useNotification();
349
+ const { formatAPIError } = useAPIErrorHandler();
350
+ const [deleteReleaseAction] = useDeleteReleaseActionMutation();
351
+ const handleDeleteAction = async () => {
352
+ const response = await deleteReleaseAction({
353
+ params: { releaseId, actionId }
354
+ });
355
+ if ("data" in response) {
356
+ toggleNotification({
357
+ type: "success",
358
+ message: formatMessage({
359
+ id: "content-releases.content-manager-edit-view.remove-from-release.notification.success",
360
+ defaultMessage: "Entry removed from release"
361
+ })
362
+ });
363
+ return;
364
+ }
365
+ if ("error" in response) {
366
+ if (isAxiosError$1(response.error)) {
367
+ toggleNotification({
368
+ type: "warning",
369
+ message: formatAPIError(response.error)
370
+ });
371
+ } else {
372
+ toggleNotification({
373
+ type: "warning",
374
+ message: formatMessage({ id: "notification.error", defaultMessage: "An error occurred" })
375
+ });
376
+ }
377
+ }
378
+ };
379
+ return /* @__PURE__ */ jsx(CheckPermissions, { permissions: PERMISSIONS.deleteAction, children: /* @__PURE__ */ jsx(StyledMenuItem, { variant: "danger", onSelect: handleDeleteAction, children: /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
380
+ /* @__PURE__ */ jsx(Icon, { as: Cross, padding: 1 }),
381
+ /* @__PURE__ */ jsx(Typography, { textColor: "danger600", variant: "omega", children: formatMessage({
382
+ id: "content-releases.content-manager-edit-view.remove-from-release",
383
+ defaultMessage: "Remove from release"
384
+ }) })
385
+ ] }) }) });
386
+ };
387
+ const ReleaseActionEntryLinkItem = ({
388
+ contentTypeUid,
389
+ entryId,
390
+ locale
391
+ }) => {
392
+ const { formatMessage } = useIntl();
393
+ const collectionTypePermissions = useTypedSelector(
394
+ (state) => state.rbacProvider.collectionTypesRelatedPermissions
395
+ );
396
+ const updatePermissions = contentTypeUid ? collectionTypePermissions[contentTypeUid]?.["plugin::content-manager.explorer.update"] : [];
397
+ const canUpdateEntryForLocale = Boolean(
398
+ !locale || updatePermissions?.find(
399
+ (permission) => permission.properties?.locales?.includes(locale)
400
+ )
401
+ );
402
+ return /* @__PURE__ */ jsx(
403
+ CheckPermissions,
404
+ {
405
+ permissions: [
406
+ {
407
+ action: "plugin::content-manager.explorer.update",
408
+ subject: contentTypeUid
409
+ }
410
+ ],
411
+ children: canUpdateEntryForLocale && /* @__PURE__ */ jsx(StyledMenuItem, { children: /* @__PURE__ */ jsx(
412
+ Link,
413
+ {
414
+ as: NavLink,
415
+ to: {
416
+ pathname: `/content-manager/collection-types/${contentTypeUid}/${entryId}`,
417
+ search: locale && `?plugins[i18n][locale]=${locale}`
418
+ },
419
+ startIcon: /* @__PURE__ */ jsx(Icon, { as: Pencil, padding: 1 }),
420
+ children: /* @__PURE__ */ jsx(Typography, { variant: "omega", children: formatMessage({
421
+ id: "content-releases.content-manager-edit-view.edit-entry",
422
+ defaultMessage: "Edit entry"
423
+ }) })
424
+ }
425
+ ) })
426
+ }
427
+ );
428
+ };
429
+ const Root = ({ children, hasTriggerBorder = false }) => {
430
+ const { formatMessage } = useIntl();
431
+ return (
432
+ // A user can access the dropdown if they have permissions to delete a release-action OR update a release
433
+ /* @__PURE__ */ jsx(CheckPermissions, { permissions: [...PERMISSIONS.deleteAction, ...PERMISSIONS.update], children: /* @__PURE__ */ jsxs(Menu.Root, { children: [
434
+ /* @__PURE__ */ jsx(
435
+ Menu.Trigger,
436
+ {
437
+ as: hasTriggerBorder ? StyledIconButton : IconButton,
438
+ paddingLeft: 2,
439
+ paddingRight: 2,
440
+ "aria-label": formatMessage({
441
+ id: "content-releases.content-manager-edit-view.release-action-menu",
442
+ defaultMessage: "Release action options"
443
+ }),
444
+ icon: /* @__PURE__ */ jsx(More, {})
445
+ }
446
+ ),
447
+ /* @__PURE__ */ jsx(Menu.Content, { top: 1, popoverPlacement: "bottom-end", children })
448
+ ] }) })
449
+ );
450
+ };
451
+ const ReleaseActionMenu = {
452
+ Root,
453
+ DeleteReleaseActionItem,
454
+ ReleaseActionEntryLinkItem
455
+ };
456
+ const getBorderLeftRadiusValue = (actionType) => {
457
+ return actionType === "publish" ? 1 : 0;
458
+ };
459
+ const getBorderRightRadiusValue = (actionType) => {
460
+ return actionType === "publish" ? 0 : 1;
461
+ };
462
+ const FieldWrapper = styled(Field)`
463
+ border-top-left-radius: ${({ actionType, theme }) => theme.spaces[getBorderLeftRadiusValue(actionType)]};
464
+ border-bottom-left-radius: ${({ actionType, theme }) => theme.spaces[getBorderLeftRadiusValue(actionType)]};
465
+ border-top-right-radius: ${({ actionType, theme }) => theme.spaces[getBorderRightRadiusValue(actionType)]};
466
+ border-bottom-right-radius: ${({ actionType, theme }) => theme.spaces[getBorderRightRadiusValue(actionType)]};
467
+
468
+ > label {
469
+ color: inherit;
470
+ padding: ${({ theme }) => `${theme.spaces[2]} ${theme.spaces[3]}`};
471
+ text-align: center;
472
+ vertical-align: middle;
473
+ text-transform: capitalize;
474
+ }
475
+
476
+ &:active,
477
+ &[data-checked='true'] {
478
+ color: ${({ theme }) => theme.colors.primary700};
479
+ background-color: ${({ theme }) => theme.colors.primary100};
480
+ border-color: ${({ theme }) => theme.colors.primary700};
481
+ }
482
+
483
+ &[data-checked='false'] {
484
+ border-left: ${({ actionType }) => actionType === "unpublish" && "none"};
485
+ border-right: ${({ actionType }) => actionType === "publish" && "none"};
486
+ }
487
+ `;
488
+ const ActionOption = ({ selected, actionType, handleChange, name }) => {
489
+ return /* @__PURE__ */ jsx(
490
+ FieldWrapper,
491
+ {
492
+ actionType,
493
+ background: "primary0",
494
+ borderColor: "neutral200",
495
+ color: selected === actionType ? "primary600" : "neutral600",
496
+ position: "relative",
497
+ cursor: "pointer",
498
+ "data-checked": selected === actionType,
499
+ children: /* @__PURE__ */ jsxs(FieldLabel, { htmlFor: `${name}-${actionType}`, children: [
500
+ /* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx(
501
+ FieldInput,
502
+ {
503
+ type: "radio",
504
+ id: `${name}-${actionType}`,
505
+ name,
506
+ checked: selected === actionType,
507
+ onChange: handleChange,
508
+ value: actionType
509
+ }
510
+ ) }),
511
+ actionType
512
+ ] })
513
+ }
514
+ );
515
+ };
516
+ const ReleaseActionOptions = ({ selected, handleChange, name }) => {
517
+ return /* @__PURE__ */ jsxs(Flex, { children: [
518
+ /* @__PURE__ */ jsx(
519
+ ActionOption,
520
+ {
521
+ actionType: "publish",
522
+ selected,
523
+ handleChange,
524
+ name
525
+ }
526
+ ),
527
+ /* @__PURE__ */ jsx(
528
+ ActionOption,
529
+ {
530
+ actionType: "unpublish",
531
+ selected,
532
+ handleChange,
533
+ name
534
+ }
535
+ )
536
+ ] });
537
+ };
538
+ const RELEASE_ACTION_FORM_SCHEMA = yup.object().shape({
539
+ type: yup.string().oneOf(["publish", "unpublish"]).required(),
540
+ releaseId: yup.string().required()
541
+ });
542
+ const INITIAL_VALUES = {
543
+ type: "publish",
544
+ releaseId: ""
545
+ };
546
+ const NoReleases = () => {
547
+ const { formatMessage } = useIntl();
548
+ return /* @__PURE__ */ jsx(
549
+ NoContent,
550
+ {
551
+ content: {
552
+ id: "content-releases.content-manager-edit-view.add-to-release.no-releases-message",
553
+ defaultMessage: "No available releases. Open the list of releases and create a new one from there."
554
+ },
555
+ action: /* @__PURE__ */ jsx(
556
+ LinkButton,
557
+ {
558
+ to: {
559
+ pathname: "/plugins/content-releases"
560
+ },
561
+ as: Link$1,
562
+ variant: "secondary",
563
+ children: formatMessage({
564
+ id: "content-releases.content-manager-edit-view.add-to-release.redirect-button",
565
+ defaultMessage: "Open the list of releases"
566
+ })
567
+ }
568
+ )
569
+ }
570
+ );
571
+ };
572
+ const AddActionToReleaseModal = ({
573
+ handleClose,
574
+ contentTypeUid,
575
+ entryId
576
+ }) => {
577
+ const { formatMessage } = useIntl();
578
+ const toggleNotification = useNotification();
579
+ const { formatAPIError } = useAPIErrorHandler();
580
+ const { modifiedData } = useCMEditViewDataManager();
581
+ const response = useGetReleasesForEntryQuery({
582
+ contentTypeUid,
583
+ entryId,
584
+ hasEntryAttached: false
585
+ });
586
+ const releases = response.data?.data;
587
+ const [createReleaseAction, { isLoading }] = useCreateReleaseActionMutation();
588
+ const handleSubmit = async (values) => {
589
+ const locale = modifiedData.locale;
590
+ const releaseActionEntry = {
591
+ contentType: contentTypeUid,
592
+ id: entryId,
593
+ locale
594
+ };
595
+ const response2 = await createReleaseAction({
596
+ body: { type: values.type, entry: releaseActionEntry },
597
+ params: { releaseId: values.releaseId }
598
+ });
599
+ if ("data" in response2) {
600
+ toggleNotification({
601
+ type: "success",
602
+ message: formatMessage({
603
+ id: "content-releases.content-manager-edit-view.add-to-release.notification.success",
604
+ defaultMessage: "Entry added to release"
605
+ })
606
+ });
607
+ handleClose();
608
+ return;
609
+ }
610
+ if ("error" in response2) {
611
+ if (isAxiosError$1(response2.error)) {
612
+ toggleNotification({
613
+ type: "warning",
614
+ message: formatAPIError(response2.error)
615
+ });
616
+ } else {
617
+ toggleNotification({
618
+ type: "warning",
619
+ message: formatMessage({ id: "notification.error", defaultMessage: "An error occurred" })
620
+ });
621
+ }
622
+ }
623
+ };
624
+ return /* @__PURE__ */ jsxs(ModalLayout, { onClose: handleClose, labelledBy: "title", children: [
625
+ /* @__PURE__ */ jsx(ModalHeader, { children: /* @__PURE__ */ jsx(Typography, { id: "title", fontWeight: "bold", textColor: "neutral800", children: formatMessage({
626
+ id: "content-releases.content-manager-edit-view.add-to-release",
627
+ defaultMessage: "Add to release"
628
+ }) }) }),
629
+ /* @__PURE__ */ jsx(
630
+ Formik,
631
+ {
632
+ onSubmit: handleSubmit,
633
+ validationSchema: RELEASE_ACTION_FORM_SCHEMA,
634
+ initialValues: INITIAL_VALUES,
635
+ children: ({ values, setFieldValue }) => {
636
+ return /* @__PURE__ */ jsxs(Form, { children: [
637
+ releases?.length === 0 ? /* @__PURE__ */ jsx(NoReleases, {}) : /* @__PURE__ */ jsx(ModalBody, { children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
638
+ /* @__PURE__ */ jsx(Box, { paddingBottom: 6, children: /* @__PURE__ */ jsx(
639
+ SingleSelect,
640
+ {
641
+ required: true,
642
+ label: formatMessage({
643
+ id: "content-releases.content-manager-edit-view.add-to-release.select-label",
644
+ defaultMessage: "Select a release"
645
+ }),
646
+ placeholder: formatMessage({
647
+ id: "content-releases.content-manager-edit-view.add-to-release.select-placeholder",
648
+ defaultMessage: "Select"
649
+ }),
650
+ onChange: (value) => setFieldValue("releaseId", value),
651
+ value: values.releaseId,
652
+ children: releases?.map((release) => /* @__PURE__ */ jsx(SingleSelectOption, { value: release.id, children: release.name }, release.id))
653
+ }
654
+ ) }),
655
+ /* @__PURE__ */ jsx(FieldLabel, { children: formatMessage({
656
+ id: "content-releases.content-manager-edit-view.add-to-release.action-type-label",
657
+ defaultMessage: "What do you want to do with this entry?"
658
+ }) }),
659
+ /* @__PURE__ */ jsx(
660
+ ReleaseActionOptions,
661
+ {
662
+ selected: values.type,
663
+ handleChange: (e) => setFieldValue("type", e.target.value),
664
+ name: "type"
665
+ }
666
+ )
667
+ ] }) }),
668
+ /* @__PURE__ */ jsx(
669
+ ModalFooter,
670
+ {
671
+ startActions: /* @__PURE__ */ jsx(Button, { onClick: handleClose, variant: "tertiary", name: "cancel", children: formatMessage({
672
+ id: "content-releases.content-manager-edit-view.add-to-release.cancel-button",
673
+ defaultMessage: "Cancel"
674
+ }) }),
675
+ endActions: (
676
+ /**
677
+ * TODO: Ideally we would use isValid from Formik to disable the button, however currently it always returns true
678
+ * for yup.string().required(), even when the value is falsy (including empty string)
679
+ */
680
+ /* @__PURE__ */ jsx(Button, { type: "submit", disabled: !values.releaseId, loading: isLoading, children: formatMessage({
681
+ id: "content-releases.content-manager-edit-view.add-to-release.continue-button",
682
+ defaultMessage: "Continue"
683
+ }) })
684
+ )
685
+ }
686
+ )
687
+ ] });
688
+ }
689
+ }
690
+ )
691
+ ] });
692
+ };
693
+ const CMReleasesContainer = () => {
694
+ const [isModalOpen, setIsModalOpen] = React.useState(false);
695
+ const { formatMessage } = useIntl();
696
+ const {
697
+ isCreatingEntry,
698
+ allLayoutData: { contentType }
699
+ } = useCMEditViewDataManager();
700
+ const params = useParams();
701
+ const canFetch = params?.id != null && contentType?.uid != null;
702
+ const fetchParams = canFetch ? {
703
+ contentTypeUid: contentType.uid,
704
+ entryId: params.id,
705
+ hasEntryAttached: true
706
+ } : skipToken;
707
+ const response = useGetReleasesForEntryQuery(fetchParams);
708
+ const releases = response.data?.data;
709
+ if (!canFetch) {
710
+ return null;
711
+ }
712
+ if (isCreatingEntry || !contentType?.options?.draftAndPublish) {
713
+ return null;
714
+ }
715
+ const toggleModal = () => setIsModalOpen((prev) => !prev);
716
+ const getReleaseColorVariant = (actionType, shade) => {
717
+ if (actionType === "unpublish") {
718
+ return `secondary${shade}`;
719
+ }
720
+ return `success${shade}`;
721
+ };
722
+ return /* @__PURE__ */ jsx(CheckPermissions, { permissions: PERMISSIONS.main, children: /* @__PURE__ */ jsxs(
723
+ Box,
724
+ {
725
+ as: "aside",
726
+ "aria-label": formatMessage({
727
+ id: "content-releases.plugin.name",
728
+ defaultMessage: "Releases"
729
+ }),
730
+ background: "neutral0",
731
+ borderColor: "neutral150",
732
+ hasRadius: true,
733
+ padding: 4,
734
+ shadow: "tableShadow",
735
+ children: [
736
+ /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 3, children: [
737
+ /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", textTransform: "uppercase", children: formatMessage({
738
+ id: "content-releases.plugin.name",
739
+ defaultMessage: "Releases"
740
+ }) }),
741
+ releases?.map((release) => {
742
+ return /* @__PURE__ */ jsxs(
743
+ Flex,
744
+ {
745
+ direction: "column",
746
+ alignItems: "start",
747
+ borderWidth: "1px",
748
+ borderStyle: "solid",
749
+ borderColor: getReleaseColorVariant(release.action.type, "200"),
750
+ overflow: "hidden",
751
+ hasRadius: true,
752
+ children: [
753
+ /* @__PURE__ */ jsx(
754
+ Box,
755
+ {
756
+ paddingTop: 3,
757
+ paddingBottom: 3,
758
+ paddingLeft: 4,
759
+ paddingRight: 4,
760
+ background: getReleaseColorVariant(release.action.type, "100"),
761
+ width: "100%",
762
+ children: /* @__PURE__ */ jsx(
763
+ Typography,
764
+ {
765
+ fontSize: 1,
766
+ variant: "pi",
767
+ textColor: getReleaseColorVariant(release.action.type, "600"),
768
+ children: formatMessage(
769
+ {
770
+ id: "content-releases.content-manager-edit-view.list-releases.title",
771
+ defaultMessage: "{isPublish, select, true {Will be published in} other {Will be unpublished in}}"
772
+ },
773
+ { isPublish: release.action.type === "publish" }
774
+ )
775
+ }
776
+ )
777
+ }
778
+ ),
779
+ /* @__PURE__ */ jsxs(Flex, { padding: 4, direction: "column", gap: 3, width: "100%", alignItems: "flex-start", children: [
780
+ /* @__PURE__ */ jsx(Typography, { fontSize: 2, fontWeight: "bold", variant: "omega", textColor: "neutral700", children: release.name }),
781
+ /* @__PURE__ */ jsx(ReleaseActionMenu.Root, { hasTriggerBorder: true, children: /* @__PURE__ */ jsx(
782
+ ReleaseActionMenu.DeleteReleaseActionItem,
783
+ {
784
+ releaseId: release.id,
785
+ actionId: release.action.id
786
+ }
787
+ ) })
788
+ ] })
789
+ ]
790
+ },
791
+ release.id
792
+ );
793
+ }),
794
+ /* @__PURE__ */ jsx(CheckPermissions, { permissions: PERMISSIONS.createAction, children: /* @__PURE__ */ jsx(
795
+ Button,
796
+ {
797
+ justifyContent: "center",
798
+ paddingLeft: 4,
799
+ paddingRight: 4,
800
+ color: "neutral700",
801
+ variant: "tertiary",
802
+ startIcon: /* @__PURE__ */ jsx(Plus, {}),
803
+ onClick: toggleModal,
804
+ children: formatMessage({
805
+ id: "content-releases.content-manager-edit-view.add-to-release",
806
+ defaultMessage: "Add to release"
807
+ })
808
+ }
809
+ ) })
810
+ ] }),
811
+ isModalOpen && /* @__PURE__ */ jsx(
812
+ AddActionToReleaseModal,
813
+ {
814
+ handleClose: toggleModal,
815
+ contentTypeUid: contentType.uid,
816
+ entryId: params.id
817
+ }
818
+ )
819
+ ]
820
+ }
821
+ ) });
822
+ };
823
+ const admin = {
824
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
825
+ register(app) {
826
+ if (window.strapi.features.isEnabled("cms-content-releases")) {
827
+ app.addMenuLink({
828
+ to: `/plugins/${pluginId}`,
829
+ icon: PaperPlane,
830
+ intlLabel: {
831
+ id: `${pluginId}.plugin.name`,
832
+ defaultMessage: "Releases"
833
+ },
834
+ async Component() {
835
+ const { App } = await import("./App-BWaM2ihP.mjs");
836
+ return App;
837
+ },
838
+ permissions: PERMISSIONS.main
839
+ });
840
+ app.addMiddlewares([() => releaseApi.middleware]);
841
+ app.addReducers({
842
+ [releaseApi.reducerPath]: releaseApi.reducer
843
+ });
844
+ app.injectContentManagerComponent("editView", "right-links", {
845
+ name: `${pluginId}-link`,
846
+ Component: CMReleasesContainer
847
+ });
848
+ }
849
+ },
850
+ async registerTrads({ locales }) {
851
+ const importedTrads = await Promise.all(
852
+ locales.map((locale) => {
853
+ return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/en.json": () => import("./en-MyLPoISH.mjs") }), `./translations/${locale}.json`).then(({ default: data }) => {
854
+ return {
855
+ data: prefixPluginTranslations(data, "content-releases"),
856
+ locale
857
+ };
858
+ }).catch(() => {
859
+ return {
860
+ data: {},
861
+ locale
862
+ };
863
+ });
864
+ })
865
+ );
866
+ return Promise.resolve(importedTrads);
867
+ }
868
+ };
869
+ export {
870
+ PERMISSIONS as P,
871
+ ReleaseActionOptions as R,
872
+ useUpdateReleaseMutation as a,
873
+ useDeleteReleaseMutation as b,
874
+ usePublishReleaseMutation as c,
875
+ useTypedDispatch as d,
876
+ useGetReleaseActionsQuery as e,
877
+ useUpdateReleaseActionMutation as f,
878
+ ReleaseActionMenu as g,
879
+ useGetReleasesQuery as h,
880
+ isAxiosError as i,
881
+ useCreateReleaseMutation as j,
882
+ admin as k,
883
+ pluginId as p,
884
+ releaseApi as r,
885
+ useGetReleaseQuery as u
886
+ };
887
+ //# sourceMappingURL=index-EIe8S-cw.mjs.map