import React from 'react'; import type {SelectOption} from '@gravity-ui/uikit'; import {HelpMark, Select, TextInput} from '@gravity-ui/uikit'; import {Controller, useFormContext, useWatch} from 'react-hook-form'; import {cn} from '../../../../utils/cn'; import {FormRow, FormSection} from '../components/layout'; import i18n from '../i18n'; import type {FormMode, FormValues, TableType} from '../types'; const b = cn('ydb-table-form-dialog'); interface GeneralSectionProps { mode: FormMode; nameInputRef?: React.Ref; } const tableTypeInfo: Record = { row: i18n('label_info-table-type_row'), column: i18n('label_info-table-type_column'), }; export function GeneralSection({mode, nameInputRef}: GeneralSectionProps) { const {control, formState} = useFormContext(); const type = useWatch({control, name: 'type'}); const typeOptions = React.useMemo( () => [ {value: 'row', content: i18n('label_row-table')}, {value: 'column', content: i18n('label_column-table')}, ], [], ); const nameError = formState.errors.name?.message; const nameDisabled = mode === 'update' && type === 'column'; const typeDisabled = mode === 'update'; const tableTypeHelpText = mode === 'create' && type ? tableTypeInfo[type] : undefined; const nameHelpText = nameDisabled ? undefined : i18n('context_field-name'); return ( ( )} />
(