-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented custom attribute management
- Loading branch information
Showing
23 changed files
with
1,576 additions
and
171 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
102 changes: 102 additions & 0 deletions
102
ui/public/assets/schema/attribute/attribute.schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
{ | ||
"type": "object", | ||
"required": [ | ||
"name", | ||
"attributeType" | ||
], | ||
"properties": { | ||
"name": { | ||
"title": "label.entity-attribute-name", | ||
"description": "tooltip.entity-attribute-name", | ||
"type": "string", | ||
"minLength": 1, | ||
"maxLength": 255 | ||
}, | ||
"attributeType": { | ||
"title": "label.entity-attribute-type", | ||
"description": "tooltip.entity-attribute-type", | ||
"type": "string", | ||
"enum": [ | ||
"STRING", | ||
"BOOLEAN", | ||
"SELECTION_LIST" | ||
], | ||
"enumNames": [ | ||
"value.string", | ||
"value.boolean", | ||
"value.list" | ||
] | ||
}, | ||
"helpText": { | ||
"title": "label.entity-attribute-help", | ||
"description": "tooltip.entity-attribute-help", | ||
"type": "string", | ||
"minLength": 1, | ||
"maxLength": 255 | ||
} | ||
}, | ||
"dependencies": { | ||
"attributeType": { | ||
"oneOf": [ | ||
{ | ||
"properties": { | ||
"attributeType": { | ||
"enum": [ | ||
"STRING" | ||
] | ||
}, | ||
"defaultValueString": { | ||
"title": "label.entity-attribute-default", | ||
"description": "tooltip.entity-attribute-default", | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
{ | ||
"properties": { | ||
"attributeType": { | ||
"enum": [ | ||
"BOOLEAN" | ||
] | ||
}, | ||
"defaultValueBoolean": { | ||
"title": "label.entity-attribute-default", | ||
"description": "tooltip.entity-attribute-default", | ||
"type": "boolean", | ||
"default": true, | ||
"enumNames": ["True", "False"] | ||
} | ||
} | ||
}, | ||
{ | ||
"properties": { | ||
"attributeType": { | ||
"enum": [ | ||
"SELECTION_LIST" | ||
] | ||
}, | ||
"customAttrListDefinitions": { | ||
"title": "label.entity-attribute-list-options", | ||
"description": "tooltip.entity-attribute-list-options", | ||
"type": "array", | ||
"items": { | ||
"title": "label.list-options", | ||
"type": "object", | ||
"properties": { | ||
"value": { | ||
"type": "string", | ||
"placeholder": "Option" | ||
}, | ||
"default": { | ||
"type": "boolean", | ||
"default": false | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
ui/src/app/form/component/fields/StringListWithDefaultField.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
import React from 'react'; | ||
|
||
import Row from "react-bootstrap/Row"; | ||
import Col from "react-bootstrap/Col"; | ||
import Form from 'react-bootstrap/Form'; | ||
|
||
import Button from 'react-bootstrap/Button'; | ||
|
||
import AddButton from "../AddButton"; | ||
|
||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { faTrash } from '@fortawesome/free-solid-svg-icons'; | ||
|
||
const ArrayFieldDescription = ({ | ||
DescriptionField, | ||
idSchema, | ||
description, | ||
}) => { | ||
if (!description) { | ||
return null; | ||
} | ||
|
||
const id = `${idSchema.$id}__description`; | ||
return <DescriptionField id={id} description={description} />; | ||
}; | ||
|
||
|
||
const ArrayFieldTitle = ({ | ||
TitleField, | ||
idSchema, | ||
title, | ||
required, | ||
}) => { | ||
if (!title) { | ||
return null; | ||
} | ||
|
||
const id = `${idSchema.$id}__title`; | ||
return <TitleField id={id} title={title} required={required} />; | ||
}; | ||
|
||
const defItem = { | ||
value: '', | ||
default: false | ||
} | ||
|
||
const StringListWithDefaultField = ({ | ||
schema, | ||
label, | ||
id, | ||
name, | ||
disabled, | ||
value, | ||
readonly, | ||
rawErrors, | ||
onChange, | ||
errorSchema, | ||
formData, | ||
registry, | ||
...props | ||
}) => { | ||
|
||
const { fields } = registry; | ||
const [items, setItems] = React.useState([ | ||
...(formData ? formData : []) | ||
]); | ||
|
||
React.useEffect(() => { | ||
onChange(items); | ||
}, [items, onChange]); | ||
|
||
const onAdd = () => { | ||
setItems([...items, { ...defItem }]); | ||
}; | ||
|
||
const setValue = (item, value) => { | ||
item.value = value; | ||
setItems([...items]); | ||
}; | ||
|
||
const setDefault = (item) => { | ||
const current = items.find(i => i.default); | ||
if (current) { | ||
current.default = false; | ||
} | ||
item.default = true; | ||
setItems([...items]); | ||
}; | ||
|
||
const removeItem = (item) => { | ||
setItems([...items.filter(i => i !== item)]); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<Row className=""> | ||
<Col className=""> | ||
<div className="d-flex align-items-center mb-3"> | ||
{<ArrayFieldTitle | ||
key={`array-field-title-${props.idSchema.$id}`} | ||
TitleField={fields.TitleField} | ||
idSchema={props.idSchema} | ||
title={props.uiSchema["ui:title"] || props.title} | ||
required={props.required} | ||
/>} | ||
<AddButton | ||
className="array-item-add mx-2" | ||
onClick={onAdd} | ||
disabled={props.disabled || props.readonly} | ||
/> | ||
{(props.uiSchema["ui:description"] || schema.description) && ( | ||
<ArrayFieldDescription | ||
key={`array-field-description-${props.idSchema.$id}`} | ||
DescriptionField={fields.DescriptionField} | ||
idSchema={props.idSchema} | ||
description={ | ||
props.uiSchema["ui:description"] || schema.description | ||
} | ||
/> | ||
)} | ||
</div> | ||
<div> | ||
{items && items.map((p, idx) => | ||
<div className="my-2 d-flex justify-content-between align-items-center form-inline"> | ||
<Form.Control | ||
type="text" | ||
className="flex-grow-1" | ||
value={p.value} | ||
onChange={({ target: { value } }) => setValue(p, value)}></Form.Control> | ||
<Form.Control custom name="default" type="radio" className="mx-4" | ||
checked={ p.default } | ||
onChange={ () => setDefault(p) } | ||
></Form.Control> | ||
<Button variant="text" className="text-danger" onClick={() => removeItem(p)}> | ||
<FontAwesomeIcon icon={faTrash} /> | ||
</Button> | ||
</div> | ||
)} | ||
</div> | ||
</Col> | ||
</Row> | ||
</div> | ||
); | ||
}; | ||
|
||
|
||
export default StringListWithDefaultField; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.