diff --git a/apps/studio/components/interfaces/Database/Wrappers/WrapperDynamicColumns.tsx b/apps/studio/components/interfaces/Database/Wrappers/WrapperDynamicColumns.tsx index 0afed348d5..6c9f5cdebc 100644 --- a/apps/studio/components/interfaces/Database/Wrappers/WrapperDynamicColumns.tsx +++ b/apps/studio/components/interfaces/Database/Wrappers/WrapperDynamicColumns.tsx @@ -131,7 +131,6 @@ const WrapperDynamicColumns = ({ value={column.type} enumTypes={[]} onOptionSelect={(value) => onUpdateValue(column.id, 'type', value)} - layout="vertical" className="[&_label]:!p-0" /> diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx index 200a6c2be9..cce27c4d0e 100644 --- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx +++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx @@ -264,7 +264,6 @@ const ColumnEditor = ({ )} - type.name)) const isAvailableType = value ? availableTypes.includes(value) : true const recommendation = RECOMMENDED_ALTERNATIVE_DATA_TYPE[value] + const [open, setOpen] = useState(false) + console.log({ availableTypes }) + + const getOptionByName = (name: string) => { + // handle built in types + const pgOption = POSTGRES_DATA_TYPE_OPTIONS.find((option) => option.name === name) + if (pgOption) return pgOption + + // handle custom enums + const enumType = enumTypes.find((type) => type.name === name) + return enumType ? { ...enumType, type: 'enum' } : undefined + } const inferIcon = (type: string) => { switch (type) { case 'number': - return + return case 'time': - return + return case 'text': - return + return case 'json': return (
{'{ }'}
) + case 'jsonb': + return ( +
+ {'{ }'} +
+ ) case 'bool': - return + return default: - return + return } } @@ -119,7 +160,6 @@ const ColumnType = ({ layout={showLabel ? 'horizontal' : undefined} className="md:gap-x-0" size="small" - icon={inferIcon(POSTGRES_DATA_TYPE_OPTIONS.find((x) => x.name === value)?.type ?? '')} value={value} /> @@ -143,105 +183,126 @@ const ColumnType = ({ } return ( -
- onOptionSelect(value)} - optionsWidth={480} - > - - --- - - - {/* - Weird issue with Listbox here - 1. Can't do render conditionally (&&) within Listbox hence why using Fragment - 2. Can't wrap these 2 components within a Fragment conditional (enumTypes.length) - as selecting the enumType option will not render it in the Listbox component - */} - {enumTypes.length > 0 ? ( - - Other Data Types - - ) : ( - <> - )} - - {enumTypes.length > 0 ? ( - // @ts-ignore - enumTypes.map((enumType: PostgresType) => ( - { - return - }} - > -
-

{enumType.name}

- {enumType.comment !== undefined && ( -

{enumType.comment}

- )} -
-
- )) - ) : ( - <> - )} - - - PostgreSQL Data Types - - - {POSTGRES_DATA_TYPE_OPTIONS.map((option: PostgresDataTypeOption) => ( - inferIcon(option.type)} +
+ + + + + + + + + Type not found. + + + + {POSTGRES_DATA_TYPE_OPTIONS.map((option: PostgresDataTypeOption) => ( + { + onOptionSelect(value) + setOpen(false) + }} + > +
+ {inferIcon(option.type)} + {option.name} + {option.description} +
+ + {option.name === value ? ( + + ) : ( + '' + )} + +
+ ))} +
+ {enumTypes.length > 0 && ( + <> + Other types + + {enumTypes.map((option: any) => ( + { + onOptionSelect(value) + setOpen(false) + }} + > +
+
+ +
+ {option.name} + {option.comment !== undefined && ( + + {option.comment} + + )} + + {option.name === value ? : ''} + +
+
+ ))} +
+ + )} +
+
+
+
+
+ {showRecommendation && recommendation !== undefined && ( - - It is recommended to use {recommendation.alternative}{' '} - instead - - } - > -

- Postgres recommends against using the data type {value}{' '} - unless you have a very specific use case. -

-
- - -
-
+ + + + {' '} + It is recommended to use + {recommendation.alternative} + {' '} + insteadn + + +

+ Postgres recommends against using the data type{' '} + {value} unless you have a very specific use case. +

+
+ + +
+
+
)}
) diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/Column.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/Column.tsx index 732550d400..9328642dc5 100644 --- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/Column.tsx +++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/Column.tsx @@ -226,7 +226,6 @@ const Column = ({ { await page.getByRole('button', { name: 'Add column' }).click() await page.getByRole('textbox', { name: 'column_name' }).click() await page.getByRole('textbox', { name: 'column_name' }).fill('defaultValueColumn') - await page.getByRole('button', { name: '---' }).click() + await page.locator('button').filter({ hasText: 'Choose a column type...' }).click() await page.getByText('Signed two-byte integer').click() await page.getByTestId('defaultValueColumn-default-value').click() await page.getByTestId('defaultValueColumn-default-value').fill('2')