chippifyText()

in frontend/src/js/components/UtilComponents/InputSupper/index.js [61:104]


    chippifyText(chips, value) {
        let overrideElements = JSON.parse(value).map(e => {
            if (_isString(e)) {
                return {
                    type: 'input',
                    value: e
                };
            } else if (_isObject(e)) {
                return {
                    type: 'chip',
                    name: e.n,
                    value: e.v,
                    negate: e.op === '-',
                    chipType: e.t,
                    workspaceId: e.workspaceId,
                    folderId: e.folderId,
                };
            }

            return undefined;
        });

        // Fill options on dropdown chips
        overrideElements = overrideElements.map(c => {
            if (c.chipType === 'dropdown') {
                const chip = chips.find(s => s.name === c.name);
                c.options = chip && chip.options ? chip.options : [];
                return c;
            } else {
                return c;
            }
        });

        if (this.state.elements.length === overrideElements.length &&
            this.state.elements.every((e, i) => overrideElements[i].value.startsWith(e.value))) {
            this.setState({
                elements: this.state.elements.map((e, i) => Object.assign(e, overrideElements[i]))
            });
        } else {
            this.setState({
                elements: overrideElements
            });
        }
    }