Skip to content

Commit 61a461f

Browse files
Copilothotlong
andcommitted
Fix code review issues: proper TypeScript types and Tailwind CSS classes
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 61d8446 commit 61a461f

3 files changed

Lines changed: 50 additions & 6 deletions

File tree

packages/plugin-object/src/ObjectGrid.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
*/
2020

2121
import React, { useState, useCallback, useRef, useEffect } from 'react';
22-
import type { ObjectTableSchema, TableColumn, DataSource, FieldMetadata } from '@object-ui/types';
22+
import type { ObjectGridSchema, TableColumn, DataSource, FieldMetadata } from '@object-ui/types';
2323
import { getCellRenderer } from './field-renderers';
2424

2525
export interface ObjectGridProps {
2626
/**
2727
* The schema configuration for the grid
2828
*/
29-
schema: ObjectTableSchema;
29+
schema: ObjectGridSchema;
3030

3131
/**
3232
* Data source for fetching data

packages/plugin-object/src/field-renderers.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,19 @@ export function SelectCellRenderer({ value, field }: CellRendererProps): React.R
173173

174174
if (!value) return <span>-</span>;
175175

176+
// Color mapping for Tailwind CSS (to avoid dynamic class names)
177+
const colorClasses: Record<string, { bg: string; text: string }> = {
178+
gray: { bg: 'bg-gray-100', text: 'text-gray-800' },
179+
red: { bg: 'bg-red-100', text: 'text-red-800' },
180+
orange: { bg: 'bg-orange-100', text: 'text-orange-800' },
181+
yellow: { bg: 'bg-yellow-100', text: 'text-yellow-800' },
182+
green: { bg: 'bg-green-100', text: 'text-green-800' },
183+
blue: { bg: 'bg-blue-100', text: 'text-blue-800' },
184+
indigo: { bg: 'bg-indigo-100', text: 'text-indigo-800' },
185+
purple: { bg: 'bg-purple-100', text: 'text-purple-800' },
186+
pink: { bg: 'bg-pink-100', text: 'text-pink-800' },
187+
};
188+
176189
// Handle multiple values
177190
if (Array.isArray(value)) {
178191
return (
@@ -181,11 +194,12 @@ export function SelectCellRenderer({ value, field }: CellRendererProps): React.R
181194
const option = options.find(opt => opt.value === val);
182195
const label = option?.label || val;
183196
const color = option?.color || 'gray';
197+
const classes = colorClasses[color] || colorClasses.gray;
184198

185199
return (
186200
<span
187201
key={idx}
188-
className={`inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-${color}-100 text-${color}-800`}
202+
className={`inline-flex items-center px-2 py-0.5 rounded text-xs font-medium ${classes.bg} ${classes.text}`}
189203
>
190204
{label}
191205
</span>
@@ -199,10 +213,11 @@ export function SelectCellRenderer({ value, field }: CellRendererProps): React.R
199213
const option = options.find(opt => opt.value === value);
200214
const label = option?.label || value;
201215
const color = option?.color || 'blue';
216+
const classes = colorClasses[color] || colorClasses.blue;
202217

203218
return (
204219
<span
205-
className={`inline-flex items-center px-2 py-1 rounded text-xs font-medium bg-${color}-100 text-${color}-800`}
220+
className={`inline-flex items-center px-2 py-1 rounded text-xs font-medium ${classes.bg} ${classes.text}`}
206221
>
207222
{label}
208223
</span>

packages/types/src/field-types.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,43 @@ export interface BaseFieldMetadata {
8787
/**
8888
* Conditional visibility expression
8989
*/
90-
visible_on?: any;
90+
visible_on?: VisibilityCondition;
9191

9292
/**
9393
* Custom validation function or rules
9494
*/
95-
validate?: any;
95+
validate?: ValidationFunction | ValidationRule;
9696
}
9797

98+
/**
99+
* Visibility condition type
100+
*/
101+
export type VisibilityCondition = {
102+
field: string;
103+
operator?: '=' | '!=' | '>' | '>=' | '<' | '<=' | 'in';
104+
value?: any;
105+
and?: VisibilityCondition[];
106+
or?: VisibilityCondition[];
107+
};
108+
109+
/**
110+
* Validation function type
111+
*/
112+
export type ValidationFunction = (value: any) => boolean | string | Promise<boolean | string>;
113+
114+
/**
115+
* Validation rule type
116+
*/
117+
export type ValidationRule = {
118+
required?: boolean | string;
119+
minLength?: number;
120+
maxLength?: number;
121+
min?: number;
122+
max?: number;
123+
pattern?: string | RegExp;
124+
custom?: ValidationFunction;
125+
};
126+
98127
/**
99128
* Text field metadata
100129
*/

0 commit comments

Comments
 (0)