Skip to content

Commit 3e81f4b

Browse files
authored
fix: Accessible name for KeyValueField and Eslint adjustments (#4410)
* fix: Accessible name for KeyValueField and Eslint adjustments * fix: not updating
1 parent 96ae09e commit 3e81f4b

File tree

7 files changed

+71
-58
lines changed

7 files changed

+71
-58
lines changed

eslint.config.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,29 @@ export default defineConfig(
4444

4545
// TypeScript
4646
'@typescript-eslint/no-explicit-any': 'off',
47-
'@typescript-eslint/no-unused-vars': 'warn',
47+
'@typescript-eslint/no-unused-vars': [
48+
'warn',
49+
{
50+
varsIgnorePattern: '^_',
51+
argsIgnorePattern: '^_',
52+
caughtErrorsIgnorePattern: '^_',
53+
},
54+
],
4855
'@typescript-eslint/no-empty-object-type': 'off',
4956
'@typescript-eslint/no-non-null-asserted-optional-chain': 'warn',
5057
'@typescript-eslint/no-unsafe-function-type': 'warn',
5158
'@typescript-eslint/no-unused-expressions': 'warn',
5259
'@typescript-eslint/ban-ts-comment': 'warn',
5360
'@typescript-eslint/no-require-imports': 'warn',
5461
// Misc
55-
'no-unused-vars': 'warn',
62+
'no-unused-vars': [
63+
'warn',
64+
{
65+
varsIgnorePattern: '^_',
66+
argsIgnorePattern: '^_',
67+
caughtErrorsIgnorePattern: '^_',
68+
},
69+
],
5670
'no-undef': 'warn',
5771
'no-case-declarations': 'warn',
5872
'no-constant-binary-expression': 'warn',

src/components/Extensibility/components-form/KeyValuePairRenderer.jsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@ const getEnumComponent = (
1818
if (!Array.isArray(enumValues)) return input;
1919

2020
const options = enumValues.map((opt) => ({ key: opt, text: opt }));
21-
return ({ onChange, setValue, onBlur, value, ...props }) => (
21+
const DropdownComp = ({ onChange, setValue, onBlur, value, ...props }) => (
2222
<Dropdown
2323
{...props}
2424
value={value}
2525
options={options}
2626
setValue={(v) => {
27-
isKeyInput
28-
? onChange({
29-
target: {
30-
value: v,
31-
},
32-
})
33-
: setValue(v);
27+
if (isKeyInput) {
28+
onChange({ target: { value: v } });
29+
} else {
30+
setValue(v);
31+
}
3432
onBlur();
3533
}}
3634
/>
3735
);
36+
37+
return DropdownComp;
3838
};
3939

4040
const getValueComponent = (valueInfo) => {
@@ -45,8 +45,8 @@ const getValueComponent = (valueInfo) => {
4545
return getEnumComponent(valueEnum, false, Inputs.Number);
4646
case 'string':
4747
return getEnumComponent(valueEnum, false, Inputs.Text);
48-
case 'object':
49-
return ({ setValue, value }) => (
48+
case 'object': {
49+
const FieldComp = ({ setValue, value }) => (
5050
<KeyValueField
5151
className="nested-key-value-pair"
5252
value={value}
@@ -59,6 +59,8 @@ const getValueComponent = (valueInfo) => {
5959
}}
6060
/>
6161
);
62+
return FieldComp;
63+
}
6264
default:
6365
return getEnumComponent(valueEnum, false);
6466
}
@@ -97,7 +99,7 @@ export function KeyValuePairRenderer({
9799

98100
try {
99101
value = value ? value.toJS() : {};
100-
} catch (error) {
102+
} catch (_error) {
101103
value = {};
102104
}
103105

src/shared/ResourceForm/fields/KeyValueField.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export function KeyValueField({
2424
required,
2525
disableOnEdit,
2626
editMode,
27-
accessibleName,
2827
...props
2928
}) {
3029
const { t } = useTranslation();
@@ -60,6 +59,7 @@ export function KeyValueField({
6059
actions = [
6160
...actions,
6261
<Button
62+
key="button-encode"
6363
design="Transparent"
6464
icon={valuesEncoded ? 'show' : 'hide'}
6565
onClick={toggleEncoding}

src/shared/ResourceForm/fields/MultiInput.jsx

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,21 @@ export function MultiInput({
9898
};
9999
const open = defaultOpen ?? false;
100100

101+
const inputComponents = internalValue.map((entry, index) =>
102+
inputs.map((input, inputIndex) =>
103+
input({
104+
index: (index + 1) * keys,
105+
value: entry,
106+
setValue: (entry) => setEntry(entry, index),
107+
ref: refs[index]?.[inputIndex],
108+
updateValue: () => updateValue(internalValue),
109+
internalValue,
110+
setMultiValue: setValue,
111+
focus: (e, target) => handleFocusMove(e, target, index),
112+
}),
113+
),
114+
);
115+
101116
useEffect(() => {
102117
internalValue.forEach((entry, index) => {
103118
const isValid = (child) => child.props.validate(entry) ?? true;
@@ -122,32 +137,19 @@ export function MultiInput({
122137
});
123138
}, [inputs, internalValue]); // eslint-disable-line react-hooks/exhaustive-deps
124139

125-
const inputComponents = internalValue.map((entry, index) =>
126-
inputs.map((input, inputIndex) =>
127-
input({
128-
index: (index + 1) * keys,
129-
value: entry,
130-
setValue: (entry) => setEntry(entry, index),
131-
ref: refs[index]?.[inputIndex],
132-
updateValue: () => updateValue(internalValue),
133-
internalValue,
134-
setMultiValue: setValue,
135-
focus: (e, target) => {
136-
if (e.key === 'Enter') {
137-
if (typeof target === 'undefined') {
138-
focus(refs[index + 1]?.[0]);
139-
} else {
140-
focus(refs[index][target]);
141-
}
142-
} else if (e.key === 'ArrowDown') {
143-
focus(refs[index + 1]?.[0]);
144-
} else if (e.key === 'ArrowUp') {
145-
focus(refs[index - 1]?.[0]);
146-
}
147-
},
148-
}),
149-
),
150-
);
140+
const handleFocusMove = (e, target, index) => {
141+
if (e.key === 'Enter') {
142+
if (typeof target === 'undefined') {
143+
focus(refs[index + 1]?.[0]);
144+
} else {
145+
focus(refs[index][target]);
146+
}
147+
} else if (e.key === 'ArrowDown') {
148+
focus(refs[index + 1]?.[0]);
149+
} else if (e.key === 'ArrowUp') {
150+
focus(refs[index - 1]?.[0]);
151+
}
152+
};
151153

152154
return (
153155
<ResourceForm.CollapsibleSection

src/shared/ResourceForm/inputs/Switch.jsx

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Switch as UI5Switch } from '@ui5/webcomponents-react';
2+
3+
interface SwitchProps {
4+
value: boolean;
5+
setValue: (_value: boolean) => void;
6+
}
7+
8+
export function Switch({ value, setValue, ...props }: SwitchProps) {
9+
return (
10+
<UI5Switch checked={value} onChange={() => setValue(!value)} {...props} />
11+
);
12+
}

src/shared/ResourceForm/inputs/Text.jsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@ export function Text({ key, ...props }) {
88
export function WrappedText({ value, setValue, onChange, inputRef, ...props }) {
99
if (!props.readOnly) delete props.readOnly;
1010

11-
const {
12-
validationRef,
13-
internalValue,
14-
setMultiValue,
15-
setResource,
16-
validateMessage,
17-
accessibleName,
18-
...inputProps
19-
} = props;
20-
2111
const validationProps = useValidation({
2212
inputRef,
2313
onChange: [onChange, (e) => setValue && setValue(e.target.value)],
@@ -27,7 +17,7 @@ export function WrappedText({ value, setValue, onChange, inputRef, ...props }) {
2717
<Input
2818
value={value || ''}
2919
onInput={onChange ?? ((e) => setValue && setValue(e.target.value))}
30-
{...inputProps}
20+
{...props}
3121
{...validationProps}
3222
/>
3323
);

0 commit comments

Comments
 (0)