@onereach/channel-transformer
Version:
Convert data model between different channels (Slack, Microsoft Teams, Generic...)
63 lines (53 loc) • 1.48 kB
text/typescript
import { IGenericSelect } from '../../../../generic/types/select';
import { ISlackSelectStatic } from '../../../types';
import {
convertOptions, convertGroupOptions,
convertSingleOption, convertGroupOption
} from '../helpers/convert-options';
import { transformConfirm } from '../confirm';
import { transformTextObject } from '../helpers/transform-text-object';
export const transformSelect = ({
type,
placeholder,
action_id,
options,
option_groups,
initial_option,
confirm
}: ISlackSelectStatic): IGenericSelect => {
const res: IGenericSelect = {
type: 'select',
props: {
slack: {
type
}
}
};
if (action_id) {
res.props.variableName = action_id;
}
if (placeholder) {
res.props.placeholder = transformTextObject(placeholder).value;
}
if (placeholder) {
res.props.slack.placeholder_type = placeholder.type;
res.props.slack.placeholder_emoji = placeholder.emoji;
res.props.slack.placeholder_verbatim = placeholder.verbatim;
}
if (initial_option) {
res.props.value = convertSingleOption(initial_option);
}
if (options) {
res.props.options = convertOptions(options);
}
if (option_groups) {
res.props.slack.option_groups = convertGroupOptions(option_groups);
if (initial_option) {
res.props.slack.initial_option = convertGroupOption(initial_option);
}
}
if (confirm) {
res.props.slack.confirm = transformConfirm(confirm);
}
return res;
};