fix: Handle missing select options and async relation view lookups

This commit is contained in:
Nathan
2025-10-31 08:06:17 +08:00
parent 716b725cfa
commit 9037a202cd
5 changed files with 18 additions and 8 deletions

View File

@@ -1294,13 +1294,14 @@ export const useSelectFieldOptions = (fieldId: string, searchValue?: string) =>
if (!typeOption) return [] as SelectOption[]; if (!typeOption) return [] as SelectOption[];
const normalizedOptions = typeOption.options.filter((option): option is SelectOption => { const normalizedOptions = typeOption.options.filter((option) => {
return Boolean(option && option.id && option.name); return Boolean(option && option.id);
}); });
return normalizedOptions.filter((option) => { return normalizedOptions.filter((option) => {
const optionName = typeof option.name === 'string' ? option.name : '';
if (!searchValue) return true; if (!searchValue) return true;
return option.name.toLowerCase().includes(searchValue.toLowerCase()); return optionName.toLowerCase().includes(searchValue.toLowerCase());
}); });
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [field, searchValue, clock]); }, [field, searchValue, clock]);

View File

@@ -46,6 +46,7 @@ export interface Database2Props {
paddingEnd?: number; paddingEnd?: number;
showActions?: boolean; showActions?: boolean;
createFolderView?: (payload: CreateFolderViewPayload) => Promise<string>; createFolderView?: (payload: CreateFolderViewPayload) => Promise<string>;
getViewIdFromDatabaseId?: (databaseId: string) => Promise<string | null>;
} }
function Database(props: Database2Props) { function Database(props: Database2Props) {

View File

@@ -60,16 +60,24 @@ function RelationItems({
}, [cell.data]); }, [cell.data]);
useEffect(() => { useEffect(() => {
if (!relatedDatabaseId) return; if (!relatedDatabaseId) {
setRelatedViewId(null);
return;
}
void (async () => { void (async () => {
try { try {
const viewId = await getViewIdFromDatabaseId?.(relatedDatabaseId); const viewId = await getViewIdFromDatabaseId?.(relatedDatabaseId);
if (!viewId) return; if (!viewId) {
setRelatedViewId(null);
return;
}
setRelatedViewId(viewId); setRelatedViewId(viewId);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
setRelatedViewId(null);
} }
})(); })();
}, [getViewIdFromDatabaseId, relatedDatabaseId]); }, [getViewIdFromDatabaseId, relatedDatabaseId]);

View File

@@ -48,8 +48,8 @@ export function SelectOptionList({
); );
if (!field || !typeOption) return null; if (!field || !typeOption) return null;
const normalizedOptions = typeOption.options.filter((option): option is SelectOption => { const normalizedOptions = typeOption.options.filter((option) => {
return Boolean(option && option.id && option.name); return Boolean(option && option.id);
}); });
return <div className={'flex flex-col'}>{normalizedOptions.map(renderOption)}</div>; return <div className={'flex flex-col'}>{normalizedOptions.map(renderOption)}</div>;

View File

@@ -32,7 +32,7 @@ export interface DatabaseProps {
viewMeta: ViewMetaProps; viewMeta: ViewMetaProps;
appendBreadcrumb?: AppendBreadcrumb; appendBreadcrumb?: AppendBreadcrumb;
onRendered?: () => void; onRendered?: () => void;
getViewIdFromDatabaseId?: (databaseId: string) => string | null; getViewIdFromDatabaseId?: (databaseId: string) => Promise<string | null>;
} }
function DatabaseView({ viewMeta, ...props }: DatabaseProps) { function DatabaseView({ viewMeta, ...props }: DatabaseProps) {