From 0ed41b7d7e77fa580832b961f2a1cbc2354b6473 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Thu, 17 Feb 2022 19:12:05 -0800 Subject: [PATCH] #176 - Extra setting updates --- package.json | 20 +++++++++++++++-- src/models/PanelSettings.ts | 1 + .../components/Fields/WrapperField.tsx | 22 ++++++------------- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index ad44c67f..d2f78f7f 100644 --- a/package.json +++ b/package.json @@ -701,7 +701,18 @@ "fields": { "$ref": "#contenttypefield" }, - "blockType": { + "fieldGroup": { + "type": [ + "string", + "array" + ], + "default": [], + "description": "The ID(s) of your field group(s) defined in the `frontMatter.taxonomy.fieldGroups` setting", + "items": { + "type": "string" + } + }, + "dataType": { "type": [ "string", "array" @@ -711,6 +722,11 @@ "items": { "type": "string" } + }, + "taxonomyLimit": { + "type": "number", + "default": 0, + "description": "Limit the number of taxonomies to select. Set to 0 to allow unlimited." } }, "additionalProperties": false, @@ -771,7 +787,7 @@ }, "then": { "required": [ - "blockType" + "fieldGroup" ] } }, diff --git a/src/models/PanelSettings.ts b/src/models/PanelSettings.ts index 16377739..20201bc6 100644 --- a/src/models/PanelSettings.ts +++ b/src/models/PanelSettings.ts @@ -64,6 +64,7 @@ export interface Field { fields?: Field[]; fieldGroup?: string | string[]; dataType?: string | string[]; + taxonomyLimit?: number | string[]; } export interface DateInfo { diff --git a/src/panelWebView/components/Fields/WrapperField.tsx b/src/panelWebView/components/Fields/WrapperField.tsx index a1b2e622..c67e4eac 100644 --- a/src/panelWebView/components/Fields/WrapperField.tsx +++ b/src/panelWebView/components/Fields/WrapperField.tsx @@ -70,7 +70,6 @@ export const WrapperField: React.FunctionComponent = ({ useEffect(() => { let value: any = parent[field.name]; - let shouldSetField = false; if (field.type === 'datetime') { value = getDate(value) || undefined; @@ -88,8 +87,6 @@ export const WrapperField: React.FunctionComponent = ({ if (field.type === "tags" || field.type === "categories" || field.type === "taxonomy") { value = []; } - - shouldSetField = true; } // Check if the field value contains a placeholder @@ -211,7 +208,8 @@ export const WrapperField: React.FunctionComponent = ({ focussed={focusElm === TagType.tags} unsetFocus={unsetFocus} parents={parentFields} - blockData={blockData} /> + blockData={blockData} + limit={field.taxonomyLimit} /> ); } else if (field.type === 'taxonomy') { @@ -231,31 +229,25 @@ export const WrapperField: React.FunctionComponent = ({ fieldName={field.name} taxonomyId={field.taxonomyId} parents={parentFields} - blockData={blockData} /> + blockData={blockData} + limit={field.taxonomyLimit} /> ); } else if (field.type === 'categories') { - let selectedValues = parent[field.name]; - if (!selectedValues && typeof parent[field.name] === "undefined" && field.default) { - selectedValues = field.default; - onSendUpdate(field.name, selectedValues, parentFields); - } else { - selectedValues = []; - } - return ( } - crntSelected={selectedValues as string[] || []} + crntSelected={fieldValue as string[] || []} options={settings.categories} freeform={settings.freeform || false} focussed={focusElm === TagType.categories} unsetFocus={unsetFocus} parents={parentFields} - blockData={blockData} /> + blockData={blockData} + limit={field.taxonomyLimit} /> ); } else if (field.type === 'draft') {