From ce5b7b54dad3bcf677a3d7a23c67f9e17ee111ba Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Fri, 27 Oct 2023 12:38:42 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20[#2]=20PR=20feedback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/formio/common.ts | 2 +- src/formio/components/checkbox.ts | 2 +- src/formio/components/email.ts | 2 +- src/formio/components/index.ts | 2 +- src/formio/components/radio.ts | 28 ++++++++------ src/formio/components/selectboxes.ts | 30 ++++++++------- test-d/formio/components/checkbox.test-d.ts | 1 + test-d/formio/components/email.test-d.ts | 15 ++++++++ test-d/formio/components/radio.test-d.ts | 37 +++++++++++++++++-- .../formio/components/selectboxes.test-d.ts | 6 ++- 10 files changed, 90 insertions(+), 35 deletions(-) diff --git a/src/formio/common.ts b/src/formio/common.ts index d0618c1..34c01b6 100644 --- a/src/formio/common.ts +++ b/src/formio/common.ts @@ -9,7 +9,7 @@ export interface Option { value: string; label: string; openForms?: { - translations: ComponentTranslations; + translations: ComponentTranslations<'label'>; }; } diff --git a/src/formio/components/checkbox.ts b/src/formio/components/checkbox.ts index bf9ff0d..5ee7dd1 100644 --- a/src/formio/components/checkbox.ts +++ b/src/formio/components/checkbox.ts @@ -12,6 +12,6 @@ export type CheckboxInputSchema = InputComponentSchema { type: 'checkbox'; - defaultValue?: boolean; + defaultValue: boolean; multiple?: false; } diff --git a/src/formio/components/email.ts b/src/formio/components/email.ts index bdb651d..1d00500 100644 --- a/src/formio/components/email.ts +++ b/src/formio/components/email.ts @@ -11,7 +11,7 @@ export type EmailInputSchema = InputComponentSchema { type: 'email'; - validateOn?: 'blur'; + validateOn: 'blur'; // additional properties autocomplete?: string; // OF custom properties diff --git a/src/formio/components/index.ts b/src/formio/components/index.ts index df17a54..b4dfee5 100644 --- a/src/formio/components/index.ts +++ b/src/formio/components/index.ts @@ -10,11 +10,11 @@ export * from './postcode'; export * from './iban'; export * from './licenseplate'; export * from './radio'; -export * from './selectboxes'; export * from './number'; export * from './checkbox'; export * from './selectboxes'; export * from './file'; +export * from './radio'; // Layout components export * from './content'; diff --git a/src/formio/components/radio.ts b/src/formio/components/radio.ts index e9edefd..2eadbef 100644 --- a/src/formio/components/radio.ts +++ b/src/formio/components/radio.ts @@ -11,26 +11,30 @@ export type RadioInputSchema = InputComponentSchema { +interface BaseRadioSchema { type: 'radio'; - defaultValue?: string | null; + defaultValue: string | null; multiple?: false; - // additional properties - openForms: OFExtensions['openForms'] & ManualValues; - values: Option[]; } /** * @group Form.io components * @category Base types */ -interface RadioVariableValuesSchema extends Omit { - type: 'radio'; - defaultValue?: string | null; - multiple?: false; - // additional properties - openForms: OFExtensions['openForms'] & VariableValues; -} +type RadioManualValuesSchema = Omit & + BaseRadioSchema & { + openForms: OFExtensions['openForms'] & ManualValues; + values: Option[]; + }; + +/** + * @group Form.io components + * @category Base types + */ +type RadioVariableValuesSchema = Omit & + BaseRadioSchema & { + openForms: OFExtensions['openForms'] & VariableValues; + }; /** * @group Form.io components diff --git a/src/formio/components/selectboxes.ts b/src/formio/components/selectboxes.ts index cd97862..4a25b46 100644 --- a/src/formio/components/selectboxes.ts +++ b/src/formio/components/selectboxes.ts @@ -15,28 +15,30 @@ export type SelectboxesInputSchema = InputComponentSchema< * @group Form.io components * @category Base types */ -interface SelectboxesManualValuesSchema - extends Omit { +interface BaseSelectboxesSchema { type: 'selectboxes'; - defaultValue?: Record; + defaultValue: Record; multiple?: false; - // additional properties - openForms: OFExtensions['openForms'] & ManualValues; - values: Option[]; } /** * @group Form.io components * @category Base types */ -interface SelectboxesVariableValuesSchema - extends Omit { - type: 'selectboxes'; - defaultValue?: Record; - multiple?: false; - // additional properties - openForms: OFExtensions['openForms'] & VariableValues; -} +type SelectboxesManualValuesSchema = Omit & + BaseSelectboxesSchema & { + openForms: OFExtensions['openForms'] & ManualValues; + values: Option[]; + }; + +/** + * @group Form.io components + * @category Base types + */ +type SelectboxesVariableValuesSchema = Omit & + BaseSelectboxesSchema & { + openForms: OFExtensions['openForms'] & VariableValues; + }; /** * @group Form.io components diff --git a/test-d/formio/components/checkbox.test-d.ts b/test-d/formio/components/checkbox.test-d.ts index c4f5c67..619f95e 100644 --- a/test-d/formio/components/checkbox.test-d.ts +++ b/test-d/formio/components/checkbox.test-d.ts @@ -8,6 +8,7 @@ expectAssignable({ type: 'checkbox', key: 'someCheckbox', label: 'Some checkbox', + defaultValue: true, }); diff --git a/test-d/formio/components/email.test-d.ts b/test-d/formio/components/email.test-d.ts index 02332d8..e69a5f8 100644 --- a/test-d/formio/components/email.test-d.ts +++ b/test-d/formio/components/email.test-d.ts @@ -8,6 +8,7 @@ expectAssignable({ type: 'email', key: 'someEmail', label: 'Some email', + validateOn: 'blur', }); // with additional, email-component specific properties @@ -16,6 +17,7 @@ expectAssignable({ type: 'email', key: 'someEmail', label: 'Some email', + validateOn: 'blur', autocomplete: 'email', confirmationRecipient: false, }); @@ -26,6 +28,7 @@ expectAssignable({ type: 'email', key: 'someEmail', label: 'Some email', + validateOn: 'blur', multiple: false, defaultValue: '', }); @@ -36,6 +39,7 @@ expectAssignable({ type: 'email', key: 'someEmail', label: 'Some email', + validateOn: 'blur', multiple: true, defaultValue: [''], }); @@ -95,12 +99,21 @@ expectNotAssignable({ validateOn: 'change', }); +// missing validateOn +expectNotAssignable({ + id: 'yejak', + type: 'email', + key: 'someEmail', + label: 'Some email', +}); + // invalid, multiple true and non-array default value expectNotAssignable({ id: 'yejak', type: 'email', key: 'someEmail', label: 'Some email', + validateOn: 'blur', multiple: true, defaultValue: '', }); @@ -111,6 +124,7 @@ expectNotAssignable({ type: 'email', key: 'someEmail', label: 'Some email', + validateOn: 'blur', multiple: false, defaultValue: [''], }); @@ -121,6 +135,7 @@ expectNotAssignable({ type: 'email', key: 'someEmail', label: 'Some email', + validateOn: 'blur', multiple: true, defaultValue: [0], }); diff --git a/test-d/formio/components/radio.test-d.ts b/test-d/formio/components/radio.test-d.ts index 04d0d7e..0d48598 100644 --- a/test-d/formio/components/radio.test-d.ts +++ b/test-d/formio/components/radio.test-d.ts @@ -8,6 +8,7 @@ expectAssignable({ type: 'radio', key: 'aRadio', label: 'A radio', + defaultValue: null, openForms: { dataSrc: 'manual', translations: {}, @@ -26,9 +27,10 @@ expectAssignable({ type: 'radio', key: 'aRadio', label: 'A radio', + defaultValue: null, openForms: { dataSrc: 'variable', - itemsExpression: 'dummy', + itemsExpression: {var: 'dummy'}, translations: {}, }, }); @@ -82,10 +84,10 @@ expectAssignable({ openForms: { translations: { en: { - dummy: 'dummy_en', + label: 'dummy_en', }, nl: { - dummy_: 'dummy_nl', // TODO this should not be possible + label: 'dummy_nl', } } } @@ -198,3 +200,32 @@ expectNotAssignable({ translations: {}, }, }); + +// manual with both itemsExpression and values +expectNotAssignable({ + id: 'yejak', + type: 'radio', + key: 'aRadio', + label: 'A radio', + openForms: { + dataSrc: 'manual', + itemsExpression: 'dummy', + translations: {}, + }, + values: [ + { + value: 'dummy', + label: 'dummy', + openForms: { + translations: { + en: { + label: 'dummy_en', + }, + nl: { + label: 'dummy_nl', + } + } + } + } + ] +}); diff --git a/test-d/formio/components/selectboxes.test-d.ts b/test-d/formio/components/selectboxes.test-d.ts index 6b8c044..2a0f29d 100644 --- a/test-d/formio/components/selectboxes.test-d.ts +++ b/test-d/formio/components/selectboxes.test-d.ts @@ -8,6 +8,7 @@ expectAssignable({ type: 'selectboxes', key: 'someSelectboxes', label: 'Some selectboxes', + defaultValue: {}, openForms: { dataSrc: 'manual', translations: {}, @@ -26,6 +27,7 @@ expectAssignable({ type: 'selectboxes', key: 'someSelectboxes', label: 'Some selectboxes', + defaultValue: {}, openForms: { dataSrc: 'variable', itemsExpression: 'dummy', @@ -67,10 +69,10 @@ expectAssignable({ openForms: { translations: { en: { - dummy: 'dummy_en', + label: 'dummy_en', }, nl: { - dummy_: 'dummy_nl', // TODO this should not be possible + label: 'dummy_nl', } } }