Skip to content

Commit 8c5c933

Browse files
committed
chore: remove unused EditAttribute 'array' type
1 parent 8dc29c9 commit 8c5c933

File tree

1 file changed

+0
-108
lines changed

1 file changed

+0
-108
lines changed

packages/webui/src/client/lib/EditAttribute.tsx

Lines changed: 0 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export type EditAttributeType =
3333
| 'json'
3434
| 'colorpicker'
3535
| 'iconpicker'
36-
| 'array'
3736
export class EditAttribute extends React.Component<IEditAttribute> {
3837
render(): JSX.Element {
3938
if (this.props.type === 'text') {
@@ -60,8 +59,6 @@ export class EditAttribute extends React.Component<IEditAttribute> {
6059
return <EditAttributeColorPicker {...this.props} />
6160
} else if (this.props.type === 'iconpicker') {
6261
return <EditAttributeIconPicker {...this.props} />
63-
} else if (this.props.type === 'array') {
64-
return <EditAttributeArray {...this.props} />
6562
} else {
6663
assertNever(this.props.type)
6764
}
@@ -335,111 +332,6 @@ function EditAttributeJson(props: IEditAttributeBaseProps) {
335332
/>
336333
)
337334
}
338-
function EditAttributeArray(props: IEditAttributeBaseProps) {
339-
const stateHelper = useEditAttributeStateHelper(props)
340-
341-
const [editingValue, setEditingValue] = useState<string | null>(null)
342-
343-
const handleChange = useCallback(
344-
(event: React.ChangeEvent<HTMLInputElement>) => {
345-
const v = event.target.value
346-
347-
setEditingValue(v)
348-
349-
const arrayObj = stringIsArray(v, props.arrayType)
350-
if (arrayObj) {
351-
if (props.updateOnKey) {
352-
stateHelper.handleUpdate(arrayObj.parsed)
353-
}
354-
stateHelper.setValueError(false)
355-
}
356-
},
357-
[setEditingValue, props.arrayType, props.updateOnKey, stateHelper.handleUpdate, stateHelper.setValueError]
358-
)
359-
const handleBlur = useCallback(
360-
(event: React.FocusEvent<HTMLInputElement>) => {
361-
const v = event.target.value
362-
363-
setEditingValue(v)
364-
365-
const arrayObj = stringIsArray(v, props.arrayType)
366-
if (arrayObj) {
367-
stateHelper.handleUpdate(arrayObj.parsed)
368-
stateHelper.setValueError(false)
369-
} else {
370-
stateHelper.setValueError(true)
371-
}
372-
},
373-
[setEditingValue, props.arrayType, stateHelper.handleUpdate, stateHelper.setValueError]
374-
)
375-
const handleEscape = useCallback(
376-
(e: React.KeyboardEvent<HTMLInputElement>) => {
377-
if (e.key === 'Escape') {
378-
setEditingValue(null)
379-
}
380-
},
381-
[setEditingValue]
382-
)
383-
384-
let currentValueString = stateHelper.getAttributeValue()
385-
if (Array.isArray(currentValueString)) {
386-
currentValueString = currentValueString.join(', ')
387-
} else {
388-
currentValueString = ''
389-
}
390-
391-
return (
392-
<input
393-
type="text"
394-
className={ClassNames(
395-
'form-control',
396-
props.className,
397-
stateHelper.valueError && props.invalidClassName
398-
? props.invalidClassName
399-
: editingValue !== null
400-
? props.modifiedClassName || ''
401-
: ''
402-
)}
403-
placeholder={props.label}
404-
value={(editingValue ?? currentValueString) || ''}
405-
onChange={handleChange}
406-
onBlur={handleBlur}
407-
onKeyUp={handleEscape}
408-
disabled={props.disabled}
409-
/>
410-
)
411-
}
412-
function stringIsArray(strOrg: string, arrayType: IEditAttributeBaseProps['arrayType']): { parsed: any[] } | false {
413-
if (!(strOrg + '').trim().length) return { parsed: [] }
414-
415-
const values: any[] = []
416-
const strs = (strOrg + '').split(',')
417-
418-
for (const str of strs) {
419-
// Check that the values in the array are of the right type:
420-
421-
if (arrayType === 'boolean') {
422-
const parsed = JSON.parse(str)
423-
if (typeof parsed !== 'boolean') return false // type check failed
424-
values.push(parsed)
425-
} else if (arrayType === 'int') {
426-
const parsed = parseInt(str, 10)
427-
428-
if (Number.isNaN(parsed)) return false // type check failed
429-
values.push(parsed)
430-
} else if (arrayType === 'float') {
431-
const parsed = parseFloat(str)
432-
if (Number.isNaN(parsed)) return false // type check failed
433-
values.push(parsed)
434-
} else {
435-
// else this.props.arrayType is 'string'
436-
const parsed = str + ''
437-
if (typeof parsed !== 'string') return false // type check failed
438-
values.push(parsed.trim())
439-
}
440-
}
441-
return { parsed: values }
442-
}
443335
function EditAttributeColorPicker(props: IEditAttributeBaseProps) {
444336
const stateHelper = useEditAttributeStateHelper(props)
445337

0 commit comments

Comments
 (0)