[MM-38103] initialize select fields with the value (#5640) (#6548)

This commit is contained in:
Mattermost Build 2022-08-04 23:59:35 +03:00 committed by GitHub
parent 8e26b4b2b5
commit 5bbf11ce33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -52,7 +52,34 @@ export default class AppsFormField extends React.PureComponent<Props, State> {
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) => {