From c76c659d22ad76aed3e8972a496ecb0c65064b70 Mon Sep 17 00:00:00 2001 From: sadakchap Date: Wed, 16 Oct 2024 13:41:27 +0530 Subject: [PATCH 1/4] allow only csv & json to be selected for import --- src/dashboard/Data/Browser/ImportDialog.react.js | 2 +- src/dashboard/Data/Browser/ImportRelationDialog.react.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dashboard/Data/Browser/ImportDialog.react.js b/src/dashboard/Data/Browser/ImportDialog.react.js index ed627d0a98..c97b36f835 100644 --- a/src/dashboard/Data/Browser/ImportDialog.react.js +++ b/src/dashboard/Data/Browser/ImportDialog.react.js @@ -58,7 +58,7 @@ export default class ImportDialog extends React.Component { input={
{this.setState({ file: file });}} /> + onChange={(file) => {this.setState({ file: file });}} accept=".csv,.json" />
} /> diff --git a/src/dashboard/Data/Browser/ImportRelationDialog.react.js b/src/dashboard/Data/Browser/ImportRelationDialog.react.js index 141daac315..67604101c5 100644 --- a/src/dashboard/Data/Browser/ImportRelationDialog.react.js +++ b/src/dashboard/Data/Browser/ImportRelationDialog.react.js @@ -71,7 +71,7 @@ export default class ImportRelationDialog extends React.Component { input={
{this.setState({ file: file });}} /> + onChange={(file) => {this.setState({ file: file });}} accept=".csv,.json" />
} /> From a0626f9f0dde18638a3f9f2d89c41be839553b28 Mon Sep 17 00:00:00 2001 From: sadakchap Date: Wed, 16 Oct 2024 15:04:59 +0530 Subject: [PATCH 2/4] update export format to import format --- src/dashboard/Data/Browser/Browser.react.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/dashboard/Data/Browser/Browser.react.js b/src/dashboard/Data/Browser/Browser.react.js index ba7d1ec8c6..336dd531c1 100644 --- a/src/dashboard/Data/Browser/Browser.react.js +++ b/src/dashboard/Data/Browser/Browser.react.js @@ -2049,14 +2049,16 @@ class Browser extends DashboardView { const element = document.createElement('a'); const file = new Blob( [ - JSON.stringify( - objects.map(obj => { + JSON.stringify({ + results: objects.map(obj => { const json = obj._toFullJSON(); delete json.__type; + delete json.className return json; - }), - null, - indentation ? 2 : null + }) + }, + null, + indentation ? 2 : null ), ], { type: 'application/json' } From 509d1200a92d3a5d57b4e69dceadb53afe3e6a14 Mon Sep 17 00:00:00 2001 From: sadakchap Date: Wed, 16 Oct 2024 15:18:19 +0530 Subject: [PATCH 3/4] show import success response --- src/dashboard/Data/Browser/Browser.react.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/dashboard/Data/Browser/Browser.react.js b/src/dashboard/Data/Browser/Browser.react.js index 336dd531c1..7c8197b498 100644 --- a/src/dashboard/Data/Browser/Browser.react.js +++ b/src/dashboard/Data/Browser/Browser.react.js @@ -787,13 +787,16 @@ class Browser extends DashboardView { importClass(className, file) { return this.context.importData(className, file) .then((res) => { - return res; + return res.json(); }, (error) => { console.log(error); return Promise.resolve({ error: true, message: error.message }); + }).then(data => { + this.showNote(data.response); + return data; }); } From 31621572fc6fffe81ec9eaedb2211ff6373b0aca Mon Sep 17 00:00:00 2001 From: sadakchap Date: Wed, 16 Oct 2024 15:30:14 +0530 Subject: [PATCH 4/4] fix: show action message & clean state --- src/dashboard/Data/Browser/Browser.react.js | 6 ++---- .../Data/Browser/ImportDialog.react.js | 20 +++++++++---------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/dashboard/Data/Browser/Browser.react.js b/src/dashboard/Data/Browser/Browser.react.js index 7c8197b498..2b1e18692d 100644 --- a/src/dashboard/Data/Browser/Browser.react.js +++ b/src/dashboard/Data/Browser/Browser.react.js @@ -787,16 +787,13 @@ class Browser extends DashboardView { importClass(className, file) { return this.context.importData(className, file) .then((res) => { - return res.json(); + return res; }, (error) => { console.log(error); return Promise.resolve({ error: true, message: error.message }); - }).then(data => { - this.showNote(data.response); - return data; }); } @@ -2525,6 +2522,7 @@ class Browser extends DashboardView { this.setState({ showImportDialog: false })} + showNote={this.showNote} onConfirm={(file) => this.importClass(className, file)} /> ); } else if (this.state.showImportRelationDialog) { diff --git a/src/dashboard/Data/Browser/ImportDialog.react.js b/src/dashboard/Data/Browser/ImportDialog.react.js index c97b36f835..78e4f2372f 100644 --- a/src/dashboard/Data/Browser/ImportDialog.react.js +++ b/src/dashboard/Data/Browser/ImportDialog.react.js @@ -15,12 +15,11 @@ import Label from 'components/Label/Label.react'; export default class ImportDialog extends React.Component { constructor() { - super(); - this.state = { - file: undefined, - startedImport: false, - errorMessage: null - }; + super(); + this.state = { + file: undefined, + startedImport: false + }; } valid() { @@ -41,14 +40,17 @@ export default class ImportDialog extends React.Component { disabled={!this.valid()} onCancel={this.props.onCancel} onConfirm={() => { + this.setState({ startedImport: true }) this.props.onConfirm(this.state.file) .then((res) => { if (res.error) { this.setState({ errorMessage: res.message }); + this.props.showNote(`Import Request failed with the following error: "${res.error }".`) } else { this.props.onCancel(); + this.props.showNote('We are importing your data. You will be notified by e-mail once it is completed.') } - }); + }).finally(() => this.setState({ startedImport: false, file: undefined })); }}> } /> - {this.state.startedImport ? -
We are importing your data. You will be notified by e-mail once it is completed.
: null } - {this.state.errorMessage ? -
Import Request failed with the following error: "{ this.state.errorMessage }".
: null } );