From 5bbf11ce33c3c01127bc2ecc798e7cff95942cd4 Mon Sep 17 00:00:00 2001 From: Mattermost Build Date: Thu, 4 Aug 2022 23:59:35 +0300 Subject: [PATCH] [MM-38103] initialize select fields with the value (#5640) (#6548) --- app/screens/apps_form/apps_form_field.tsx | 29 ++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/app/screens/apps_form/apps_form_field.tsx b/app/screens/apps_form/apps_form_field.tsx index 55ba20e2e..14b6cfafb 100644 --- a/app/screens/apps_form/apps_form_field.tsx +++ b/app/screens/apps_form/apps_form_field.tsx @@ -52,7 +52,34 @@ export default class AppsFormField extends React.PureComponent { constructor(props: Props) { super(props); - this.state = {}; + let selected; + switch (props.field.type) { + case AppFieldTypes.STATIC_SELECT: + case AppFieldTypes.DYNAMIC_SELECT: + case AppFieldTypes.USER: + case AppFieldTypes.CHANNEL: { + const value = props.value as AppSelectOption[] | AppSelectOption | null; + if (value) { + if (Array.isArray(value)) { + selected = value.map((option) => { + return { + text: option.label, + value: option.value, + }; + }); + } else { + selected = { + text: value.label, + value: value.value, + }; + } + } + } + } + + this.state = { + selected, + }; } handleAutocompleteSelect = (selected: DialogOption) => {