From f23686240a14e82c53226a5d8fd3f876f66c7ac7 Mon Sep 17 00:00:00 2001 From: Alex Grozav Date: Fri, 17 May 2024 14:35:15 +0300 Subject: [PATCH 1/7] fix: fix various design system type errors --- .../components/N8nColorPicker/ColorPicker.vue | 9 ++++-- .../src/components/N8nFormInput/FormInput.vue | 17 ++++++----- .../src/components/N8nFormInput/validators.ts | 6 ++-- .../components/N8nFormInputs/FormInputs.vue | 2 +- .../src/components/N8nInput/Input.vue | 22 ++++++++++++-- .../components/N8nInputNumber/InputNumber.vue | 20 +++++++++++-- .../src/components/N8nLink/Link.vue | 4 ++- .../src/components/N8nNodeIcon/NodeIcon.vue | 9 ++++-- .../src/components/N8nRoute/Route.vue | 6 ++-- .../src/components/N8nSelect/Select.vue | 15 ++++++---- .../N8nUsersList/UsersList.stories.ts | 6 ++-- .../src/components/N8nUsersList/UsersList.vue | 11 +++++-- packages/design-system/src/types/datatable.ts | 4 +-- packages/design-system/src/types/form.ts | 6 +++- packages/design-system/tsconfig.json | 2 +- .../editor-ui/src/views/SettingsUsersView.vue | 29 +++++++++++++++---- 16 files changed, 121 insertions(+), 47 deletions(-) diff --git a/packages/design-system/src/components/N8nColorPicker/ColorPicker.vue b/packages/design-system/src/components/N8nColorPicker/ColorPicker.vue index 0754fcc87b93a..0c97c43577daf 100644 --- a/packages/design-system/src/components/N8nColorPicker/ColorPicker.vue +++ b/packages/design-system/src/components/N8nColorPicker/ColorPicker.vue @@ -23,6 +23,8 @@ const props = withDefaults(defineProps(), { showAlpha: false, colorFormat: 'hex', popperClass: '', + predefine: undefined, + modelValue: undefined, showInput: true, name: uid('color-picker'), }); @@ -30,7 +32,7 @@ const props = withDefaults(defineProps(), { const color = ref(props.modelValue); const colorPickerProps = computed(() => { - const { showInput, ...rest } = props; + const { showInput, modelValue, size, ...rest } = props; return rest; }); @@ -50,6 +52,8 @@ const model = computed({ }, }); +const resolvedSize = computed(() => props.size as '' | 'small' | 'large' | 'default' | undefined); + const onChange = (value: string) => { emit('change', value); }; @@ -68,6 +72,7 @@ const onActiveChange = (value: string) => { @@ -75,7 +80,7 @@ const onActiveChange = (value: string) => { v-if="showInput" :class="$style.input" :disabled="props.disabled" - :size="props.size" + :size="size" :model-value="color" :name="name" type="text" diff --git a/packages/design-system/src/components/N8nFormInput/FormInput.vue b/packages/design-system/src/components/N8nFormInput/FormInput.vue index 87f0732b51282..e802048a6a881 100644 --- a/packages/design-system/src/components/N8nFormInput/FormInput.vue +++ b/packages/design-system/src/components/N8nFormInput/FormInput.vue @@ -59,9 +59,9 @@ v-else ref="inputRef" :name="name" - :type="type" + :type="type as InputType" :placeholder="placeholder" - :model-value="modelValue" + :model-value="modelValue as InputModelValue" :maxlength="maxlength" :autocomplete="autocomplete" :disabled="disabled" @@ -103,6 +103,9 @@ import type { Rule, RuleGroup, IValidator, Validatable, FormState } from '../../ import { t } from '../../locale'; +type InputModelValue = string | number | undefined; +type InputType = 'number' | 'text' | 'email' | 'password' | 'textarea' | undefined; + export interface Props { modelValue: Validatable; label: string; @@ -120,10 +123,10 @@ export interface Props { validators?: { [key: string]: IValidator | RuleGroup }; maxlength?: number; options?: Array<{ value: string | number; label: string; disabled?: boolean }>; - autocomplete?: string; + autocomplete?: 'off' | 'autocomplete'; name?: string; focusInitially?: boolean; - labelSize?: 'small' | 'medium'; + labelSize?: 'small' | 'medium' | 'large'; disabled?: boolean; activeLabel?: string; activeColor?: string; @@ -225,9 +228,9 @@ const validationError = computed(() => { const error = getInputValidationError(); if (error) { - if (error.messageKey) { - return t(error.messageKey, error.options); - } else { + if ('messageKey' in error) { + return t(error.messageKey, error.options as object); + } else if ('message' in error) { return error.message; } } diff --git a/packages/design-system/src/components/N8nFormInput/validators.ts b/packages/design-system/src/components/N8nFormInput/validators.ts index 855c3ba6a2050..990e6b083ba53 100644 --- a/packages/design-system/src/components/N8nFormInput/validators.ts +++ b/packages/design-system/src/components/N8nFormInput/validators.ts @@ -20,7 +20,7 @@ export const requiredValidator: IValidator<{}> = { }; export const minLengthValidator: IValidator<{ minimum: number }> = { - validate: (value: Validatable, config: { minimum: number }) => { + validate: (value: Validatable, config) => { if (typeof value === 'string' && value.length < config.minimum) { return { messageKey: 'formInput.validator.minCharactersRequired', @@ -76,7 +76,7 @@ export const emailValidator: IValidator<{}> = { }; export const containsUpperCaseValidator: IValidator<{ minimum: number }> = { - validate: (value: Validatable, config: { minimum: number }) => { + validate: (value: Validatable, config) => { if (typeof value !== 'string') { return false; } @@ -94,7 +94,7 @@ export const containsUpperCaseValidator: IValidator<{ minimum: number }> = { }; export const matchRegex: IValidator<{ regex: RegExp; message: string }> = { - validate: (value: Validatable, config: { regex: RegExp; message: string }) => { + validate: (value: Validatable, config) => { if (!config.regex.test(`${value as string}`)) { return { message: config.message, diff --git a/packages/design-system/src/components/N8nFormInputs/FormInputs.vue b/packages/design-system/src/components/N8nFormInputs/FormInputs.vue index 3060646dd56ea..293b78e854e55 100644 --- a/packages/design-system/src/components/N8nFormInputs/FormInputs.vue +++ b/packages/design-system/src/components/N8nFormInputs/FormInputs.vue @@ -75,7 +75,7 @@ export default defineComponent({ default: true, }, tagSize: { - type: String, + type: String as PropType<'small' | 'medium'>, default: 'small', validator: (value: string): boolean => ['small', 'medium'].includes(value), }, diff --git a/packages/design-system/src/components/N8nInput/Input.vue b/packages/design-system/src/components/N8nInput/Input.vue index d5419d23178c9..3fbe7bd3553d1 100644 --- a/packages/design-system/src/components/N8nInput/Input.vue +++ b/packages/design-system/src/components/N8nInput/Input.vue @@ -1,11 +1,18 @@