diff --git a/packages/web-console/src/components/TableSchemaDialog/actions.tsx b/packages/web-console/src/components/TableSchemaDialog/actions.tsx index cae8d0896..3e0ef2e3e 100644 --- a/packages/web-console/src/components/TableSchemaDialog/actions.tsx +++ b/packages/web-console/src/components/TableSchemaDialog/actions.tsx @@ -13,10 +13,12 @@ export const Actions = ({ action, ctaText, lastFocusedIndex, + onAdded, }: { action: Action ctaText: string lastFocusedIndex?: number + onAdded: (index: number) => void }) => { const newEntry = { name: "", @@ -63,17 +65,19 @@ export const Actions = ({ - insert( + onClick={() => { + const index = lastFocusedIndex !== undefined ? lastFocusedIndex - : watchSchemaColumns.length, - newEntry, - ) - } + : watchSchemaColumns.length + insert(index, newEntry) + onAdded(index) + }} > @@ -92,14 +96,14 @@ export const Actions = ({ diff --git a/packages/web-console/src/components/TableSchemaDialog/column.tsx b/packages/web-console/src/components/TableSchemaDialog/column.tsx index 24bda44b2..b6dff4340 100644 --- a/packages/web-console/src/components/TableSchemaDialog/column.tsx +++ b/packages/web-console/src/components/TableSchemaDialog/column.tsx @@ -62,6 +62,7 @@ export const Column = ({ onSetTimestamp, onFocus, timestamp, + lastFocusedIndex, }: { action: Action disabled: boolean @@ -70,6 +71,7 @@ export const Column = ({ onSetTimestamp: (name: string) => void onFocus: (index: number) => void timestamp: string + lastFocusedIndex?: number }) => { const [name, setName] = useState(column.name) @@ -99,6 +101,7 @@ export const Column = ({ name={`schemaColumns.${index}.name`} autoComplete="off" required + {...(lastFocusedIndex === index && { autoFocus: true })} /> diff --git a/packages/web-console/src/components/TableSchemaDialog/columns.tsx b/packages/web-console/src/components/TableSchemaDialog/columns.tsx index 8d9cca042..b20cad403 100644 --- a/packages/web-console/src/components/TableSchemaDialog/columns.tsx +++ b/packages/web-console/src/components/TableSchemaDialog/columns.tsx @@ -39,10 +39,12 @@ export const Columns = ({ action, isEditLocked, onColumnFocus, + lastFocusedIndex, }: { action: Action isEditLocked: boolean onColumnFocus: (index: number) => void + lastFocusedIndex?: number }) => { const { formState, getValues, setValue, watch } = useFormContext() @@ -60,6 +62,7 @@ export const Columns = ({ column={column} disabled={isEditLocked} index={index} + lastFocusedIndex={lastFocusedIndex} onFocus={onColumnFocus} onSetTimestamp={(name) => { setValue("timestamp", watchTimestamp === name ? "" : name) diff --git a/packages/web-console/src/components/TableSchemaDialog/dialog.tsx b/packages/web-console/src/components/TableSchemaDialog/dialog.tsx index 9817b3b5b..d84f43e2b 100644 --- a/packages/web-console/src/components/TableSchemaDialog/dialog.tsx +++ b/packages/web-console/src/components/TableSchemaDialog/dialog.tsx @@ -215,6 +215,7 @@ export const Dialog = ({ ctaText={ctaText} action={action} lastFocusedIndex={lastFocusedIndex} + onAdded={setLastFocusedIndex} /> } /> @@ -326,6 +327,7 @@ export const Dialog = ({ action={action} isEditLocked={isEditLocked} onColumnFocus={setLastFocusedIndex} + lastFocusedIndex={lastFocusedIndex} />