Skip to content

Commit 2837cf7

Browse files
committed
refactor(plugin-detail): type the object-definition reads of the stage press
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibyyvCaZXvGAh38AKjD
1 parent bc74bc5 commit 2837cf7

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

‎ui/packages/plugin-detail/src/renderers/recordPathStageChange.tsx‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ export function stageRefusalLines(
9999
return [extractWriteErrorMessage(err) ?? t('detail.pathStageChangeFailed')];
100100
}
101101

102+
/** The members of an object definition's field entry this module reads. */
103+
type FieldDef = { type?: unknown; readonly?: unknown; label?: unknown };
104+
105+
const fieldDefOf = (objectSchema: unknown, field: string): FieldDef | undefined =>
106+
(objectSchema as { fields?: Record<string, FieldDef | undefined> } | null | undefined)?.fields?.[field];
107+
102108
const canUpdate = (ds: unknown): boolean => {
103109
const d = ds as Record<string, unknown> | null | undefined;
104110
return typeof d?.update === 'function' || typeof d?.updateOne === 'function' || typeof d?.patch === 'function';
@@ -131,7 +137,7 @@ export function useStageChange(allowStageChange: boolean, statusField: string |
131137
const objectName = ctx?.objectName;
132138
const recordId = ctx?.recordId;
133139
const dataSource = ctx?.dataSource;
134-
const fieldDef = statusField ? (ctx?.objectSchema as any)?.fields?.[statusField] : undefined;
140+
const fieldDef = statusField ? fieldDefOf(ctx?.objectSchema, statusField) : undefined;
135141
const pressable =
136142
allowStageChange
137143
&& !!statusField
@@ -152,8 +158,8 @@ export function useStageChange(allowStageChange: boolean, statusField: string |
152158
}, []);
153159

154160
const labelOf = (field: string): string => {
155-
const declared = (ctx?.objectSchema as any)?.fields?.[field]?.label;
156-
const fallback = declared == null ? field : String(pickLocalized(declared, language) ?? field);
161+
const declared = fieldDefOf(ctx?.objectSchema, field)?.label;
162+
const fallback = declared == null ? field : String(pickLocalized(declared as Parameters<typeof pickLocalized>[0], language) ?? field);
157163
return objectName ? fieldLabel(objectName, field, fallback) : fallback;
158164
};
159165

0 commit comments

Comments
 (0)