Skip to content

Commit ba662b1

Browse files
authored
fix: control HCMS entry editor width using Width config (#4555)
1 parent f48143d commit ba662b1

File tree

5 files changed

+47
-24
lines changed

5 files changed

+47
-24
lines changed

packages/app-headless-cms/src/admin/config/contentEntries/editor/Actions/BaseAction.tsx

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react";
22
import { Property, useIdGenerator } from "@webiny/react-properties";
3-
import { useModel } from "~/admin/hooks";
3+
import { IsApplicableToCurrentModel } from "~/admin/config/IsApplicableToCurrentModel";
44

55
export interface BaseActionConfig<T extends string> {
66
name: string;
@@ -27,28 +27,25 @@ export const BaseAction = ({
2727
element,
2828
$type
2929
}: BaseActionProps) => {
30-
const { model } = useModel();
3130
const getId = useIdGenerator("action");
3231

33-
if (modelIds.length > 0 && !modelIds.includes(model.modelId)) {
34-
return null;
35-
}
36-
3732
const placeAfter = after !== undefined ? getId(after) : undefined;
3833
const placeBefore = before !== undefined ? getId(before) : undefined;
3934

4035
return (
41-
<Property
42-
id={getId(name)}
43-
name={"actions"}
44-
remove={remove}
45-
array={true}
46-
before={placeBefore}
47-
after={placeAfter}
48-
>
49-
<Property id={getId(name, "name")} name={"name"} value={name} />
50-
<Property id={getId(name, "element")} name={"element"} value={element} />
51-
<Property id={getId(name, "$type")} name={"$type"} value={$type} />
52-
</Property>
36+
<IsApplicableToCurrentModel modelIds={modelIds}>
37+
<Property
38+
id={getId(name)}
39+
name={"actions"}
40+
remove={remove}
41+
array={true}
42+
before={placeBefore}
43+
after={placeAfter}
44+
>
45+
<Property id={getId(name, "name")} name={"name"} value={name} />
46+
<Property id={getId(name, "element")} name={"element"} value={element} />
47+
<Property id={getId(name, "$type")} name={"$type"} value={$type} />
48+
</Property>
49+
</IsApplicableToCurrentModel>
5350
);
5451
};

packages/app-headless-cms/src/admin/config/contentEntries/editor/ContentEntryEditorConfig.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@ import { useMemo } from "react";
22
import { createConfigurableComponent } from "@webiny/react-properties";
33
import { Actions, ActionsConfig } from "./Actions";
44
import { FieldElement } from "./FieldElement";
5+
import { Width } from "./Width";
56

67
const base = createConfigurableComponent<ContentEntryEditorConfig>("ContentEntryEditorConfig");
78

8-
export const ContentEntryEditorConfig = Object.assign(base.Config, { Actions, FieldElement });
9+
export const ContentEntryEditorConfig = Object.assign(base.Config, {
10+
Actions,
11+
FieldElement,
12+
Width
13+
});
914

1015
export const ContentEntryEditorWithConfig = base.WithConfig;
1116

1217
interface ContentEntryEditorConfig {
1318
actions: ActionsConfig;
19+
width: string;
1420
}
1521

1622
export function useContentEntryEditorConfig() {
@@ -23,7 +29,8 @@ export function useContentEntryEditorConfig() {
2329
buttonActions: [...(actions.filter(action => action.$type === "button-action") || [])],
2430
menuItemActions: [
2531
...(actions.filter(action => action.$type === "menu-item-action") || [])
26-
]
32+
],
33+
width: config.width || "1020px"
2734
}),
2835
[config]
2936
);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from "react";
2+
import { Property } from "@webiny/react-properties";
3+
import { IsApplicableToCurrentModel } from "~/admin/config/IsApplicableToCurrentModel";
4+
5+
export interface WidthProps {
6+
value: string;
7+
modelIds?: string[];
8+
}
9+
10+
export const Width = ({ value, modelIds = [] }: WidthProps) => {
11+
return (
12+
<IsApplicableToCurrentModel modelIds={modelIds}>
13+
<Property id={`contentEntryForm:width`} name={"width"} value={value} />
14+
</IsApplicableToCurrentModel>
15+
);
16+
};

packages/app-headless-cms/src/admin/views/contentEntries/ContentEntry/FullScreenContentEntry/FullScreenContentEntry.styled.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,10 @@ export const FullScreenContentEntryContentFormWrapper = styled.div`
106106
justify-content: center;
107107
`;
108108

109-
export const FullScreenContentEntryContentFormInner = styled.div`
110-
flex-shrink: 1;
111-
flex-basis: 1020px;
109+
type FullScreenContentEntryContentFormInnerProps = { width: string };
110+
111+
export const FullScreenContentEntryContentFormInner = styled.div<FullScreenContentEntryContentFormInnerProps>`
112+
width: ${props => props.width};
112113
`;
113114

114115
export const FullScreenContentEntryContentFormInnerCss = css`

packages/app-headless-cms/src/admin/views/contentEntries/ContentEntry/FullScreenContentEntry/FullScreenContentEntry.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ import {
1616
import { FullScreenContentEntryProvider } from "./useFullScreenContentEntry";
1717
import { ContentEntryEditorConfig } from "~/ContentEntryEditorConfig";
1818
import { cmsLegacyEntryEditor } from "~/utils/cmsLegacyEntryEditor";
19+
import { useContentEntryEditorConfig } from "~/admin/config/contentEntries";
1920

2021
const { ContentEntry } = ContentEntryEditorConfig;
2122

2223
const FullScreenContentEntryDecorator = ContentEntry.createDecorator(Original => {
2324
return function ContentEntry() {
25+
const { width } = useContentEntryEditorConfig();
2426
const { loading } = useContentEntry();
2527
const [isRevisionListOpen, openRevisionList] = useState<boolean>(false);
2628

@@ -45,7 +47,7 @@ const FullScreenContentEntryDecorator = ContentEntry.createDecorator(Original =>
4547
{loading && <CircularProgress style={{ zIndex: 10 }} />}
4648
<FullScreenContentEntryContent>
4749
<FullScreenContentEntryContentFormWrapper>
48-
<FullScreenContentEntryContentFormInner>
50+
<FullScreenContentEntryContentFormInner width={width}>
4951
<Original />
5052
</FullScreenContentEntryContentFormInner>
5153
</FullScreenContentEntryContentFormWrapper>

0 commit comments

Comments
 (0)