Skip to content

Commit

Permalink
Make it possible to remove the "Hide in menu" field from `createEditP…
Browse files Browse the repository at this point in the history
…ageNode` (#2052)

In some of our projects, the menu isn't generated directly from the
PageTree (but can be built separately). In that case it doesn't make
sense to have a "Hide in menu" checkbox and it's confusing to the users.
Thus, I added this option.

---------

Co-authored-by: Johannes Obermair <48853629+johnnyomair@users.noreply.github.com>
  • Loading branch information
thomasdax98 and johnnyomair authored May 14, 2024
1 parent 584d14d commit f89af8b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-suns-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@comet/cms-admin": minor
---

Add `disableHideInMenu` option to `createEditPageNode` to hide the "Hide in menu" checkbox
1 change: 1 addition & 0 deletions demo/admin/src/common/EditPageNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const additionalPageTreeNodeFieldsFragment = {
};

export const EditPageNode = createEditPageNode({
disableHideInMenu: false,
valuesToInput: ({ values }: { values: { userGroup: string } }) => {
return {
userGroup: values.userGroup,
Expand Down
42 changes: 23 additions & 19 deletions packages/admin/cms-admin/src/pages/createEditPageNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ interface CreateEditPageNodeProps {
additionalFormFields?: React.ReactNode;
nodeFragment?: { name: string; fragment: DocumentNode };
valuesToInput?: (values: EditPageNodeFinalFormValues) => EditPageNodeFinalFormValues;
disableHideInMenu?: boolean;
}

export interface EditPageNodeProps {
Expand All @@ -52,6 +53,7 @@ export function createEditPageNode({
additionalFormFields,
nodeFragment,
valuesToInput,
disableHideInMenu = false,
}: CreateEditPageNodeProps): (props: EditPageNodeProps) => JSX.Element {
const editPageNodeQuery = gql`
query EditPageNode($id: ID!) {
Expand Down Expand Up @@ -446,25 +448,27 @@ export function createEditPageNode({
</FinalFormSelect>
)}
</Field>
<Field
label={intl.formatMessage({
id: "comet.pages.pages.page.menuVisibility",
defaultMessage: "Menu Visibility",
})}
name="hideInMenu"
type="checkbox"
variant="horizontal"
>
{(props) => (
<FormControlLabel
label={intl.formatMessage({
id: "comet.pages.pages.page.hideInMenu",
defaultMessage: "Hide in Menu",
})}
control={<FinalFormCheckbox {...props} />}
/>
)}
</Field>
{!disableHideInMenu && (
<Field
label={intl.formatMessage({
id: "comet.pages.pages.page.menuVisibility",
defaultMessage: "Menu Visibility",
})}
name="hideInMenu"
type="checkbox"
variant="horizontal"
>
{(props) => (
<FormControlLabel
label={intl.formatMessage({
id: "comet.pages.pages.page.hideInMenu",
defaultMessage: "Hide in Menu",
})}
control={<FinalFormCheckbox {...props} />}
/>
)}
</Field>
)}

{additionalFormFields}
</>
Expand Down

0 comments on commit f89af8b

Please sign in to comment.