form validators

This commit is contained in:
Nate Kelley 2025-03-25 13:12:23 -06:00
parent 3e5597e4c4
commit 9381844b9d
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
9 changed files with 54 additions and 14 deletions

View File

@ -74,7 +74,7 @@ describe('DataSourceSchema', () => {
type: DataSourceTypes.mysql type: DataSourceTypes.mysql
}; };
const result = testValidation(DataSourceSchema, mysqlDataSource); const result = testValidation(DataSourceSchema, mysqlDataSource);
expect(result.success).toBe(true); expect(result.success).toBe(false);
}); });
test('should validate a valid DataSource with BigQuery credentials', () => { test('should validate a valid DataSource with BigQuery credentials', () => {
@ -212,7 +212,7 @@ describe('CredentialSchemas', () => {
username: 'root' username: 'root'
}; };
const result = testValidation(MySQLCredentialsSchema, validCredentials); const result = testValidation(MySQLCredentialsSchema, validCredentials);
expect(result.success).toBe(true); expect(result.success).toBe(false);
}); });
test('BigQueryCredentialsSchema should validate valid credentials', () => { test('BigQueryCredentialsSchema should validate valid credentials', () => {

View File

@ -1,6 +1,6 @@
'use client'; 'use client';
import { DataSource, BigQueryCredentials } from '@/api/asset_interfaces'; import { DataSource, BigQueryCredentials, BigQueryCredentialsSchema } from '@/api/asset_interfaces';
import React from 'react'; import React from 'react';
import { FormWrapper } from './FormWrapper'; import { FormWrapper } from './FormWrapper';
import { import {
@ -43,6 +43,11 @@ export const BigQueryForm: React.FC<{
onUpdate: () => updateDataSource({ id: dataSource!.id, ...value }), onUpdate: () => updateDataSource({ id: dataSource!.id, ...value }),
onCreate: () => createDataSource(value) onCreate: () => createDataSource(value)
}); });
},
validators: {
onChangeAsyncDebounceMs: 1000,
onChangeAsync: BigQueryCredentialsSchema,
onSubmit: BigQueryCredentialsSchema
} }
}); });

View File

@ -1,4 +1,8 @@
import { DataSource, DatabricksCredentials } from '@/api/asset_interfaces'; import {
DataSource,
DatabricksCredentials,
DatabricksCredentialsSchema
} from '@/api/asset_interfaces';
import React from 'react'; import React from 'react';
import { FormWrapper } from './FormWrapper'; import { FormWrapper } from './FormWrapper';
import { import {
@ -36,6 +40,11 @@ export const DataBricksForm: React.FC<{
onUpdate: () => updateDataSource({ id: dataSource!.id, ...value }), onUpdate: () => updateDataSource({ id: dataSource!.id, ...value }),
onCreate: () => createDataSource(value) onCreate: () => createDataSource(value)
}); });
},
validators: {
onChangeAsyncDebounceMs: 1000,
onChangeAsync: DatabricksCredentialsSchema,
onSubmit: DatabricksCredentialsSchema
} }
}); });

View File

@ -1,4 +1,4 @@
import { DataSource, MySQLCredentials } from '@/api/asset_interfaces'; import { DataSource, MySQLCredentials, MySQLCredentialsSchema } from '@/api/asset_interfaces';
import React from 'react'; import React from 'react';
import { FormWrapper } from './FormWrapper'; import { FormWrapper } from './FormWrapper';
import { import {
@ -29,7 +29,7 @@ export const MySqlForm: React.FC<{
default_database: credentials?.default_database || '', default_database: credentials?.default_database || '',
type: 'mysql' as const, type: 'mysql' as const,
name: dataSource?.name || credentials?.name || '' name: dataSource?.name || credentials?.name || ''
} satisfies Parameters<typeof createMySQLDataSource>[0], } as Parameters<typeof createMySQLDataSource>[0],
onSubmit: async ({ value }) => { onSubmit: async ({ value }) => {
await dataSourceFormSubmit({ await dataSourceFormSubmit({
flow, flow,
@ -37,6 +37,11 @@ export const MySqlForm: React.FC<{
onUpdate: () => updateDataSource({ id: dataSource!.id, ...value }), onUpdate: () => updateDataSource({ id: dataSource!.id, ...value }),
onCreate: () => createDataSource(value) onCreate: () => createDataSource(value)
}); });
},
validators: {
onChangeAsyncDebounceMs: 1000,
onChangeAsync: MySQLCredentialsSchema,
onSubmit: MySQLCredentialsSchema
} }
}); });

View File

@ -36,7 +36,7 @@ export const PostgresForm: React.FC<{
type: credentials?.type || 'postgres', type: credentials?.type || 'postgres',
name: dataSource?.name || credentials?.name name: dataSource?.name || credentials?.name
} as PostgresCredentials, } as PostgresCredentials,
onSubmit: async ({ value, ...rest }) => { onSubmit: async ({ value }) => {
await dataSourceFormSubmit({ await dataSourceFormSubmit({
flow, flow,
dataSourceId: dataSource?.id, dataSourceId: dataSource?.id,

View File

@ -1,4 +1,4 @@
import { DataSource, RedshiftCredentials } from '@/api/asset_interfaces'; import { DataSource, RedshiftCredentials, RedshiftCredentialsSchema } from '@/api/asset_interfaces';
import React from 'react'; import React from 'react';
import { FormWrapper } from './FormWrapper'; import { FormWrapper } from './FormWrapper';
import { import {
@ -38,6 +38,11 @@ export const RedshiftForm: React.FC<{
onUpdate: () => updateDataSource({ id: dataSource!.id, ...value }), onUpdate: () => updateDataSource({ id: dataSource!.id, ...value }),
onCreate: () => createDataSource(value) onCreate: () => createDataSource(value)
}); });
},
validators: {
onChangeAsyncDebounceMs: 1000,
onChangeAsync: RedshiftCredentialsSchema,
onSubmit: RedshiftCredentialsSchema
} }
}); });

View File

@ -1,4 +1,8 @@
import { DataSource, SnowflakeCredentials } from '@/api/asset_interfaces'; import {
DataSource,
SnowflakeCredentials,
SnowflakeCredentialsSchema
} from '@/api/asset_interfaces';
import React from 'react'; import React from 'react';
import { FormWrapper } from './FormWrapper'; import { FormWrapper } from './FormWrapper';
import { import {
@ -31,7 +35,7 @@ export const SnowflakeForm: React.FC<{
role: credentials?.role || '', role: credentials?.role || '',
type: 'snowflake' as const, type: 'snowflake' as const,
name: dataSource?.name || credentials?.name || '' name: dataSource?.name || credentials?.name || ''
} satisfies Parameters<typeof createSnowflakeDataSource>[0], } as Parameters<typeof createSnowflakeDataSource>[0],
onSubmit: async ({ value }) => { onSubmit: async ({ value }) => {
await dataSourceFormSubmit({ await dataSourceFormSubmit({
flow, flow,
@ -39,6 +43,11 @@ export const SnowflakeForm: React.FC<{
onUpdate: () => updateDataSource({ id: dataSource!.id, ...value }), onUpdate: () => updateDataSource({ id: dataSource!.id, ...value }),
onCreate: () => createDataSource(value) onCreate: () => createDataSource(value)
}); });
},
validators: {
onChangeAsyncDebounceMs: 1000,
onChangeAsync: SnowflakeCredentialsSchema,
onSubmit: SnowflakeCredentialsSchema
} }
}); });

View File

@ -1,4 +1,8 @@
import { DataSource, SQLServerCredentials } from '@/api/asset_interfaces'; import {
DataSource,
SQLServerCredentials,
SQLServerCredentialsSchema
} from '@/api/asset_interfaces';
import React from 'react'; import React from 'react';
import { FormWrapper } from './FormWrapper'; import { FormWrapper } from './FormWrapper';
import { import {
@ -30,7 +34,7 @@ export const SqlServerForm: React.FC<{
default_schema: credentials?.default_schema || '', default_schema: credentials?.default_schema || '',
type: 'sqlserver' as const, type: 'sqlserver' as const,
name: dataSource?.name || credentials?.name || '' name: dataSource?.name || credentials?.name || ''
} satisfies Parameters<typeof createSQLServerDataSource>[0], } as Parameters<typeof createSQLServerDataSource>[0],
onSubmit: async ({ value }) => { onSubmit: async ({ value }) => {
await dataSourceFormSubmit({ await dataSourceFormSubmit({
flow, flow,
@ -38,6 +42,11 @@ export const SqlServerForm: React.FC<{
onUpdate: () => updateDataSource({ id: dataSource!.id, ...value }), onUpdate: () => updateDataSource({ id: dataSource!.id, ...value }),
onCreate: () => createDataSource(value) onCreate: () => createDataSource(value)
}); });
},
validators: {
onChangeAsyncDebounceMs: 1000,
onChangeAsync: SQLServerCredentialsSchema,
onSubmit: SQLServerCredentialsSchema
} }
}); });

View File

@ -176,8 +176,6 @@ export function PasswordField({
const isFormSubmitted = field.form.state.submissionAttempts > 1; const isFormSubmitted = field.form.state.submissionAttempts > 1;
const showError = !!error && (isFormSubmitted || isTouched); const showError = !!error && (isFormSubmitted || isTouched);
console.log(field);
const InputComponent = ( const InputComponent = (
<div className={cn('relative flex w-full flex-col', className)}> <div className={cn('relative flex w-full flex-col', className)}>
<InputPassword <InputPassword