Compare commits

...
Author SHA1 Message Date
Sonarly Claude CodeandClaude Opus 4.6 8a82f93d29 fix: gracefully handle missing field metadata in EditableSortChip
When a sort references a field metadata ID that no longer exists (e.g.,
deleted custom field), EditableSortChip crashed the page by using
useFieldMetadataItemByIdOrThrow. Switch to the non-throwing
useFieldMetadataItemById and return null when the field is not found,
preventing the unhandled error on /objects/opportunities.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 21:50:52 +00:00
@@ -1,9 +1,10 @@
import { useFieldMetadataItemByIdOrThrow } from '@/object-metadata/hooks/useFieldMetadataItemByIdOrThrow';
import { useFieldMetadataItemById } from '@/object-metadata/hooks/useFieldMetadataItemById';
import { useRemoveRecordSort } from '@/object-record/record-sort/hooks/useRemoveRecordSort';
import { useUpsertRecordSort } from '@/object-record/record-sort/hooks/useUpsertRecordSort';
import { type RecordSort } from '@/object-record/record-sort/types/RecordSort';
import { SortOrFilterChip } from '@/views/components/SortOrFilterChip';
import { IconArrowDown, IconArrowUp } from 'twenty-ui/display';
import { isDefined } from 'twenty-shared/utils';
import { ViewSortDirection } from '~/generated-metadata/graphql';
type EditableSortChipProps = {
@@ -19,10 +20,14 @@ export const EditableSortChip = ({ recordSort }: EditableSortChipProps) => {
removeRecordSort(recordSort.fieldMetadataId);
};
const { fieldMetadataItem } = useFieldMetadataItemByIdOrThrow(
const { fieldMetadataItem } = useFieldMetadataItemById(
recordSort.fieldMetadataId,
);
if (!isDefined(fieldMetadataItem)) {
return null;
}
const handleClick = () => {
const newSort: RecordSort = {
...recordSort,