Skip to content

Commit ab9f4c5

Browse files
Move additional properties card to component and use for errors (#61)
* make card with additional properties component. use for errors, too
1 parent 5047f26 commit ab9f4c5

File tree

5 files changed

+96
-52
lines changed

5 files changed

+96
-52
lines changed

__tests__/components/JSONEditor.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ describe('JSONEditor', () => {
267267
await userEvent.click(applyButton);
268268

269269
await waitFor(() =>
270-
expect(screen.getByText('Schema Validation Errors:')).toBeInTheDocument()
270+
expect(screen.getByText('Schema Validation Errors')).toBeInTheDocument()
271271
);
272272

273273
expect(mockOnChange).not.toHaveBeenCalled();
@@ -285,7 +285,7 @@ describe('JSONEditor', () => {
285285
await userEvent.click(applyButton);
286286

287287
await waitFor(() =>
288-
expect(screen.getByText('Schema Validation Errors:')).toBeInTheDocument()
288+
expect(screen.getByText('Schema Validation Errors')).toBeInTheDocument()
289289
);
290290
});
291291

__tests__/playwright/CreateIngestPage.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ test.describe('Create Ingest Page', () => {
262262
await test.step('paste a JSON not matching required schema in the editor and check for error message', async () => {
263263
await page.getByTestId('json-editor').fill('{"validJSON": true}');
264264
await page.getByRole('button', { name: /apply changes/i }).click();
265-
await expect(page.getByText('Schema Validation Errors:')).toBeVisible();
265+
await expect(page.getByText('Schema Validation Errors')).toBeVisible();
266266
const requiredProperties = [
267267
'collection',
268268
'title',

components/AdditionalPropertyCard.tsx

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { Card, theme, Typography } from 'antd';
2+
import {
3+
ExclamationCircleOutlined,
4+
CloseCircleOutlined,
5+
} from '@ant-design/icons';
6+
7+
const { useToken } = theme;
8+
9+
function AdditionalPropertyCard({
10+
additionalProperties,
11+
style,
12+
}: {
13+
additionalProperties: string[] | null;
14+
style: 'warning' | 'error';
15+
}) {
16+
const { token } = useToken();
17+
18+
if (!additionalProperties) return null;
19+
20+
const styleConfig = {
21+
warning: {
22+
title: 'Extra Properties set via JSON Editor',
23+
icon: <ExclamationCircleOutlined />,
24+
textColor: token.colorWarningText,
25+
},
26+
error: {
27+
title: 'Schema Validation Errors',
28+
icon: <CloseCircleOutlined />,
29+
textColor: token.colorErrorText,
30+
},
31+
};
32+
33+
const { title, icon, textColor } = styleConfig[style];
34+
35+
return (
36+
<Card
37+
data-testid="extra-properties-card"
38+
title={
39+
<div
40+
style={{
41+
display: 'flex',
42+
alignItems: 'center',
43+
gap: '8px',
44+
color: textColor,
45+
}}
46+
>
47+
{icon}
48+
<span>{title}</span>
49+
</div>
50+
}
51+
style={{
52+
width: '100%',
53+
marginTop: '10px',
54+
maxHeight: '300px',
55+
overflowY: 'auto',
56+
backgroundColor: '#f5f5f5',
57+
boxShadow: '0px 3px 15px rgba(0, 0, 0, 0.2)',
58+
borderRadius: '8px',
59+
}}
60+
>
61+
<ul
62+
style={{
63+
display: 'grid',
64+
gridTemplateRows: 'repeat(3, auto)',
65+
gridAutoFlow: 'column',
66+
gap: '10px',
67+
padding: 0,
68+
listStyleType: 'none',
69+
}}
70+
>
71+
{additionalProperties.map((prop) => (
72+
<li key={prop} style={{ paddingLeft: '10px' }}>
73+
<Typography.Text style={{ color: textColor, fontSize: '16px' }}>
74+
{prop}
75+
</Typography.Text>
76+
</li>
77+
))}
78+
</ul>
79+
</Card>
80+
);
81+
}
82+
83+
export default AdditionalPropertyCard;

components/IngestForm.tsx

+5-39
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { customValidate } from '@/utils/CustomValidation';
1717
import { handleSubmit } from '@/utils/FormHandlers';
1818
import JSONEditor from '@/components/JSONEditor';
1919
import { JSONEditorValue } from '@/components/JSONEditor';
20+
import AdditionalPropertyCard from '@/components/AdditionalPropertyCard';
2021

2122
const Form = withTheme(AntDTheme);
2223

@@ -143,45 +144,10 @@ function IngestForm({
143144
{children}
144145
</Form>
145146
{additionalProperties && additionalProperties.length > 0 && (
146-
<Card
147-
data-testid="extra-properties-card"
148-
title={
149-
<div
150-
style={{
151-
display: 'flex',
152-
alignItems: 'center',
153-
gap: '8px',
154-
color: '#faad14',
155-
}}
156-
>
157-
<ExclamationCircleOutlined />
158-
<span>Extra Properties set via JSON Editor</span>
159-
</div>
160-
}
161-
style={{
162-
width: '100%',
163-
marginTop: '10px',
164-
maxHeight: '300px',
165-
overflowY: 'auto',
166-
}}
167-
>
168-
<ul
169-
style={{
170-
display: 'grid',
171-
gridTemplateRows: 'repeat(3, auto)', // 3 rows before wrapping to new column
172-
gridAutoFlow: 'column',
173-
gap: '10px',
174-
padding: 0,
175-
listStyleType: 'none',
176-
}}
177-
>
178-
{additionalProperties.map((prop) => (
179-
<li key={prop} style={{ paddingLeft: '10px' }}>
180-
{prop}
181-
</li>
182-
))}
183-
</ul>
184-
</Card>
147+
<AdditionalPropertyCard
148+
additionalProperties={additionalProperties}
149+
style="warning"
150+
/>
185151
)}
186152
</>
187153
),

components/JSONEditor.tsx

+5-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Input, Button, Typography, Checkbox, Flex, message } from 'antd';
33
import Ajv from 'ajv';
44
import addFormats from 'ajv-formats';
55
import jsonSchema from '@/FormSchemas/jsonschema.json';
6+
import AdditionalPropertyCard from '@/components/AdditionalPropertyCard';
67

78
const { TextArea } = Input;
89
const { Text } = Typography;
@@ -204,16 +205,10 @@ const JSONEditor: React.FC<JSONEditorProps> = ({
204205

205206
{jsonError && <Text type="danger">{jsonError}</Text>}
206207
{schemaErrors.length > 0 && (
207-
<div style={{ marginTop: '10px' }}>
208-
<Text type="danger">Schema Validation Errors:</Text>
209-
<ul>
210-
{schemaErrors.map((error, index) => (
211-
<li key={index}>
212-
<Text type="danger">{error}</Text>
213-
</li>
214-
))}
215-
</ul>
216-
</div>
208+
<AdditionalPropertyCard
209+
additionalProperties={schemaErrors}
210+
style="error"
211+
/>
217212
)}
218213
</Flex>
219214
);

0 commit comments

Comments
 (0)