@onereach/channel-transformer
Version:
Convert data model between different channels (Slack, Microsoft Teams, Generic...)
30 lines (25 loc) • 1.01 kB
text/typescript
/* eslint-disable no-prototype-builtins */
import { IGenericSelect } from "../../../../generic/types";
import { IRWCAnswerComponent, IRWCOption } from '../../../types';
import { RWCAnswerComponent } from "../../../classes/v5";
export const transformSelect = ({ props }: IGenericSelect): IRWCAnswerComponent => {
const result: any = {};
const options: Array<IRWCOption> = props.options.map(op => {
return {
label: op.label,
value: op.value
};
});
result.options = options;
const type = props.rwc?.type ||
(options.length > 10 || props.hasOwnProperty('placeholder') ?
'rwc-dropdown':
'rwc-menu'
);
if (type === 'rwc-menu') return new RWCAnswerComponent(result, 'rwc-menu');
// RWC DROPDOWN PARAMS;
result.multiple = props?.multiple || false;
result.button = props.rwc?.button || "";
result.dropdownPlaceholder = props.placeholder || "";
return new RWCAnswerComponent(result, 'rwc-dropdown');
};