From 0fe93dc0e6f8004c3dab5753b56b57115dd10dfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Zori=C4=87?= Date: Fri, 15 Sep 2023 10:36:46 +0200 Subject: [PATCH] fix(app-headless-cms): boolean field default value (#3526) --- .../src/types/model.ts | 2 +- .../src/admin/plugins/fields/boolean.tsx | 55 ++++++++++++++++--- packages/ui/src/Input/Input.tsx | 2 +- 3 files changed, 48 insertions(+), 11 deletions(-) diff --git a/packages/app-headless-cms-common/src/types/model.ts b/packages/app-headless-cms-common/src/types/model.ts index 22c052bb6a7..9803638f0e4 100644 --- a/packages/app-headless-cms-common/src/types/model.ts +++ b/packages/app-headless-cms-common/src/types/model.ts @@ -12,7 +12,7 @@ import { CmsIdentity } from "~/types/shared"; export type CmsEditorField = CmsModelField; export interface CmsModelFieldSettings { - defaultValue?: string | null | undefined; + defaultValue?: string | boolean | number | null | undefined; defaultSetValue?: string; type?: string; fields?: CmsModelField[]; diff --git a/packages/app-headless-cms/src/admin/plugins/fields/boolean.tsx b/packages/app-headless-cms/src/admin/plugins/fields/boolean.tsx index d2ab279ce8c..a959afeff1e 100644 --- a/packages/app-headless-cms/src/admin/plugins/fields/boolean.tsx +++ b/packages/app-headless-cms/src/admin/plugins/fields/boolean.tsx @@ -2,12 +2,50 @@ import React from "react"; import { ReactComponent as BooleanIcon } from "@material-design-icons/svg/outlined/toggle_on.svg"; import { CmsModelFieldTypePlugin } from "~/types"; import { i18n } from "@webiny/app/i18n"; -import { Grid, Cell } from "@webiny/ui/Grid"; -import { Select } from "@webiny/ui/Select"; +import { Cell, Grid } from "@webiny/ui/Grid"; import { Bind } from "@webiny/form"; +import { Radio, RadioGroup } from "@webiny/ui/Radio"; const t = i18n.ns("app-headless-cms/admin/fields"); +interface OptionsProps { + onChange: (value: boolean) => void; + value?: boolean | "true" | "false"; +} + +const Options: React.VFC = ({ onChange, value: initialValue }) => { + const value = initialValue === true || initialValue === "true"; + + return ( + + {() => { + return ( + <> +
+ { + onChange(true); + }} + /> +
+
+ { + onChange(false); + }} + /> +
+ + ); + }} +
+ ); +}; + const plugin: CmsModelFieldTypePlugin = { type: "cms-editor-field-type", name: "cms-editor-field-type-boolean", @@ -25,6 +63,9 @@ const plugin: CmsModelFieldTypePlugin = { validation: [], renderer: { name: "" + }, + settings: { + defaultValue: false } }; }, @@ -33,13 +74,9 @@ const plugin: CmsModelFieldTypePlugin = { - + {bind => { + return ; + }} diff --git a/packages/ui/src/Input/Input.tsx b/packages/ui/src/Input/Input.tsx index 9beae159b72..d867d7d63d6 100644 --- a/packages/ui/src/Input/Input.tsx +++ b/packages/ui/src/Input/Input.tsx @@ -148,7 +148,7 @@ export const Input: React.FC = props => { onBlur={onBlur} label={label} icon={icon} - placeholder={(!label && placeholder) || undefined} + placeholder={placeholder} trailingIcon={trailingIcon} rows={rows} className={classNames(