mirror of
https://github.com/AppFlowy-IO/AppFlowy-Web.git
synced 2025-11-29 19:08:33 +08:00
fix: Handle missing select options and async relation view lookups
This commit is contained in:
@@ -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]);
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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]);
|
||||||
|
|||||||
@@ -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>;
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user