Skip to content

Commit 09c48e6

Browse files
fix: address code review type safety feedback - replace any with typed interfaces
- Define ObjectWidgetSchema and ObjectFieldDesignerSchema interfaces - Define ObjectWidgetNode for schema factory body nodes - Replace (schema as any).objectName with typed schema access - Replace node: any with SchemaNode in detail content renderers Agent-Logs-Url: https://github.com/objectstack-ai/objectui/sessions/0c570236-7df3-4c11-b21b-0a9ee3d5968a Co-authored-by: xuyushun441-sys <255036401+xuyushun441-sys@users.noreply.github.com>
1 parent b8fbd7a commit 09c48e6

File tree

5 files changed

+47
-26
lines changed

5 files changed

+47
-26
lines changed

apps/console/src/components/schema/ObjectFieldDesignerWidget.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ import { useMetadataService } from '../../hooks/useMetadataService';
2121
import { MetadataService } from '../../services/MetadataService';
2222
import { toFieldDefinition, type MetadataObject } from '../../utils/metadataConverters';
2323

24-
export function ObjectFieldDesignerWidget({ schema }: { schema: SchemaNode }) {
25-
const objectName = (schema as any).objectName as string;
24+
/** Schema props for the field designer widget. */
25+
interface ObjectFieldDesignerSchema extends SchemaNode {
26+
objectName: string;
27+
}
28+
29+
export function ObjectFieldDesignerWidget({ schema }: { schema: ObjectFieldDesignerSchema }) {
30+
const objectName = schema.objectName;
2631
const { objects: metadataObjects, refresh } = useMetadata();
2732
const metadataService = useMetadataService();
2833

apps/console/src/components/schema/objectDetailWidgets.tsx

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ import type { SchemaNode } from '@object-ui/core';
2626
import { useMetadata } from '../../context/MetadataProvider';
2727
import { toObjectDefinition, toFieldDefinition, type MetadataObject } from '../../utils/metadataConverters';
2828

29+
// ---------------------------------------------------------------------------
30+
// Widget schema interface
31+
// ---------------------------------------------------------------------------
32+
33+
/** Schema props for object detail widgets. All widgets receive `objectName`. */
34+
interface ObjectWidgetSchema extends SchemaNode {
35+
objectName: string;
36+
}
37+
2938
// ---------------------------------------------------------------------------
3039
// Shared hook: resolve object definition + fields from metadata context
3140
// ---------------------------------------------------------------------------
@@ -59,8 +68,8 @@ function useObjectData(objectName: string) {
5968
// Schema: { type: 'object-properties', objectName: 'account' }
6069
// ---------------------------------------------------------------------------
6170

62-
export function ObjectPropertiesWidget({ schema }: { schema: SchemaNode }) {
63-
const objectName = (schema as any).objectName as string;
71+
export function ObjectPropertiesWidget({ schema }: { schema: ObjectWidgetSchema }) {
72+
const objectName = schema.objectName;
6473
const { object, fields } = useObjectData(objectName);
6574

6675
if (!object) return null;
@@ -122,8 +131,8 @@ export function ObjectPropertiesWidget({ schema }: { schema: SchemaNode }) {
122131
// Schema: { type: 'object-relationships', objectName: 'account' }
123132
// ---------------------------------------------------------------------------
124133

125-
export function ObjectRelationshipsWidget({ schema }: { schema: SchemaNode }) {
126-
const objectName = (schema as any).objectName as string;
134+
export function ObjectRelationshipsWidget({ schema }: { schema: ObjectWidgetSchema }) {
135+
const objectName = schema.objectName;
127136
const { object } = useObjectData(objectName);
128137

129138
if (!object) return null;
@@ -165,8 +174,8 @@ export function ObjectRelationshipsWidget({ schema }: { schema: SchemaNode }) {
165174
// Schema: { type: 'object-keys', objectName: 'account' }
166175
// ---------------------------------------------------------------------------
167176

168-
export function ObjectKeysWidget({ schema }: { schema: SchemaNode }) {
169-
const objectName = (schema as any).objectName as string;
177+
export function ObjectKeysWidget({ schema }: { schema: ObjectWidgetSchema }) {
178+
const objectName = schema.objectName;
170179
const { fields } = useObjectData(objectName);
171180

172181
const keyFields = useMemo(
@@ -206,7 +215,7 @@ export function ObjectKeysWidget({ schema }: { schema: SchemaNode }) {
206215
// Schema: { type: 'object-data-experience', objectName: 'account' }
207216
// ---------------------------------------------------------------------------
208217

209-
export function ObjectDataExperienceWidget(_props: { schema: SchemaNode }) {
218+
export function ObjectDataExperienceWidget(_props: { schema: ObjectWidgetSchema }) {
210219
return (
211220
<div className="rounded-lg border bg-card p-4 sm:p-6 space-y-4" data-testid="data-experience-section">
212221
<h2 className="text-sm font-semibold flex items-center gap-2">
@@ -239,8 +248,8 @@ export function ObjectDataExperienceWidget(_props: { schema: SchemaNode }) {
239248
// Schema: { type: 'object-data-preview', objectName: 'account' }
240249
// ---------------------------------------------------------------------------
241250

242-
export function ObjectDataPreviewWidget({ schema }: { schema: SchemaNode }) {
243-
const objectName = (schema as any).objectName as string;
251+
export function ObjectDataPreviewWidget({ schema }: { schema: ObjectWidgetSchema }) {
252+
const objectName = schema.objectName;
244253
const { object } = useObjectData(objectName);
245254

246255
return (

apps/console/src/pages/system/MetadataDetailPage.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import { useMetadata } from '../../context/MetadataProvider';
4242
import { getMetadataTypeConfig, DEFAULT_FORM_FIELDS, type MetadataTypeConfig } from '../../config/metadataTypeRegistry';
4343
import { MetadataFormDialog } from '../../components/MetadataFormDialog';
4444
import { getIcon } from '../../utils/getIcon';
45-
import type { PageSchema } from '@object-ui/types';
45+
import type { PageSchema, SchemaNode, BaseSchema } from '@object-ui/types';
4646

4747
// ---------------------------------------------------------------------------
4848
// Schema rendering error boundary (class component for React error boundary)
@@ -105,8 +105,8 @@ function SchemaDetailContent({ schema }: { schema: PageSchema }) {
105105

106106
return (
107107
<div className="flex flex-col gap-6" data-testid="schema-detail-content">
108-
{bodyNodes.map((node: any, idx: number) => (
109-
<SchemaRenderer key={node?.id || idx} schema={node} />
108+
{bodyNodes.map((node: SchemaNode, idx: number) => (
109+
<SchemaRenderer key={(node as BaseSchema)?.id || idx} schema={node} />
110110
))}
111111
</div>
112112
);

apps/console/src/pages/system/ObjectManagerPage.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
} from 'lucide-react';
2727
import { ObjectManager } from '@object-ui/plugin-designer';
2828
import { SchemaRenderer } from '@object-ui/react';
29-
import type { ObjectDefinition } from '@object-ui/types';
29+
import type { ObjectDefinition, SchemaNode, BaseSchema } from '@object-ui/types';
3030
import { toast } from 'sonner';
3131
import { useMetadata } from '../../context/MetadataProvider';
3232
import { useMetadataService } from '../../hooks/useMetadataService';
@@ -101,8 +101,8 @@ function ObjectSchemaDetailContent({ objectName, metadataObject }: {
101101

102102
return (
103103
<div className="flex flex-col gap-6" data-testid="schema-detail-content">
104-
{bodyNodes.map((node: any, idx: number) => (
105-
<SchemaRenderer key={node?.id || idx} schema={node} />
104+
{bodyNodes.map((node: SchemaNode, idx: number) => (
105+
<SchemaRenderer key={(node as BaseSchema)?.id || idx} schema={node} />
106106
))}
107107
</div>
108108
);

apps/console/src/schemas/objectDetailPageSchema.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
* @module schemas/objectDetailPageSchema
1414
*/
1515

16-
import type { PageSchema } from '@object-ui/types';
16+
import type { PageSchema, BaseSchema } from '@object-ui/types';
17+
18+
/** Widget schema node with `objectName` property. */
19+
interface ObjectWidgetNode extends BaseSchema {
20+
objectName: string;
21+
}
1722

1823
/**
1924
* Build a PageSchema for an object detail page.
@@ -29,6 +34,15 @@ export function buildObjectDetailPageSchema(
2934
const label = (item?.label as string) || objectName;
3035
const description = (item?.description as string) || objectName;
3136

37+
const widgets: ObjectWidgetNode[] = [
38+
{ type: 'object-properties', id: `${objectName}-properties`, objectName },
39+
{ type: 'object-relationships', id: `${objectName}-relationships`, objectName },
40+
{ type: 'object-keys', id: `${objectName}-keys`, objectName },
41+
{ type: 'object-data-experience', id: `${objectName}-data-experience`, objectName },
42+
{ type: 'object-data-preview', id: `${objectName}-data-preview`, objectName },
43+
{ type: 'object-field-designer', id: `${objectName}-field-designer`, objectName },
44+
];
45+
3246
return {
3347
type: 'page',
3448
name: `object-detail-${objectName}`,
@@ -37,13 +51,6 @@ export function buildObjectDetailPageSchema(
3751
icon: 'database',
3852
pageType: 'record_detail',
3953
object: objectName,
40-
body: [
41-
{ type: 'object-properties', id: `${objectName}-properties`, objectName } as any,
42-
{ type: 'object-relationships', id: `${objectName}-relationships`, objectName } as any,
43-
{ type: 'object-keys', id: `${objectName}-keys`, objectName } as any,
44-
{ type: 'object-data-experience', id: `${objectName}-data-experience`, objectName } as any,
45-
{ type: 'object-data-preview', id: `${objectName}-data-preview`, objectName } as any,
46-
{ type: 'object-field-designer', id: `${objectName}-field-designer`, objectName } as any,
47-
],
54+
body: widgets,
4855
};
4956
}

0 commit comments

Comments
 (0)