From 3770f618ab073fbac6654c9edcc4b53a1e010fea Mon Sep 17 00:00:00 2001 From: Alex Collins Date: Mon, 14 Sep 2020 09:05:04 -0700 Subject: [PATCH] fix(ui): Report errors when uploading files. Fixes #3994 (#3995) --- .../shared/components/resource-editor/resource-editor.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ui/src/app/shared/components/resource-editor/resource-editor.tsx b/ui/src/app/shared/components/resource-editor/resource-editor.tsx index b7918827a572..baac615b1f6b 100644 --- a/ui/src/app/shared/components/resource-editor/resource-editor.tsx +++ b/ui/src/app/shared/components/resource-editor/resource-editor.tsx @@ -31,7 +31,7 @@ const LOCAL_STORAGE_KEY = 'ResourceEditorLang'; export class ResourceEditor extends React.Component, State> { private set lang(lang: string) { try { - this.setState({lang, error: null, value: stringify(parse(this.state.value), lang)}); + this.setState(state => ({lang, error: null, value: stringify(parse(state.value), lang)})); } catch (error) { this.setState({error}); } @@ -84,14 +84,15 @@ export class ResourceEditor extends React.Component, State> { public componentDidUpdate(prevProps: Props) { if (prevProps.value !== this.props.value) { - this.setState({value: stringify(this.props.value, this.state.lang)}); + this.setState(state => ({value: stringify(this.props.value, state.lang)})); } } public handleFiles(files: FileList) { files[0] .text() - .then(value => this.setState({error: null, value: stringify(parse(value), this.state.lang)})) + .then(value => stringify(parse(value), this.state.lang)) + .then(value => this.setState({error: null, value})) .catch(error => this.setState(error)); }