Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | 98x 1x 1x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 4x 1x 1x 1x 1x 4x 4x 98x 98x 12x 12x 12x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x 98x | import { html } from 'lit-html';
import { ActionConfig, ACTION_GROUPS, FormData, FlowTypes } from '../types';
import { Node, AddInputLabels } from '../../store/flow-definition';
import { renderNamedObjects } from '../utils';
export const add_input_labels: ActionConfig = {
name: 'Add Input Labels',
group: ACTION_GROUPS.save,
flowTypes: [FlowTypes.VOICE, FlowTypes.MESSAGE, FlowTypes.BACKGROUND],
render: (_node: Node, action: AddInputLabels) => {
return html`<div>${renderNamedObjects(action.labels, 'label')}</div>`;
},
// Form-level transformations
toFormData: (action: AddInputLabels) => {
return {
labels: action.labels || null,
uuid: action.uuid
};
},
form: {
labels: {
type: 'select',
label: 'Labels',
helpText:
'Select labels to add to the input. Type a new label name to create it.',
required: true,
options: [],
multi: true,
searchable: true,
endpoint: '/api/v2/labels.json',
valueKey: 'uuid',
nameKey: 'name',
placeholder: 'Search for labels or type to create new ones...',
allowCreate: true,
createArbitraryOption: (input: string, options: any[]) => {
// Check if a label with this name already exists
const existing = options.find(
(option) =>
option.name.toLowerCase().trim() === input.toLowerCase().trim()
);
if (!existing && input.trim()) {
return {
name: input.trim(),
arbitrary: true
};
}
return null;
}
}
},
fromFormData: (formData: FormData): AddInputLabels => {
return {
uuid: formData.uuid,
type: 'add_input_labels',
labels: (formData.labels || []).map((l: any) => ({
uuid: l.uuid,
name: l.name
}))
};
}
};
|