Skip to content

Commit d10517b

Browse files
committed
fix(app-headless-cms): add support for custom DZ actions
1 parent 467f5e4 commit d10517b

File tree

4 files changed

+68
-19
lines changed

4 files changed

+68
-19
lines changed

packages/app-headless-cms/src/ContentEntryEditorConfig.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
ContentEntryFormMeta,
1515
ContentEntryFormTitle
1616
} from "~/admin/views/contentEntries/ContentEntry/FullScreenContentEntry/FullScreenContentEntryHeaderLeft";
17+
import { SingleValueItemContainer } from "~/admin/plugins/fieldRenderers/dynamicZone/SingleValueDynamicZone";
1718

1819
export const ContentEntryEditorConfig = Object.assign(BaseContentEntryEditorConfig, {
1920
ContentEntry: Object.assign(ContentEntry, {
@@ -42,11 +43,9 @@ export const ContentEntryEditorConfig = Object.assign(BaseContentEntryEditorConf
4243
useTemplate: DzField.useTemplate
4344
},
4445
Container: DzField.DynamicZoneContainer,
45-
// SingleValue: {
46-
// Container: null,
47-
// ItemContainer: null,
48-
// Item: null
49-
// },
46+
SingleValue: {
47+
ItemContainer: SingleValueItemContainer
48+
},
5049
MultiValue: {
5150
Container: DzField.MultiValueContainer,
5251
ItemContainer: DzField.MultiValueItemContainer,

packages/app-headless-cms/src/admin/plugins/fieldRenderers/dynamicZone/MultiValueDynamicZone.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export interface MultiValueItemContainerProps {
4242
title: React.ReactNode;
4343
description: string;
4444
icon: JSX.Element;
45+
actions?: JSX.Element;
4546
template: CmsDynamicZoneTemplate;
4647
children: React.ReactNode;
4748
}
@@ -53,20 +54,28 @@ export const MultiValueItemContainer = makeDecoratable(
5354
<AccordionItem.Actions>
5455
<AccordionItem.Action
5556
icon={<ArrowUpIcon />}
57+
tooltip={"Move up"}
5658
onClick={props.onMoveUp}
5759
disabled={props.isFirst}
5860
/>
5961
<AccordionItem.Action
6062
icon={<ArrowDownIcon />}
63+
tooltip={"Move down"}
6164
onClick={props.onMoveDown}
6265
disabled={props.isLast}
6366
/>
6467
<AccordionItem.Divider />
68+
{props.actions ? <>{props.actions}</> : null}
6569
<AccordionItem.Action
70+
tooltip={"Duplicate"}
6671
icon={<CloneIcon />}
6772
onClick={() => props.onClone(props.value)}
6873
/>
69-
<AccordionItem.Action icon={<DeleteIcon />} onClick={props.onDelete} />
74+
<AccordionItem.Action
75+
icon={<DeleteIcon />}
76+
onClick={props.onDelete}
77+
tooltip={"Delete"}
78+
/>
7079
</AccordionItem.Actions>
7180
);
7281

packages/app-headless-cms/src/admin/plugins/fieldRenderers/dynamicZone/SingleValueDynamicZone.tsx

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
ParentValueIndexProvider,
1919
ModelFieldProvider
2020
} from "~/admin/components/ModelFieldProvider";
21-
import { useConfirmationDialog } from "@webiny/app-admin";
21+
import { makeDecoratable, useConfirmationDialog } from "@webiny/app-admin";
2222

2323
type GetBind = CmsModelFieldRendererProps["getBind"];
2424

@@ -29,6 +29,51 @@ interface SingleValueDynamicZoneProps {
2929
getBind: GetBind;
3030
}
3131

32+
interface TemplateValue {
33+
_templateId: string;
34+
[key: string]: any;
35+
}
36+
37+
export interface SingleValueItemContainerProps {
38+
value: TemplateValue;
39+
contentModel: CmsModel;
40+
onDelete: () => void;
41+
title: React.ReactNode;
42+
description: string;
43+
icon: JSX.Element;
44+
actions?: JSX.Element;
45+
template: CmsDynamicZoneTemplate;
46+
children: React.ReactNode;
47+
}
48+
49+
export const SingleValueItemContainer = makeDecoratable(
50+
"SingleValueItemContainer",
51+
(props: SingleValueItemContainerProps) => {
52+
const { template, actions, children } = props;
53+
return (
54+
<AccordionItem
55+
title={template.name}
56+
description={template.description}
57+
icon={<TemplateIcon icon={template.icon} />}
58+
open={true}
59+
interactive={false}
60+
actions={
61+
<AccordionItem.Actions>
62+
{actions ?? null}
63+
<AccordionItem.Action
64+
icon={<DeleteIcon />}
65+
onClick={props.onDelete}
66+
tooltip={"Delete"}
67+
/>
68+
</AccordionItem.Actions>
69+
}
70+
>
71+
{children}
72+
</AccordionItem>
73+
);
74+
}
75+
);
76+
3277
export const SingleValueDynamicZone = ({
3378
field,
3479
bind,
@@ -66,20 +111,14 @@ export const SingleValueDynamicZone = ({
66111
<ParentValueIndexProvider index={-1}>
67112
<ModelFieldProvider field={field}>
68113
<Accordion>
69-
<AccordionItem
114+
<SingleValueItemContainer
115+
template={template}
116+
value={bind.value}
117+
contentModel={contentModel}
118+
onDelete={unsetValue}
70119
title={template.name}
71120
description={template.description}
72121
icon={<TemplateIcon icon={template.icon} />}
73-
open={true}
74-
interactive={false}
75-
actions={
76-
<AccordionItem.Actions>
77-
<AccordionItem.Action
78-
icon={<DeleteIcon />}
79-
onClick={unsetValue}
80-
/>
81-
</AccordionItem.Actions>
82-
}
83122
>
84123
<TemplateProvider template={template}>
85124
<Fields
@@ -89,7 +128,7 @@ export const SingleValueDynamicZone = ({
89128
Bind={Bind}
90129
/>
91130
</TemplateProvider>
92-
</AccordionItem>
131+
</SingleValueItemContainer>
93132
</Accordion>
94133
</ModelFieldProvider>
95134
</ParentValueIndexProvider>

packages/app-headless-cms/src/admin/plugins/fieldRenderers/dynamicZone/dynamicZoneRenderer.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export type DynamicZoneContainerProps = {
3030
title?: string;
3131
description?: string;
3232
className?: string;
33+
actions?: JSX.Element;
3334
};
3435

3536
export const DynamicZoneContainer = makeDecoratable(
@@ -57,6 +58,7 @@ export const DynamicZoneContainer = makeDecoratable(
5758
description={description}
5859
className={className || defaultClassName}
5960
open={open}
61+
actions={props.actions ?? null}
6062
>
6163
{children}
6264
</AccordionItem>

0 commit comments

Comments
 (0)