feat(xo-web/SelectTag): allow non existing tags (#3316)

This commit is contained in:
badrAZ 2018-08-17 10:05:20 +02:00 committed by Julien Fontanet
parent 235da199f9
commit 1aa4966a92

View File

@ -119,6 +119,7 @@ const getObjectsById = objects =>
*/ */
class GenericSelect extends React.Component { class GenericSelect extends React.Component {
static propTypes = { static propTypes = {
allowMissingObjects: PropTypes.bool,
hasSelectAll: PropTypes.bool, hasSelectAll: PropTypes.bool,
multi: PropTypes.bool, multi: PropTypes.bool,
onChange: PropTypes.func.isRequired, onChange: PropTypes.func.isRequired,
@ -138,7 +139,8 @@ class GenericSelect extends React.Component {
() => this.props.xoContainers !== undefined, () => this.props.xoContainers !== undefined,
() => this.props.xoObjects, () => this.props.xoObjects,
this._getSelectedIds, this._getSelectedIds,
(withContainers, objects, ids) => { () => !this.props.allowMissingObjects,
(withContainers, objects, ids, removed) => {
const objectsById = getObjectsById(objects) const objectsById = getObjectsById(objects)
const missingObjects = [] const missingObjects = []
const addIfMissing = id => { const addIfMissing = id => {
@ -146,8 +148,8 @@ class GenericSelect extends React.Component {
missingObjects.push({ missingObjects.push({
id, id,
label: id, label: id,
removed,
value: id, value: id,
removed: true,
}) })
} }
} }
@ -580,7 +582,7 @@ export const SelectTag = makeStoreSelect(
tags => map(tags, tag => ({ id: tag, type: 'tag', value: tag })) tags => map(tags, tag => ({ id: tag, type: 'tag', value: tag }))
), ),
}), }),
{ placeholder: _('selectTags') } { allowMissingObjects: true, placeholder: _('selectTags') }
) )
export const SelectHighLevelObject = makeStoreSelect( export const SelectHighLevelObject = makeStoreSelect(