From 4ba97f2e4105c41f797e79d45beec8310bb83777 Mon Sep 17 00:00:00 2001 From: Maksim Chervonnyi Date: Tue, 1 Oct 2024 16:15:03 +0200 Subject: [PATCH] minor improvements --- .../containers/Admin/Buckets/Tabulator.tsx | 68 +++++++++++-------- 1 file changed, 40 insertions(+), 28 deletions(-) diff --git a/catalog/app/containers/Admin/Buckets/Tabulator.tsx b/catalog/app/containers/Admin/Buckets/Tabulator.tsx index f39ca724e97..42ee02b6483 100644 --- a/catalog/app/containers/Admin/Buckets/Tabulator.tsx +++ b/catalog/app/containers/Admin/Buckets/Tabulator.tsx @@ -27,6 +27,39 @@ import RENAME_TABULATOR_TABLE_MUTATION from './gql/TabulatorTablesRename.generat const TextEditor = React.lazy(() => import('components/FileEditor/TextEditor')) +function anyIn(obj: FF.ValidationErrors, keys: string[]) { + if (!obj) return false + const entries = Object.entries(obj) + if (!entries.length) return false + return entries.find(([key, value]) => keys.includes(key) && !!value) +} + +interface InlineErrorProps { + keys: string[] + errors?: Record +} + +function InlineError({ keys, errors: errorsDict = {} }: InlineErrorProps) { + const state = RF.useFormState() + const error = React.useMemo( + () => + state.error || + state.submitError || + anyIn(state.errors, keys) || + anyIn(state.submitErrors, keys), + [keys, state], + ) + return ( + + ) +} + const isEmpty = (obj: Record) => { const values = Object.values(obj) if (values.length === 0) return true @@ -165,7 +198,7 @@ function AddTable({ disabled, onCancel, onSubmit }: AddTableProps) { margin="normal" name="name" size="small" - validate={validators.required as FF.FieldValidator} + validate={validators.required as FF.FieldValidator} variant="outlined" /> , + validators.required as FF.FieldValidator, validateYaml, validateTable, )} @@ -303,7 +336,7 @@ function TabulatorRow({ {editName && isEmpty(deleteError) ? ( - {({ handleSubmit, error, submitError, errors, submitErrors }) => ( + {({ handleSubmit }) => (
- } + helperText={} disabled={disabled} /> onSubmit({ ...tabulatorTable, ...values })} > - {({ - handleSubmit, - error, - errors, - submitErrors, - submitError, - submitFailed, - }) => ( + {({ handleSubmit, submitFailed }) => ( , + validators.required as FF.FieldValidator, validateYaml, validateTable, )} disabled={disabled} />
- {submitFailed && ( - - )} + {submitFailed && }