Skip to content

Commit 7cf936a

Browse files
Copilothotlong
andcommitted
refactor: hoist OBJECT_SAFE_TYPES constant outside render loop, use optional chaining
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent ebb6775 commit 7cf936a

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

packages/plugin-detail/src/HeaderHighlight.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import type { HighlightField, FieldMetadata } from '@object-ui/types';
1212
import { getCellRenderer } from '@object-ui/fields';
1313
import { useSafeFieldLabel } from '@object-ui/react';
1414

15+
/** Renderer types that natively handle object values without crashing */
16+
const OBJECT_SAFE_TYPES = ['lookup', 'master_detail', 'user', 'owner', 'file', 'image', 'object'];
17+
1518
export interface HeaderHighlightProps {
1619
fields: HighlightField[];
1720
data?: any;
@@ -74,10 +77,9 @@ export const HeaderHighlight: React.FC<HeaderHighlightProps> = ({
7477
// Types like lookup/user/owner/file/image handle objects natively.
7578
const isPlainObject = value !== null && typeof value === 'object'
7679
&& !Array.isArray(value) && !(value instanceof Date);
77-
const OBJECT_SAFE_TYPES = ['lookup', 'master_detail', 'user', 'owner', 'file', 'image', 'object'];
7880

7981
if (isPlainObject && !OBJECT_SAFE_TYPES.includes(resolvedType)) {
80-
displayValue = String(value.name || value.label || value._id || JSON.stringify(value));
82+
displayValue = String(value?.name || value?.label || value?._id || JSON.stringify(value));
8183
} else {
8284
displayValue = <CellRenderer value={value} field={enrichedField as unknown as FieldMetadata} />;
8385
}

0 commit comments

Comments
 (0)