fix(custom_types): fix display custom types in select box (#737)

This commit is contained in:
Guy Ben-Aharon
2025-06-05 15:21:55 +03:00
committed by GitHub
parent c6788b4917
commit 24be28a662
2 changed files with 47 additions and 30 deletions

View File

@@ -418,27 +418,22 @@ export const SelectBox = React.forwardRef<HTMLInputElement, SelectBoxProps>(
<ScrollArea>
<div className="max-h-64 w-full">
<CommandGroup>
<CommandList className="max-h-fit w-full">
{hasGroups
? Object.entries(groups).map(
([
groupName,
groupOptions,
]) => (
<CommandGroup
key={groupName}
heading={groupName}
>
{groupOptions.map(
renderOption
)}
</CommandGroup>
)
<CommandList className="max-h-fit w-full">
{hasGroups
? Object.entries(groups).map(
([groupName, groupOptions]) => (
<CommandGroup
key={groupName}
heading={groupName}
>
{groupOptions.map(
renderOption
)}
</CommandGroup>
)
: options.map(renderOption)}
</CommandList>
</CommandGroup>
)
: options.map(renderOption)}
</CommandList>
</div>
</ScrollArea>
</Command>

View File

@@ -1,4 +1,4 @@
import React, { useCallback } from 'react';
import React, { useCallback, useMemo } from 'react';
import { GripVertical, KeyRound } from 'lucide-react';
import { Input } from '@/components/input/input';
import type { DBField } from '@/lib/domain/db-field';
@@ -34,20 +34,42 @@ export const TableField: React.FC<TableFieldProps> = ({
updateField,
removeField,
}) => {
const { databaseType } = useChartDB();
const { databaseType, customTypes } = useChartDB();
const { t } = useTranslation();
const { attributes, listeners, setNodeRef, transform, transition } =
useSortable({ id: field.id });
const dataFieldOptions: SelectBoxOption[] = sortedDataTypeMap[
databaseType
].map((type) => ({
label: type.name,
value: type.id,
regex: type.hasCharMaxLength ? `^${type.name}\\(\\d+\\)$` : undefined,
extractRegex: type.hasCharMaxLength ? /\((\d+)\)/ : undefined,
}));
const dataFieldOptions = useMemo(() => {
const standardTypes: SelectBoxOption[] = sortedDataTypeMap[
databaseType
].map((type) => ({
label: type.name,
value: type.id,
regex: type.hasCharMaxLength
? `^${type.name}\\(\\d+\\)$`
: undefined,
extractRegex: type.hasCharMaxLength ? /\((\d+)\)/ : undefined,
group: customTypes?.length ? 'Standard Types' : undefined,
}));
if (!customTypes?.length) {
return standardTypes;
}
// Add custom types as options
const customTypeOptions: SelectBoxOption[] = customTypes.map(
(type) => ({
label: type.name,
value: type.name,
description:
type.kind === 'enum' ? `${type.values?.join(' | ')}` : '',
group: 'Custom Types',
})
);
return [...standardTypes, ...customTypeOptions];
}, [databaseType, customTypes]);
const onChangeDataType = useCallback<
NonNullable<SelectBoxProps['onChange']>