Skip to content

Commit

Permalink
Merge pull request #78 from glific/feature/id-added
Browse files Browse the repository at this point in the history
Added ids in interactive messages
  • Loading branch information
mdshamoon authored Aug 26, 2022
2 parents 0701023 + 1192d32 commit 15ad8ed
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@glific/flow-editor",
"license": "AGPL-3.0",
"repository": "git://github.com/glific/floweditor.git",
"version": "1.17.1-4",
"version": "1.17.1-7",
"description": "'Standalone flow editing tool designed for use within the Glific suite of messaging tools'",
"browser": "umd/flow-editor.min.js",
"unpkg": "umd/flow-editor.min.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@
margin-top: 10px;
}

.id {
margin-right: 4px;
}

.listItem {
display: flex;
width: 48% !important;
margin: 4px 4px;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface SendInteractiveMsgFormState extends FormState {
interactives: FormEntry;
labels?: any;
expression?: null | FormEntry;
listValues?: Array<any>;
listValues?: any[];
listValuesCount?: string;
isChecked?: boolean;
attachment_type?: StringEntry;
Expand All @@ -49,7 +49,7 @@ export default class SendMsgForm extends React.Component<
> {
constructor(props: ActionFormProps) {
super(props);
this.state = stateToForm(this.props.nodeSettings, this.props.assetStore);
this.state = stateToForm(this.props.nodeSettings);
bindCallbacks(this, {
include: [/^handle/, /^on/]
});
Expand Down Expand Up @@ -183,11 +183,11 @@ export default class SendMsgForm extends React.Component<
);
}

private handleAttachmentChanged(index: number, value: string): void {
private handleAttachmentChanged(index: number, id: string, label: string): void {
let { listValues }: any = this.state;
listValues = mutate(listValues, {
[index]: {
$set: { value }
$set: { value: { id, label } }
}
});

Expand All @@ -197,16 +197,28 @@ export default class SendMsgForm extends React.Component<
private renderListOptions(): JSX.Element {
const { listValues } = this.state;

const renderListOption = (value: any, index: number) => (
const renderListOption = ({ value }: any, index: number) => (
<div className={styles.listItem}>
<div className={styles.id}>
<TextInputElement
placeholder={`id ${index + 1}`}
name={i18n.t('forms.list_item_id', 'id')}
style={TextInputStyle.normal}
onChange={(id: string) => {
this.handleAttachmentChanged(index, id, value.label);
}}
entry={{ value: value.id }}
autocomplete={true}
/>
</div>
<TextInputElement
placeholder={`variable ${index + 1}`}
name={i18n.t('forms.list_item', 'variable')}
name={i18n.t('forms.list_item_variable', 'variable')}
style={TextInputStyle.normal}
onChange={(value: string) => {
this.handleAttachmentChanged(index, value);
onChange={(label: string) => {
this.handleAttachmentChanged(index, value.id, label);
}}
entry={value}
entry={{ value: value.label }}
autocomplete={true}
/>
</div>
Expand Down
11 changes: 4 additions & 7 deletions src/components/flow/actions/sendinteractivemsg/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import { ReactComponent as ButtonIcon } from './icons/button.svg';

import { SendInteractiveMsgFormState } from './SendInteractiveMsgForm';

export const initializeForm = (
settings: NodeEditorSettings,
assetStore: AssetStore
): SendInteractiveMsgFormState => {
export const initializeForm = (settings: NodeEditorSettings): SendInteractiveMsgFormState => {
if (settings.originalAction && settings.originalAction.type === Types.send_interactive_msg) {
const action = settings.originalAction as SendInteractiveMsg;
let { id, name, expression, params, paramsCount } = action;
Expand All @@ -34,7 +31,7 @@ export const initializeForm = (
: [];

while (listValues.length < 10) {
listValues.push({ value: '' });
listValues.push({ value: { id: '', label: '' } });
}

const returnValue: SendInteractiveMsgFormState = {
Expand Down Expand Up @@ -69,7 +66,7 @@ export const initializeForm = (
labels: {
value: []
},
listValues: Array(10).fill({ value: '' }),
listValues: Array(10).fill({ value: { id: '', label: '' } }),
valid: false,
listValuesCount: '',
attachment_url: { value: '' },
Expand All @@ -84,7 +81,7 @@ export const stateToAction = (
let result: any = {};

const params = state.listValues
.filter(listItem => listItem.value !== '')
.filter(listItem => listItem.value.label !== '')
.map(listItem => listItem.value);

const paramsCount = state.listValuesCount;
Expand Down

0 comments on commit 15ad8ed

Please sign in to comment.