Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: [M3-8954] - Update @hookform/resolvers to latest #11349

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/api-v4/src/cloudpulse/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,13 @@ export interface CreateAlertDefinitionPayload {
rule_criteria: {
rules: MetricCriteria[];
};
triggerCondition: TriggerCondition;
trigger_condition: TriggerCondition;
channel_ids: number[];
}
export interface MetricCriteria {
metric: string;
aggregation_type: MetricAggregationType;
operator: MetricOperatorType;
value: number;
dimension_filters: DimensionFilter[];
}

Expand Down
2 changes: 1 addition & 1 deletion packages/manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@dnd-kit/utilities": "^3.2.2",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@hookform/resolvers": "2.9.11",
"@hookform/resolvers": "3.9.1",
"@linode/api-v4": "*",
"@linode/design-language-system": "^2.6.1",
"@linode/search": "*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { filterFormValues, filterMetricCriteriaFormValues } from './utilities';

import type { CreateAlertDefinitionForm, MetricCriteriaForm } from './types';
import type { TriggerCondition } from '@linode/api-v4/lib/cloudpulse/types';
import type { ObjectSchema } from 'yup';

const triggerConditionInitialValues: TriggerCondition = {
evaluation_period_seconds: 0,
Expand All @@ -30,7 +31,6 @@ const criteriaInitialValues: MetricCriteriaForm = {
dimension_filters: [],
metric: '',
operator: null,
value: 0,
};
const initialValues: CreateAlertDefinitionForm = {
channel_ids: [],
Expand All @@ -43,7 +43,7 @@ const initialValues: CreateAlertDefinitionForm = {
},
serviceType: null,
severity: null,
triggerCondition: triggerConditionInitialValues,
trigger_condition: triggerConditionInitialValues,
};

const overrides = [
Expand All @@ -65,7 +65,9 @@ export const CreateAlertDefinition = () => {
const formMethods = useForm<CreateAlertDefinitionForm>({
defaultValues: initialValues,
mode: 'onBlur',
resolver: yupResolver(CreateAlertDefinitionFormSchema),
resolver: yupResolver(
CreateAlertDefinitionFormSchema as ObjectSchema<CreateAlertDefinitionForm>
),
});

const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export interface ImageUploadFormData extends ImageUploadPayload {
* form state at once.
*/
export const ImageUploadSchema = uploadImageSchema.shape({
file: mixed().required('Image is required.'),
file: mixed((input): input is File => input instanceof File).required(
'Image is required.'
),
});

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import type {
LinodeCreateFormContext,
LinodeCreateFormValues,
} from './utilities';
import type { CreateLinodeRequest } from '@linode/api-v4';
import type { QueryClient } from '@tanstack/react-query';
import type { FieldErrors, Resolver } from 'react-hook-form';
import type { ObjectSchema } from 'yup';

export const getLinodeCreateResolver = (
tab: LinodeCreateType | undefined,
Expand All @@ -30,9 +32,9 @@ export const getLinodeCreateResolver = (
const transformedValues = getLinodeCreatePayload(structuredClone(values));

const { errors } = await yupResolver(
schema,
schema as ObjectSchema<CreateLinodeRequest>,
{},
{ mode: 'async', rawValues: true }
{ mode: 'async', raw: true }
)(transformedValues, context, options);

if (tab === 'Clone Linode' && !values.linode) {
Expand Down
13 changes: 11 additions & 2 deletions packages/validation/src/buckets.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,17 @@ export const CreateBucketSchema = object()
}),
endpoint_type: string()
.oneOf([...ENDPOINT_TYPES])
.notRequired(),
cors_enabled: boolean().notRequired(),
.optional(),
cors_enabled: boolean().optional(),
acl: string()
.oneOf([
'private',
'public-read',
'authenticated-read',
'public-read-write',
])
.optional(),
s3_endpoint: string().optional(),
},
[['cluster', 'region']]
)
Expand Down
24 changes: 14 additions & 10 deletions packages/validation/src/cloudpulse.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ const metricCriteria = object({
dimension_filters: array().of(dimensionFilters).notRequired(),
});

const triggerCondition = object({
criteria_condition: string().required('Criteria condition is required.'),
polling_interval_seconds: string().required('Polling Interval is required.'),
evaluation_period_seconds: string().required(
const trigger_condition = object({
polling_interval_seconds: number().required('Polling Interval is required.'),
evaluation_period_seconds: number().required(
'Evaluation Period is required.'
),
trigger_occurrences: number()
Expand All @@ -30,10 +29,15 @@ const triggerCondition = object({
export const createAlertDefinitionSchema = object({
label: string().required('Name is required.'),
description: string().optional(),
severity: string().required('Severity is required.'),
entity_ids: array().of(string()).min(1, 'At least one resource is needed.'),
criteria: array()
.of(metricCriteria)
.min(1, 'At least one metric criteria is needed.'),
triggerCondition,
severity: number().oneOf([0, 1, 2, 3]).required('Severity is required.'),
entity_ids: array()
.of(string().required())
.min(1, 'At least one resource is needed.'),
rule_criteria: object({
rules: array()
.of(metricCriteria)
.min(1, 'At least one metric criteria is needed.'),
}),
trigger_condition,
channel_ids: array(number()),
});
14 changes: 7 additions & 7 deletions packages/validation/src/images.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ const labelSchema = string()
);

export const baseImageSchema = object({
label: labelSchema.notRequired(),
description: string().notRequired().min(1).max(65000),
cloud_init: boolean().notRequired(),
tags: array(string().min(3).max(50)).max(500).notRequired(),
label: labelSchema.optional(),
description: string().optional().min(1).max(65000),
cloud_init: boolean().optional(),
tags: array(string().min(3).max(50).required()).max(500).optional(),
});

export const createImageSchema = baseImageSchema.shape({
Expand All @@ -27,11 +27,11 @@ export const uploadImageSchema = baseImageSchema.shape({
});

export const updateImageSchema = object({
label: labelSchema.notRequired(),
label: labelSchema.optional(),
description: string()
.notRequired()
.optional()
.max(65000, 'Length must be 65000 characters or less.'),
tags: array(string()).notRequired(),
tags: array(string().required()).optional(),
});

export const updateImageRegionsSchema = object({
Expand Down
14 changes: 8 additions & 6 deletions packages/validation/src/kubernetes.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ export const createKubeClusterSchema = object().shape({
.min(1, 'Please add at least one node pool.'),
});

export const ipv4Address = string().test({
export const ipv4Address = string().defined().test({
name: 'validateIP',
message: 'Must be a valid IPv4 address.',
test: validateIP,
});

export const ipv6Address = string().test({
export const ipv6Address = string().defined().test({
name: 'validateIP',
message: 'Must be a valid IPv6 address.',
test: validateIP,
Expand All @@ -77,10 +77,12 @@ export const ipv6Address = string().test({
const controlPlaneACLOptionsSchema = object().shape({
enabled: boolean(),
'revision-id': string(),
addresses: object().shape({
ipv4: array().of(ipv4Address).nullable(),
ipv6: array().of(ipv6Address).nullable(),
}),
addresses: object()
.shape({
ipv4: array().of(ipv4Address).nullable(),
ipv6: array().of(ipv6Address).nullable(),
})
.notRequired(),
});

export const kubernetesControlPlaneACLPayloadSchema = object().shape({
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -949,10 +949,10 @@
dependencies:
levn "^0.4.1"

"@hookform/resolvers@2.9.11":
version "2.9.11"
resolved "https://registry.yarnpkg.com/@hookform/resolvers/-/resolvers-2.9.11.tgz#9ce96e7746625a89239f68ca57c4f654264c17ef"
integrity sha512-bA3aZ79UgcHj7tFV7RlgThzwSSHZgvfbt2wprldRkYBcMopdMvHyO17Wwp/twcJasNFischFfS7oz8Katz8DdQ==
"@hookform/resolvers@3.9.1":
version "3.9.1"
resolved "https://registry.yarnpkg.com/@hookform/resolvers/-/resolvers-3.9.1.tgz#a23883c40bfd449cb6c6ab5a0fa0729184c950ff"
integrity sha512-ud2HqmGBM0P0IABqoskKWI6PEf6ZDDBZkFqe2Vnl+mTHCEHzr3ISjjZyCwTjC/qpL25JC9aIDkloQejvMeq0ug==

"@humanwhocodes/config-array@^0.5.0":
version "0.5.0"
Expand Down
Loading