From 7f82d4a98c46bb576023ffe9fbbcbcec39f9617f Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Tue, 24 Oct 2023 16:17:55 +0200 Subject: [PATCH 1/6] =?UTF-8?q?=E2=9C=A8=20[#2]=20Implement=20types=20for?= =?UTF-8?q?=20`checkbox`=20and=20`checkboxes`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/formio/components/checkbox.ts | 15 +++++++++++++++ src/formio/components/index.ts | 2 ++ src/formio/components/selectboxes.ts | 18 ++++++++++++++++++ src/formio/index.ts | 4 ++++ 4 files changed, 39 insertions(+) create mode 100644 src/formio/components/checkbox.ts create mode 100644 src/formio/components/selectboxes.ts diff --git a/src/formio/components/checkbox.ts b/src/formio/components/checkbox.ts new file mode 100644 index 0000000..8f92dc7 --- /dev/null +++ b/src/formio/components/checkbox.ts @@ -0,0 +1,15 @@ +import {InputComponentSchema} from '..'; + +type Validator = 'required'; +type TranslatableKeys = 'label' | 'description' | 'tooltip'; + +export type CheckboxInputSchema = InputComponentSchema; + +/** + * @group Form.io components + * @category Concrete types + */ +export interface CheckboxComponentSchema + extends Omit { + type: 'checkbox'; +} diff --git a/src/formio/components/index.ts b/src/formio/components/index.ts index b89d3a4..bb356e1 100644 --- a/src/formio/components/index.ts +++ b/src/formio/components/index.ts @@ -10,6 +10,8 @@ export * from './postcode'; export * from './iban'; export * from './licenseplate'; export * from './number'; +export * from './checkbox'; +export * from './selectboxes'; export * from './file'; // Layout components diff --git a/src/formio/components/selectboxes.ts b/src/formio/components/selectboxes.ts new file mode 100644 index 0000000..0149295 --- /dev/null +++ b/src/formio/components/selectboxes.ts @@ -0,0 +1,18 @@ +import {InputComponentSchema} from '..'; + +type Validator = 'required'; +type TranslatableKeys = 'label' | 'description' | 'tooltip'; + +export type SelectboxesInputSchema = InputComponentSchema; + +/** + * @group Form.io components + * @category Concrete types + */ +export interface SelectboxesComponentSchema + extends Omit { + type: 'selectboxes'; + // OF custom properties + dataSrc: 'manual' | 'variable'; + itemsExpression?: string; +} diff --git a/src/formio/index.ts b/src/formio/index.ts index c64f224..2d64bd8 100644 --- a/src/formio/index.ts +++ b/src/formio/index.ts @@ -1,4 +1,5 @@ import { + CheckboxComponentSchema, ContentComponentSchema, CurrencyComponentSchema, DateComponentSchema, @@ -10,6 +11,7 @@ import { NumberComponentSchema, PhoneNumberComponentSchema, PostcodeComponentSchema, + SelectboxesComponentSchema, TextFieldComponentSchema, TimeComponentSchema, } from './components'; @@ -40,12 +42,14 @@ export * from './components'; export type AnyComponentSchema = // inputs | TextFieldComponentSchema + | CheckboxComponentSchema | EmailComponentSchema | DateComponentSchema | DateTimeComponentSchema | TimeComponentSchema | PhoneNumberComponentSchema | PostcodeComponentSchema + | SelectboxesComponentSchema | FileComponentSchema | NumberComponentSchema | CurrencyComponentSchema From d0e6ac110af20fb8f9d643f268debba3d637a1de Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Thu, 26 Oct 2023 12:39:08 +0200 Subject: [PATCH 2/6] =?UTF-8?q?=E2=9C=A8=20[#2]=20Apply=20feedback=20and?= =?UTF-8?q?=20add=20`radio`=20component?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/formio/common.ts | 29 +++ src/formio/components/checkbox.ts | 4 +- src/formio/components/email.ts | 1 + src/formio/components/index.ts | 2 + src/formio/components/radio.ts | 39 ++++ src/formio/components/selectboxes.ts | 41 +++- src/formio/index.ts | 9 +- src/types.ts | 4 + test-d/formio/components/checkbox.test-d.ts | 84 ++++++++ test-d/formio/components/email.test-d.ts | 9 + test-d/formio/components/radio.test-d.ts | 200 ++++++++++++++++++ .../formio/components/selectboxes.test-d.ts | 185 ++++++++++++++++ 12 files changed, 598 insertions(+), 9 deletions(-) create mode 100644 src/formio/common.ts create mode 100644 src/formio/components/radio.ts create mode 100644 src/types.ts create mode 100644 test-d/formio/components/checkbox.test-d.ts create mode 100644 test-d/formio/components/radio.test-d.ts create mode 100644 test-d/formio/components/selectboxes.test-d.ts diff --git a/src/formio/common.ts b/src/formio/common.ts new file mode 100644 index 0000000..d0618c1 --- /dev/null +++ b/src/formio/common.ts @@ -0,0 +1,29 @@ +import {JSONObject} from '@/types'; + +import {ComponentTranslations} from './i18n'; + +/** + * @category Utilities + */ +export interface Option { + value: string; + label: string; + openForms?: { + translations: ComponentTranslations; + }; +} + +/** + * @category Utilities + */ +export interface ManualValues { + dataSrc: 'manual'; +} + +/** + * @category Utilities + */ +export interface VariableValues { + dataSrc: 'variable'; + itemsExpression: string | JSONObject; +} diff --git a/src/formio/components/checkbox.ts b/src/formio/components/checkbox.ts index 8f92dc7..bf9ff0d 100644 --- a/src/formio/components/checkbox.ts +++ b/src/formio/components/checkbox.ts @@ -3,7 +3,7 @@ import {InputComponentSchema} from '..'; type Validator = 'required'; type TranslatableKeys = 'label' | 'description' | 'tooltip'; -export type CheckboxInputSchema = InputComponentSchema; +export type CheckboxInputSchema = InputComponentSchema; /** * @group Form.io components @@ -12,4 +12,6 @@ export type CheckboxInputSchema = InputComponentSchema { type: 'checkbox'; + defaultValue?: boolean; + multiple?: false; } diff --git a/src/formio/components/email.ts b/src/formio/components/email.ts index 5c9e54c..bdb651d 100644 --- a/src/formio/components/email.ts +++ b/src/formio/components/email.ts @@ -11,6 +11,7 @@ export type EmailInputSchema = InputComponentSchema { type: 'email'; + validateOn?: 'blur'; // additional properties autocomplete?: string; // OF custom properties diff --git a/src/formio/components/index.ts b/src/formio/components/index.ts index bb356e1..df17a54 100644 --- a/src/formio/components/index.ts +++ b/src/formio/components/index.ts @@ -9,6 +9,8 @@ export * from './phonenumber'; export * from './postcode'; export * from './iban'; export * from './licenseplate'; +export * from './radio'; +export * from './selectboxes'; export * from './number'; export * from './checkbox'; export * from './selectboxes'; diff --git a/src/formio/components/radio.ts b/src/formio/components/radio.ts new file mode 100644 index 0000000..e9edefd --- /dev/null +++ b/src/formio/components/radio.ts @@ -0,0 +1,39 @@ +import {InputComponentSchema} from '..'; +import {OFExtensions} from '../base'; +import {ManualValues, Option, VariableValues} from '../common'; + +type Validator = 'required'; +type TranslatableKeys = 'label' | 'description' | 'tooltip'; + +export type RadioInputSchema = InputComponentSchema; + +/** + * @group Form.io components + * @category Base types + */ +interface RadioManualValuesSchema extends Omit { + type: 'radio'; + 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; +} + +/** + * @group Form.io components + * @category Concrete types + */ +export type RadioComponentSchema = RadioManualValuesSchema | RadioVariableValuesSchema; diff --git a/src/formio/components/selectboxes.ts b/src/formio/components/selectboxes.ts index 0149295..cd97862 100644 --- a/src/formio/components/selectboxes.ts +++ b/src/formio/components/selectboxes.ts @@ -1,18 +1,47 @@ import {InputComponentSchema} from '..'; +import {OFExtensions} from '../base'; +import {ManualValues, Option, VariableValues} from '../common'; type Validator = 'required'; type TranslatableKeys = 'label' | 'description' | 'tooltip'; -export type SelectboxesInputSchema = InputComponentSchema; +export type SelectboxesInputSchema = InputComponentSchema< + Record, + Validator, + TranslatableKeys +>; /** * @group Form.io components - * @category Concrete types + * @category Base types */ -export interface SelectboxesComponentSchema +interface SelectboxesManualValuesSchema extends Omit { type: 'selectboxes'; - // OF custom properties - dataSrc: 'manual' | 'variable'; - itemsExpression?: string; + 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; +} + +/** + * @group Form.io components + * @category Concrete types + */ +export type SelectboxesComponentSchema = + | SelectboxesManualValuesSchema + | SelectboxesVariableValuesSchema; diff --git a/src/formio/index.ts b/src/formio/index.ts index 2d64bd8..b07f702 100644 --- a/src/formio/index.ts +++ b/src/formio/index.ts @@ -11,6 +11,7 @@ import { NumberComponentSchema, PhoneNumberComponentSchema, PostcodeComponentSchema, + RadioComponentSchema, SelectboxesComponentSchema, TextFieldComponentSchema, TimeComponentSchema, @@ -42,20 +43,24 @@ export * from './components'; export type AnyComponentSchema = // inputs | TextFieldComponentSchema - | CheckboxComponentSchema | EmailComponentSchema | DateComponentSchema | DateTimeComponentSchema | TimeComponentSchema | PhoneNumberComponentSchema | PostcodeComponentSchema - | SelectboxesComponentSchema | FileComponentSchema | NumberComponentSchema +<<<<<<< HEAD | CurrencyComponentSchema // special types | IbanComponentSchema | LicensePlateComponentSchema +======= + | CheckboxComponentSchema + | SelectboxesComponentSchema + | RadioComponentSchema +>>>>>>> dab8ef2 (✨ [#2] Apply feedback and add `radio` component) // layout | ContentComponentSchema; diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 0000000..e793a40 --- /dev/null +++ b/src/types.ts @@ -0,0 +1,4 @@ +export type JSONPrimitive = string | number | boolean | null; +export type JSONValue = JSONPrimitive | JSONObject | JSONArray; +export type JSONObject = {[member: string]: JSONValue}; +export interface JSONArray extends Array {} diff --git a/test-d/formio/components/checkbox.test-d.ts b/test-d/formio/components/checkbox.test-d.ts new file mode 100644 index 0000000..c4f5c67 --- /dev/null +++ b/test-d/formio/components/checkbox.test-d.ts @@ -0,0 +1,84 @@ +import {expectAssignable, expectNotAssignable} from 'tsd'; + +import {CheckboxComponentSchema} from '../../../lib'; + +// minimal component schema +expectAssignable({ + id: 'yejak', + type: 'checkbox', + key: 'someCheckbox', + label: 'Some checkbox', +}); + + +// multiple false and appropriate default value type +expectAssignable({ + id: 'yejak', + type: 'checkbox', + key: 'someCheckbox', + label: 'Some checkbox', + multiple: false, + defaultValue: true, +}); + +// full, correct schema +expectAssignable({ + id: 'yejak', + type: 'checkbox', + // basic tab + label: 'Some checkbox', + key: 'someCheckbox', + description: '', + tooltip: 'A tooltip', + showInSummary: true, + showInEmail: false, + showInPDF: true, + multiple: false, + hidden: false, + clearOnHide: true, + isSensitiveData: true, + defaultValue: false, + // Advanced tab + conditional: { + show: undefined, + when: '', + eq: '', + }, + // Validation tab + validate: { + required: false, + plugins: [], + }, + translatedErrors: {nl: {required: 'Geef checkbox.'}}, + errors: {required: 'Geef checkbox.'}, + // registration tab + registration: { + attribute: '', + }, + // translations tab in builder form + openForms: { + translations: { + nl: {label: 'foo'}, + }, + }, + // fixed but not editable + validateOn: 'blur', +}); + +// multiple true not allowed +expectNotAssignable({ + id: 'yejak', + type: 'checkbox', + key: 'someCheckbox', + label: 'Some checkbox', + multiple: true, +}); + +// defaultValue not allowed +expectNotAssignable({ + id: 'yejak', + 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 45d9b14..02332d8 100644 --- a/test-d/formio/components/email.test-d.ts +++ b/test-d/formio/components/email.test-d.ts @@ -86,6 +86,15 @@ expectAssignable({ validateOn: 'blur', }); +// validateOn not `blur` +expectNotAssignable({ + id: 'yejak', + type: 'email', + key: 'someEmail', + label: 'Some email', + validateOn: 'change', +}); + // invalid, multiple true and non-array default value expectNotAssignable({ id: 'yejak', diff --git a/test-d/formio/components/radio.test-d.ts b/test-d/formio/components/radio.test-d.ts new file mode 100644 index 0000000..9c6db78 --- /dev/null +++ b/test-d/formio/components/radio.test-d.ts @@ -0,0 +1,200 @@ +import {expectAssignable, expectNotAssignable} from 'tsd'; + +import {RadioComponentSchema} from '../../../lib'; + +// minimal component schema, manual: +expectAssignable({ + id: 'yejak', + type: 'radio', + key: 'someRadio', + label: 'Some radio', + openForms: { + dataSrc: 'manual', + translations: {}, + }, + values: [ + { + value: 'dummy', + label: 'dummy', + } + ], +}); + +// minimal component schema, variable: +expectAssignable({ + id: 'yejak', + type: 'radio', + key: 'someRadio', + label: 'Some radio', + openForms: { + dataSrc: 'variable', + itemsExpression: 'dummy', + translations: {}, + }, +}); + +// multiple false and appropriate default value type +expectAssignable({ + id: 'yejak', + type: 'radio', + key: 'someRadio', + label: 'Some radio', + multiple: false, + defaultValue: 'dummy', + openForms: { + dataSrc: 'variable', + itemsExpression: 'dummy', + translations: {}, + }, +}); + +// multiple false and default value type to null +expectAssignable({ + id: 'yejak', + type: 'radio', + key: 'someRadio', + label: 'Some radio', + multiple: false, + defaultValue: null, + openForms: { + dataSrc: 'variable', + itemsExpression: 'dummy', + translations: {}, + }, +}); + +// values translations +expectAssignable({ + id: 'yejak', + type: 'radio', + key: 'someRadio', + label: 'Some radio', + multiple: false, + defaultValue: 'dummy', + openForms: { + dataSrc: 'manual', + translations: {}, + }, + values: [ + { + value: 'dummy', + label: 'dummy', + openForms: { + translations: { + en: { + dummy: 'dummy_en', + }, + nl: { + dummy_: 'dummy_nl', // TODO this should not be possible + } + } + } + } + ] +}); + +// full, correct schema +expectAssignable({ + id: 'yejak', + type: 'radio', + // basic tab + label: 'Some radio', + key: 'someRadio', + description: '', + tooltip: 'A tooltip', + showInSummary: true, + showInEmail: false, + showInPDF: true, + multiple: false, + hidden: false, + clearOnHide: true, + isSensitiveData: true, + defaultValue: 'dummy', + // Advanced tab + conditional: { + show: undefined, + when: '', + eq: '', + }, + // Validation tab + validate: { + required: false, + plugins: [], + }, + translatedErrors: {nl: {required: 'Geef checkbox.'}}, + errors: {required: 'Geef checkbox.'}, + // registration tab + registration: { + attribute: '', + }, + // translations tab in builder form + openForms: { + translations: { + nl: {label: 'foo'}, + }, + dataSrc: 'variable', + itemsExpression: 'dummy', + }, + // fixed but not editable + validateOn: 'blur', +}); + +// Missing openForms +expectNotAssignable({ + id: 'yejak', + type: 'radio', + key: 'someRadio', + label: 'Some radio', +}); + +// multiple true not allowed +expectNotAssignable({ + id: 'yejak', + type: 'radio', + key: 'someRadio', + label: 'Some radio', + multiple: true, + openForms: { + dataSrc: 'variable', + itemsExpression: 'dummy', + translations: {}, + }, +}); + +// defaultValue not allowed +expectNotAssignable({ + id: 'yejak', + type: 'radio', + key: 'someRadio', + label: 'Some radio', + defaultValue: [{dummy: true}], + openForms: { + dataSrc: 'variable', + itemsExpression: 'dummy', + translations: {}, + }, +}); + +// manual without values +expectNotAssignable({ + id: 'yejak', + type: 'radio', + key: 'someRadio', + label: 'Some radio', + openForms: { + dataSrc: 'manual', + translations: {}, + }, +}); + +// variable without itemsExpressions +expectNotAssignable({ + id: 'yejak', + type: 'radio', + key: 'someRadio', + label: 'Some radio', + openForms: { + dataSrc: 'variable', + translations: {}, + }, +}); diff --git a/test-d/formio/components/selectboxes.test-d.ts b/test-d/formio/components/selectboxes.test-d.ts new file mode 100644 index 0000000..6b8c044 --- /dev/null +++ b/test-d/formio/components/selectboxes.test-d.ts @@ -0,0 +1,185 @@ +import {expectAssignable, expectNotAssignable} from 'tsd'; + +import {SelectboxesComponentSchema} from '../../../lib'; + +// minimal component schema, manual: +expectAssignable({ + id: 'yejak', + type: 'selectboxes', + key: 'someSelectboxes', + label: 'Some selectboxes', + openForms: { + dataSrc: 'manual', + translations: {}, + }, + values: [ + { + value: 'dummy', + label: 'dummy', + } + ], +}); + +// minimal component schema, variable: +expectAssignable({ + id: 'yejak', + type: 'selectboxes', + key: 'someSelectboxes', + label: 'Some selectboxes', + openForms: { + dataSrc: 'variable', + itemsExpression: 'dummy', + translations: {}, + }, +}); + +// multiple false and appropriate default value type +expectAssignable({ + id: 'yejak', + type: 'selectboxes', + key: 'someSelectboxes', + label: 'Some selectboxes', + multiple: false, + defaultValue: {dummy: true}, + openForms: { + dataSrc: 'variable', + itemsExpression: 'dummy', + translations: {}, + }, +}); + +// values translations +expectAssignable({ + id: 'yejak', + type: 'selectboxes', + key: 'someSelectboxes', + label: 'Some selectboxes', + multiple: false, + defaultValue: {dummy: true}, + openForms: { + dataSrc: 'manual', + translations: {}, + }, + values: [ + { + value: 'dummy', + label: 'dummy', + openForms: { + translations: { + en: { + dummy: 'dummy_en', + }, + nl: { + dummy_: 'dummy_nl', // TODO this should not be possible + } + } + } + } + ] +}); + +// full, correct schema +expectAssignable({ + id: 'yejak', + type: 'selectboxes', + // basic tab + label: 'Some selectboxes', + key: 'someSelectboxes', + description: '', + tooltip: 'A tooltip', + showInSummary: true, + showInEmail: false, + showInPDF: true, + multiple: false, + hidden: false, + clearOnHide: true, + isSensitiveData: true, + defaultValue: {dummy: true}, + // Advanced tab + conditional: { + show: undefined, + when: '', + eq: '', + }, + // Validation tab + validate: { + required: false, + plugins: [], + }, + translatedErrors: {nl: {required: 'Geef checkbox.'}}, + errors: {required: 'Geef checkbox.'}, + // registration tab + registration: { + attribute: '', + }, + // translations tab in builder form + openForms: { + translations: { + nl: {label: 'foo'}, + }, + dataSrc: 'variable', + itemsExpression: 'dummy', + }, + // fixed but not editable + validateOn: 'blur', +}); + +// Missing openForms +expectNotAssignable({ + id: 'yejak', + type: 'selectboxes', + key: 'someSelectboxes', + label: 'Some selectboxes', +}); + +// multiple true not allowed +expectNotAssignable({ + id: 'yejak', + type: 'selectboxes', + key: 'someSelectboxes', + label: 'Some selectboxes', + multiple: true, + openForms: { + dataSrc: 'variable', + itemsExpression: 'dummy', + translations: {}, + }, +}); + +// defaultValue not allowed +expectNotAssignable({ + id: 'yejak', + type: 'selectboxes', + key: 'someSelectboxes', + label: 'Some selectboxes', + defaultValue: [{dummy: true}], + openForms: { + dataSrc: 'variable', + itemsExpression: 'dummy', + translations: {}, + }, +}); + +// manual without values +expectNotAssignable({ + id: 'yejak', + type: 'selectboxes', + key: 'someSelectboxes', + label: 'Some selectboxes', + openForms: { + dataSrc: 'manual', + translations: {}, + }, +}); + +// variable without itemsExpressions +expectNotAssignable({ + id: 'yejak', + type: 'selectboxes', + key: 'someSelectboxes', + label: 'Some selectboxes', + openForms: { + dataSrc: 'variable', + translations: {}, + }, +}); From f1b23b8eeac1aa6c0e191670518071ba1a7ac6cc Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Thu, 26 Oct 2023 16:11:30 +0200 Subject: [PATCH 3/6] =?UTF-8?q?=E2=9C=A8=20[#2]=20Rename=20`radio`=20test?= =?UTF-8?q?=20values?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test-d/formio/components/radio.test-d.ts | 44 ++++++++++++------------ 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/test-d/formio/components/radio.test-d.ts b/test-d/formio/components/radio.test-d.ts index 9c6db78..04d0d7e 100644 --- a/test-d/formio/components/radio.test-d.ts +++ b/test-d/formio/components/radio.test-d.ts @@ -6,8 +6,8 @@ import {RadioComponentSchema} from '../../../lib'; expectAssignable({ id: 'yejak', type: 'radio', - key: 'someRadio', - label: 'Some radio', + key: 'aRadio', + label: 'A radio', openForms: { dataSrc: 'manual', translations: {}, @@ -24,8 +24,8 @@ expectAssignable({ expectAssignable({ id: 'yejak', type: 'radio', - key: 'someRadio', - label: 'Some radio', + key: 'aRadio', + label: 'A radio', openForms: { dataSrc: 'variable', itemsExpression: 'dummy', @@ -37,8 +37,8 @@ expectAssignable({ expectAssignable({ id: 'yejak', type: 'radio', - key: 'someRadio', - label: 'Some radio', + key: 'aRadio', + label: 'A radio', multiple: false, defaultValue: 'dummy', openForms: { @@ -52,8 +52,8 @@ expectAssignable({ expectAssignable({ id: 'yejak', type: 'radio', - key: 'someRadio', - label: 'Some radio', + key: 'aRadio', + label: 'A radio', multiple: false, defaultValue: null, openForms: { @@ -67,8 +67,8 @@ expectAssignable({ expectAssignable({ id: 'yejak', type: 'radio', - key: 'someRadio', - label: 'Some radio', + key: 'aRadio', + label: 'A radio', multiple: false, defaultValue: 'dummy', openForms: { @@ -98,8 +98,8 @@ expectAssignable({ id: 'yejak', type: 'radio', // basic tab - label: 'Some radio', - key: 'someRadio', + label: 'A radio', + key: 'aRadio', description: '', tooltip: 'A tooltip', showInSummary: true, @@ -143,16 +143,16 @@ expectAssignable({ expectNotAssignable({ id: 'yejak', type: 'radio', - key: 'someRadio', - label: 'Some radio', + key: 'aRadio', + label: 'A radio', }); // multiple true not allowed expectNotAssignable({ id: 'yejak', type: 'radio', - key: 'someRadio', - label: 'Some radio', + key: 'aRadio', + label: 'A radio', multiple: true, openForms: { dataSrc: 'variable', @@ -165,8 +165,8 @@ expectNotAssignable({ expectNotAssignable({ id: 'yejak', type: 'radio', - key: 'someRadio', - label: 'Some radio', + key: 'aRadio', + label: 'A radio', defaultValue: [{dummy: true}], openForms: { dataSrc: 'variable', @@ -179,8 +179,8 @@ expectNotAssignable({ expectNotAssignable({ id: 'yejak', type: 'radio', - key: 'someRadio', - label: 'Some radio', + key: 'aRadio', + label: 'A radio', openForms: { dataSrc: 'manual', translations: {}, @@ -191,8 +191,8 @@ expectNotAssignable({ expectNotAssignable({ id: 'yejak', type: 'radio', - key: 'someRadio', - label: 'Some radio', + key: 'aRadio', + label: 'A radio', openForms: { dataSrc: 'variable', translations: {}, 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 4/6] =?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', } } } From ac532737de605abfb082bd8294520ef8272bedb9 Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Fri, 27 Oct 2023 12:50:31 +0200 Subject: [PATCH 5/6] =?UTF-8?q?=E2=9C=A8=20[#2]=20Remove=20`multiple`=20wh?= =?UTF-8?q?en=20not=20multipleCapable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/formio/components/checkbox.ts | 1 - src/formio/components/index.ts | 1 - src/formio/components/radio.ts | 1 - src/formio/components/selectboxes.ts | 1 - src/formio/index.ts | 9 ++--- test-d/formio/components/checkbox.test-d.ts | 15 ++------ test-d/formio/components/radio.test-d.ts | 36 ++----------------- .../formio/components/selectboxes.test-d.ts | 21 ++--------- 8 files changed, 9 insertions(+), 76 deletions(-) diff --git a/src/formio/components/checkbox.ts b/src/formio/components/checkbox.ts index 5ee7dd1..342313a 100644 --- a/src/formio/components/checkbox.ts +++ b/src/formio/components/checkbox.ts @@ -13,5 +13,4 @@ export interface CheckboxComponentSchema extends Omit { type: 'checkbox'; defaultValue: boolean; - multiple?: false; } diff --git a/src/formio/components/index.ts b/src/formio/components/index.ts index b4dfee5..a6d591f 100644 --- a/src/formio/components/index.ts +++ b/src/formio/components/index.ts @@ -9,7 +9,6 @@ export * from './phonenumber'; export * from './postcode'; export * from './iban'; export * from './licenseplate'; -export * from './radio'; export * from './number'; export * from './checkbox'; export * from './selectboxes'; diff --git a/src/formio/components/radio.ts b/src/formio/components/radio.ts index 2eadbef..5cfe308 100644 --- a/src/formio/components/radio.ts +++ b/src/formio/components/radio.ts @@ -14,7 +14,6 @@ export type RadioInputSchema = InputComponentSchema; - multiple?: false; } /** diff --git a/src/formio/index.ts b/src/formio/index.ts index b07f702..1ada62f 100644 --- a/src/formio/index.ts +++ b/src/formio/index.ts @@ -51,16 +51,13 @@ export type AnyComponentSchema = | PostcodeComponentSchema | FileComponentSchema | NumberComponentSchema -<<<<<<< HEAD + | CheckboxComponentSchema + | SelectboxesComponentSchema | CurrencyComponentSchema + | RadioComponentSchema // special types | IbanComponentSchema | LicensePlateComponentSchema -======= - | CheckboxComponentSchema - | SelectboxesComponentSchema - | RadioComponentSchema ->>>>>>> dab8ef2 (✨ [#2] Apply feedback and add `radio` component) // layout | ContentComponentSchema; diff --git a/test-d/formio/components/checkbox.test-d.ts b/test-d/formio/components/checkbox.test-d.ts index 619f95e..11a1630 100644 --- a/test-d/formio/components/checkbox.test-d.ts +++ b/test-d/formio/components/checkbox.test-d.ts @@ -12,16 +12,6 @@ expectAssignable({ }); -// multiple false and appropriate default value type -expectAssignable({ - id: 'yejak', - type: 'checkbox', - key: 'someCheckbox', - label: 'Some checkbox', - multiple: false, - defaultValue: true, -}); - // full, correct schema expectAssignable({ id: 'yejak', @@ -34,7 +24,6 @@ expectAssignable({ showInSummary: true, showInEmail: false, showInPDF: true, - multiple: false, hidden: false, clearOnHide: true, isSensitiveData: true, @@ -66,13 +55,13 @@ expectAssignable({ validateOn: 'blur', }); -// multiple true not allowed +// multiple not allowed expectNotAssignable({ id: 'yejak', type: 'checkbox', key: 'someCheckbox', label: 'Some checkbox', - multiple: true, + multiple: 'dummy', }); // defaultValue not allowed diff --git a/test-d/formio/components/radio.test-d.ts b/test-d/formio/components/radio.test-d.ts index 0d48598..19685fb 100644 --- a/test-d/formio/components/radio.test-d.ts +++ b/test-d/formio/components/radio.test-d.ts @@ -35,43 +35,12 @@ expectAssignable({ }, }); -// multiple false and appropriate default value type -expectAssignable({ - id: 'yejak', - type: 'radio', - key: 'aRadio', - label: 'A radio', - multiple: false, - defaultValue: 'dummy', - openForms: { - dataSrc: 'variable', - itemsExpression: 'dummy', - translations: {}, - }, -}); - -// multiple false and default value type to null -expectAssignable({ - id: 'yejak', - type: 'radio', - key: 'aRadio', - label: 'A radio', - multiple: false, - defaultValue: null, - openForms: { - dataSrc: 'variable', - itemsExpression: 'dummy', - translations: {}, - }, -}); - // values translations expectAssignable({ id: 'yejak', type: 'radio', key: 'aRadio', label: 'A radio', - multiple: false, defaultValue: 'dummy', openForms: { dataSrc: 'manual', @@ -107,7 +76,6 @@ expectAssignable({ showInSummary: true, showInEmail: false, showInPDF: true, - multiple: false, hidden: false, clearOnHide: true, isSensitiveData: true, @@ -149,13 +117,13 @@ expectNotAssignable({ label: 'A radio', }); -// multiple true not allowed +// multiple not allowed expectNotAssignable({ id: 'yejak', type: 'radio', key: 'aRadio', label: 'A radio', - multiple: true, + multiple: false, openForms: { dataSrc: 'variable', itemsExpression: 'dummy', diff --git a/test-d/formio/components/selectboxes.test-d.ts b/test-d/formio/components/selectboxes.test-d.ts index 2a0f29d..83a5f18 100644 --- a/test-d/formio/components/selectboxes.test-d.ts +++ b/test-d/formio/components/selectboxes.test-d.ts @@ -35,28 +35,12 @@ expectAssignable({ }, }); -// multiple false and appropriate default value type -expectAssignable({ - id: 'yejak', - type: 'selectboxes', - key: 'someSelectboxes', - label: 'Some selectboxes', - multiple: false, - defaultValue: {dummy: true}, - openForms: { - dataSrc: 'variable', - itemsExpression: 'dummy', - translations: {}, - }, -}); - // values translations expectAssignable({ id: 'yejak', type: 'selectboxes', key: 'someSelectboxes', label: 'Some selectboxes', - multiple: false, defaultValue: {dummy: true}, openForms: { dataSrc: 'manual', @@ -92,7 +76,6 @@ expectAssignable({ showInSummary: true, showInEmail: false, showInPDF: true, - multiple: false, hidden: false, clearOnHide: true, isSensitiveData: true, @@ -134,13 +117,13 @@ expectNotAssignable({ label: 'Some selectboxes', }); -// multiple true not allowed +// multiple not allowed expectNotAssignable({ id: 'yejak', type: 'selectboxes', key: 'someSelectboxes', label: 'Some selectboxes', - multiple: true, + multiple: 'dummy', openForms: { dataSrc: 'variable', itemsExpression: 'dummy', From 980c36038f099121620b25532934aefe02733a62 Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Mon, 30 Oct 2023 13:40:22 +0100 Subject: [PATCH 6/6] =?UTF-8?q?=F0=9F=93=9D=20Add=20release=20instructions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 5d32fda..c5ce922 100644 --- a/README.md +++ b/README.md @@ -70,3 +70,18 @@ import { PrefillConfig, } from '@open-formulieren/types'; ``` + +## Release flow + +We don't let `npm` apply the git tags when releasing a new version, instead follow this process: + +```bash +npm version --no-git-tag-version minor +git commit -am ":bookmark: Bump to version " +git tag "" +git push origin main --tags +``` + +If you have PGP keys set up, you can use them for the git tag operation. + +The CI pipeline will then publish the new version to npmjs.