Skip to content

Commit 3ac0983

Browse files
authored
Merge pull request #315 from objectstack-ai/copilot/fix-step-8-error
2 parents cc2bf68 + 4fc895e commit 3ac0983

24 files changed

Lines changed: 87 additions & 25 deletions

apps/console/vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default defineConfig({
5353
test: {
5454
globals: true,
5555
environment: 'happy-dom',
56-
setupFiles: ['./vitest.setup.ts'],
56+
setupFiles: ['./vitest.setup.tsx'],
5757
server: {
5858
deps: {
5959
inline: [/@objectstack/]

apps/console/vitest.setup.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

apps/console/vitest.setup.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import '@testing-library/jest-dom';
2+
import React from 'react';
3+
import '@object-ui/fields'; // Import fields first
4+
import '@object-ui/plugin-dashboard'; // Import to register dashboard components
5+
import '@object-ui/plugin-grid'; // Import to register grid components
6+
import '@object-ui/components'; // Imports @object-ui/components for types
7+
8+
// Manually re-register basic text component to override field widget
9+
// This is necessary because @object-ui/fields has @object-ui/components as a dependency,
10+
// so components gets loaded BEFORE fields registers its widgets, causing fields to overwrite.
11+
import { ComponentRegistry } from '@object-ui/core';
12+
import type { TextSchema } from '@object-ui/types';
13+
14+
ComponentRegistry.register('text',
15+
({ schema, ...props }: { schema: TextSchema; [key: string]: any }) => {
16+
const {
17+
'data-obj-id': dataObjId,
18+
'data-obj-type': dataObjType,
19+
style,
20+
...rest
21+
} = props;
22+
23+
if (dataObjId || schema.className || rest.className) {
24+
return (
25+
<span
26+
data-obj-id={dataObjId}
27+
data-obj-type={dataObjType}
28+
style={style}
29+
className={schema.className || rest.className}
30+
{...rest}
31+
>
32+
{schema.content || schema.value}
33+
</span>
34+
);
35+
}
36+
37+
return <>{schema.content || schema.value}</>;
38+
},
39+
{
40+
namespace: 'ui',
41+
label: 'Text',
42+
}
43+
);

packages/fields/src/widgets/BooleanField.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ export function BooleanField({ value, onChange, field, readonly, ...props }: Fie
1717
return (
1818
<div className="flex items-center space-x-2">
1919
<Checkbox
20+
{...props}
2021
id={id}
2122
checked={!!value}
2223
onCheckedChange={(checked) => onChange(!!checked)}
2324
disabled={readonly}
24-
className={props.className}
2525
/>
2626
<Label htmlFor={id}>{label}</Label>
2727
</div>
@@ -31,11 +31,11 @@ export function BooleanField({ value, onChange, field, readonly, ...props }: Fie
3131
return (
3232
<div className="flex items-center space-x-2">
3333
<Switch
34+
{...props}
3435
id={id}
3536
checked={!!value}
3637
onCheckedChange={onChange}
3738
disabled={readonly}
38-
className={props.className}
3939
/>
4040
<Label htmlFor={id}>{label}</Label>
4141
</div>

packages/fields/src/widgets/CurrencyField.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function formatCurrency(value: number, currency: string = 'USD'): string {
1616
}
1717
}
1818

19-
export function CurrencyField({ value, onChange, field, readonly, errorMessage, ...props }: FieldWidgetProps<number>) {
19+
export function CurrencyField({ value, onChange, field, readonly, errorMessage, className, ...props }: FieldWidgetProps<number>) {
2020
const currencyField = (field || (props as any).schema) as any;
2121
const currency = currencyField?.currency || 'USD';
2222
const precision = currencyField?.precision ?? 2;
@@ -44,6 +44,7 @@ export function CurrencyField({ value, onChange, field, readonly, errorMessage,
4444
{currency === 'USD' ? '$' : currency}
4545
</span>
4646
<Input
47+
{...props}
4748
type="number"
4849
value={value ?? ''}
4950
onChange={(e) => {
@@ -53,10 +54,9 @@ export function CurrencyField({ value, onChange, field, readonly, errorMessage,
5354
onBlur={handleBlur}
5455
placeholder={currencyField?.placeholder || '0.00'}
5556
disabled={readonly}
56-
className={`pl-8 ${props.className || ''}`}
57+
className={`pl-8 ${className || ''}`}
5758
step={Math.pow(10, -precision).toFixed(precision)}
5859
aria-invalid={!!errorMessage}
59-
{...props}
6060
/>
6161
</div>
6262
);

packages/fields/src/widgets/DateField.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ export function DateField({ value, onChange, field, readonly, ...props }: FieldW
99

1010
return (
1111
<Input
12+
{...props}
1213
type="date"
1314
value={value || ''}
1415
onChange={(e) => onChange(e.target.value)}
1516
disabled={readonly}
16-
className={props.className}
1717
/>
1818
);
1919
}

packages/fields/src/widgets/DateTimeField.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ export function DateTimeField({ value, onChange, field, readonly, ...props }: Fi
1515

1616
return (
1717
<Input
18+
{...props}
1819
type="datetime-local"
1920
value={value || ''}
2021
onChange={(e) => onChange(e.target.value)}
2122
disabled={readonly}
22-
className={props.className}
2323
/>
2424
);
2525
}

packages/fields/src/widgets/EmailField.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ export function EmailField({ value, onChange, field, readonly, errorMessage, ...
1818

1919
return (
2020
<Input
21+
{...props}
2122
type="email"
2223
value={value || ''}
2324
onChange={(e) => onChange(e.target.value)}
2425
placeholder={config?.placeholder || 'email@example.com'}
2526
disabled={readonly}
26-
className={props.className}
2727
aria-invalid={!!errorMessage}
2828
/>
2929
);

packages/fields/src/widgets/NumberField.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export function NumberField({ value, onChange, field, readonly, ...props }: Fiel
1313

1414
return (
1515
<Input
16+
{...props}
1617
type="number"
1718
value={value ?? ''}
1819
onChange={(e) => {
@@ -22,7 +23,6 @@ export function NumberField({ value, onChange, field, readonly, ...props }: Fiel
2223
placeholder={numberField?.placeholder}
2324
disabled={readonly}
2425
step={precision ? Math.pow(10, -precision) : 'any'}
25-
className={props.className}
2626
/>
2727
);
2828
}

packages/fields/src/widgets/PasswordField.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Button } from '@object-ui/components';
44
import { Eye, EyeOff } from 'lucide-react';
55
import { FieldWidgetProps } from './types';
66

7-
export function PasswordField({ value, onChange, field, readonly, ...props }: FieldWidgetProps<string>) {
7+
export function PasswordField({ value, onChange, field, readonly, className, ...props }: FieldWidgetProps<string>) {
88
const [showPassword, setShowPassword] = useState(false);
99
const config = field || (props as any).schema;
1010

@@ -15,12 +15,13 @@ export function PasswordField({ value, onChange, field, readonly, ...props }: Fi
1515
return (
1616
<div className="relative">
1717
<Input
18+
{...props}
1819
type={showPassword ? 'text' : 'password'}
1920
value={value || ''}
2021
onChange={(e) => onChange(e.target.value)}
2122
placeholder={config?.placeholder}
2223
disabled={readonly}
23-
className={`pr-10 ${props.className || ''}`}
24+
className={`pr-10 ${className || ''}`}
2425
/>
2526
<Button
2627
type="button"

0 commit comments

Comments
 (0)