SqlFunctionSection.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { UseFormReturn } from 'react-hook-form'
  2. import { FormField, SheetSection } from 'ui'
  3. import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
  4. import { CreateCronJobForm } from './CreateCronJobSheet/CreateCronJobSheet.constants'
  5. import FunctionSelector from '@/components/ui/FunctionSelector'
  6. import SchemaSelector from '@/components/ui/SchemaSelector'
  7. interface SqlFunctionSectionProps {
  8. form: UseFormReturn<CreateCronJobForm>
  9. }
  10. export const SqlFunctionSection = ({ form }: SqlFunctionSectionProps) => {
  11. const schema = form.watch('values.schema')
  12. return (
  13. <SheetSection className="flex flex-col gap-3 2xl:flex-row 2xl:[&>div]:w-full">
  14. <FormField
  15. control={form.control}
  16. name="values.schema"
  17. render={({ field }) => (
  18. <FormItemLayout label="Schema" className="gap-1">
  19. <SchemaSelector
  20. size="small"
  21. className="w-56 2xl:w-full"
  22. selectedSchemaName={field.value}
  23. stopScrollPropagation
  24. onSelectSchema={(name) => {
  25. field.onChange(name)
  26. // deselect the selected function when the schema is changed
  27. form.resetField('values.functionName')
  28. }}
  29. />
  30. </FormItemLayout>
  31. )}
  32. />
  33. <FormField
  34. control={form.control}
  35. name="values.functionName"
  36. render={({ field }) => (
  37. <FormItemLayout label="Function name" className="gap-1">
  38. <FunctionSelector
  39. size="small"
  40. className="w-56 2xl:w-full"
  41. schema={schema}
  42. value={field.value}
  43. stopScrollPropagation
  44. onChange={(name) => field.onChange(name)}
  45. />
  46. </FormItemLayout>
  47. )}
  48. />
  49. </SheetSection>
  50. )
  51. }