Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 24fd680

Browse files
authoredDec 24, 2020
Merge pull request #89 from headwirecom/issue/53-error-icons-for-array
create an ErrorIndicator component and reuse it in the table array renderer
2 parents 6e7c2bd + 5663417 commit 24fd680

File tree

5 files changed

+61
-47
lines changed

5 files changed

+61
-47
lines changed
 

‎packages/spectrum/src/additional/ArrayLayoutToolbar.tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,15 @@
2929

3030
import {
3131
ActionButton,
32-
Button,
3332
Flex,
3433
Heading,
3534
Tooltip,
3635
TooltipTrigger,
3736
View,
3837
} from '@adobe/react-spectrum';
3938
import Add from '@spectrum-icons/workflow/Add';
40-
import AlertCircle from '@spectrum-icons/workflow/AlertCircle';
4139
import React from 'react';
40+
import { ErrorIndicator } from '../components/ErrorIndicator';
4241

4342
export interface ArrayLayoutToolbarProps {
4443
label: string;
@@ -60,18 +59,7 @@ export const ArrayLayoutToolbar = React.memo(
6059
<Heading level={4}>{label}</Heading>
6160
<View isHidden={errors.length !== 0} marginEnd='auto' />
6261
<View isHidden={errors.length === 0} marginEnd='auto'>
63-
<TooltipTrigger delay={0}>
64-
<Button
65-
isQuiet
66-
variant='negative'
67-
margin='size-50'
68-
minWidth='size-0'
69-
width='size-10'
70-
>
71-
<AlertCircle color='negative' />
72-
</Button>
73-
<Tooltip>{errors}</Tooltip>
74-
</TooltipTrigger>
62+
<ErrorIndicator errors={errors} />
7563
</View>
7664
<View>
7765
<TooltipTrigger delay={0}>

‎packages/spectrum/src/complex/SpectrumTableArrayControl.tsx

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ import {
5454
import {
5555
ActionButton,
5656
AlertDialog,
57-
Button,
5857
DialogTrigger,
5958
Flex,
6059
Header,
@@ -70,7 +69,7 @@ import './table-cell.css';
7069
import Add from '@spectrum-icons/workflow/Add';
7170
import Delete from '@spectrum-icons/workflow/Delete';
7271
import { ErrorObject } from 'ajv';
73-
import AlertCircle from '@spectrum-icons/workflow/AlertCircle';
72+
import { ErrorIndicator } from '../components/ErrorIndicator';
7473

7574
const { createLabelDescriptionFrom } = Helpers;
7675

@@ -104,13 +103,11 @@ class SpectrumTableArrayControl extends React.Component<
104103
path,
105104
data,
106105
visible,
107-
errors,
108106
label,
109107
childErrors,
110108
} = this.props;
111109

112110
const controlElement = uischema as ControlElement;
113-
114111
const createControlElement = (key?: string): ControlElement => ({
115112
type: 'Control',
116113
label: false,
@@ -132,8 +129,8 @@ class SpectrumTableArrayControl extends React.Component<
132129

133130
const getChildErrorMessage = getError(childErrors);
134131
const labelObject = createLabelDescriptionFrom(controlElement, schema);
135-
const isValid = errors.length === 0;
136132
const labelText = isPlainLabel(label) ? label : label.default;
133+
const allErrorsMessages = childErrors.map((e) => e.message).join(' ');
137134

138135
const UNSAFE_error = {
139136
color: 'rgb(215, 55, 63)',
@@ -159,21 +156,9 @@ class SpectrumTableArrayControl extends React.Component<
159156
justifyContent='space-between'
160157
>
161158
<Heading level={4}>{labelText}</Heading>
162-
<View isHidden={!isValid} marginEnd='auto' />
163-
<View isHidden={isValid} marginEnd='auto'>
164-
<TooltipTrigger delay={0}>
165-
<Button
166-
isQuiet
167-
aria-label='validation'
168-
variant='negative'
169-
margin='size-50'
170-
minWidth='size-0'
171-
width='size-10'
172-
>
173-
<AlertCircle color='negative' />
174-
</Button>
175-
<Tooltip>{errors}</Tooltip>
176-
</TooltipTrigger>
159+
<View isHidden={allErrorsMessages.length > 0} marginEnd='auto' />
160+
<View isHidden={allErrorsMessages.length === 0} marginEnd='auto'>
161+
<ErrorIndicator errors={allErrorsMessages} />
177162
</View>
178163
<TooltipTrigger delay={0}>
179164
<ActionButton

‎packages/spectrum/src/complex/array/SpectrumArrayControlRenderer.tsx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,6 @@ const SpectrumArrayControlRenderer = ({
5151
schema
5252
);
5353
const label = labelDescription.show ? labelDescription.text : '';
54-
// const controlClassName =
55-
// `control ${(Helpers.convertToValidClassName(controlElement.scope))}`;
56-
// const fieldSetClassName = getStyleAsClassName('array.layout');
57-
// const buttonClassName = getStyleAsClassName('array.button');
58-
// const childrenClassName = getStyleAsClassName('array.children');
59-
// const classNames: { [className: string]: string } = {
60-
// wrapper: controlClassName,
61-
// fieldSet: fieldSetClassName,
62-
// button: buttonClassName,
63-
// children: childrenClassName
64-
// };
6554

6655
return (
6756
<SpectrumArrayControl
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
The MIT License
3+
4+
Copyright (c) 2017-2019 EclipseSource Munich
5+
https://github.com/eclipsesource/jsonforms
6+
7+
Copyright (c) 2020 headwire.com, Inc
8+
https://github.com/headwirecom/jsonforms-react-spectrum-renderers
9+
10+
11+
Permission is hereby granted, free of charge, to any person obtaining a copy
12+
of this software and associated documentation files (the "Software"), to deal
13+
in the Software without restriction, including without limitation the rights
14+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15+
copies of the Software, and to permit persons to whom the Software is
16+
furnished to do so, subject to the following conditions:
17+
18+
The above copyright notice and this permission notice shall be included in
19+
all copies or substantial portions of the Software.
20+
21+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27+
THE SOFTWARE.
28+
*/
29+
30+
import React from 'react';
31+
import { Button, Tooltip, TooltipTrigger } from '@adobe/react-spectrum';
32+
import AlertCircle from '@spectrum-icons/workflow/AlertCircle';
33+
34+
export function ErrorIndicator({ errors }: { errors: string }) {
35+
return (
36+
<TooltipTrigger delay={0}>
37+
<Button
38+
aria-label='error-indicator'
39+
isQuiet
40+
variant='negative'
41+
margin='size-50'
42+
minWidth='size-0'
43+
width='size-10'
44+
>
45+
<AlertCircle color='negative' />
46+
</Button>
47+
<Tooltip>{errors}</Tooltip>
48+
</TooltipTrigger>
49+
);
50+
}

‎packages/spectrum/test/renderers/SpectrumTableArrayControl.test.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,9 @@ describe('validations messages', () => {
391391
const data = { test: 2 };
392392
const { getByRole } = renderForm(fixture.uischema, fixture.schema, data);
393393

394-
expect(getByRole('button', { name: /validation/ })).toBeInTheDocument();
394+
expect(
395+
getByRole('button', { name: /error-indicator/ })
396+
).toBeInTheDocument();
395397
});
396398

397399
test('empty errors by default', () => {
@@ -402,7 +404,7 @@ describe('validations messages', () => {
402404
);
403405

404406
expect(() => {
405-
getByRole('button', { name: /validation/ });
407+
getByRole('button', { name: /error-indicator/ });
406408
}).toThrow();
407409
});
408410
});

0 commit comments

Comments
 (0)