From d6b617a9526be4a192301d834658abc2bec487b1 Mon Sep 17 00:00:00 2001 From: Chaiwat Ekkaewnumchai Date: Tue, 2 Jun 2020 01:44:21 -0700 Subject: [PATCH] Change Execute Action Parameter Summary: `'Execute'` action was previously used only for execute tab which assumed the input will come from the state. This changes so that it can take any input attached to parameters (more explanation about the design in ) Reviewed By: jknoxville Differential Revision: D21788244 fbshipit-source-id: 8fb8ecb8f8df84f4854f70432e7a1fdb531403e9 --- desktop/plugins/databases/index.tsx | 70 ++++++++++++++--------------- 1 file changed, 33 insertions(+), 37 deletions(-) diff --git a/desktop/plugins/databases/index.tsx b/desktop/plugins/databases/index.tsx index d31385656..f85e5ba04 100644 --- a/desktop/plugins/databases/index.tsx +++ b/desktop/plugins/databases/index.tsx @@ -219,6 +219,7 @@ type PreviousPageEvent = { type ExecuteEvent = { type: 'Execute'; + query: string; }; type RefreshEvent = { @@ -602,45 +603,38 @@ export default class DatabasesPlugin extends FlipperPlugin< 'Execute', ( state: DatabasesPluginState, - _results: ExecuteEvent, + event: ExecuteEvent, ): DatabasesPluginState => { const timeBefore = Date.now(); - if ( - this.state.query !== null && - typeof this.state.query !== 'undefined' - ) { - this.databaseClient - .getExecution({ - databaseId: state.selectedDatabase, - value: this.state.query.value, - }) - .then((data) => { - this.setState({ - error: null, - executionTime: Date.now() - timeBefore, - }); - if (data.type === 'select') { - this.dispatchAction({ - type: 'DisplaySelect', - columns: data.columns, - values: data.values, - }); - } else if (data.type === 'insert') { - this.dispatchAction({ - type: 'DisplayInsert', - id: data.insertedId, - }); - } else if (data.type === 'update_delete') { - this.dispatchAction({ - type: 'DisplayUpdateDelete', - count: data.affectedCount, - }); - } - }) - .catch((e) => { - this.setState({error: e}); + const {query} = event; + this.databaseClient + .getExecution({databaseId: state.selectedDatabase, value: query}) + .then((data) => { + this.setState({ + error: null, + executionTime: Date.now() - timeBefore, }); - } + if (data.type === 'select') { + this.dispatchAction({ + type: 'DisplaySelect', + columns: data.columns, + values: data.values, + }); + } else if (data.type === 'insert') { + this.dispatchAction({ + type: 'DisplayInsert', + id: data.insertedId, + }); + } else if (data.type === 'update_delete') { + this.dispatchAction({ + type: 'DisplayUpdateDelete', + count: data.affectedCount, + }); + } + }) + .catch((e) => { + this.setState({error: e}); + }); let newHistory = this.state.queryHistory; const newQuery = this.state.query; if ( @@ -964,7 +958,9 @@ export default class DatabasesPlugin extends FlipperPlugin< }; onExecuteClicked = () => { - this.dispatchAction({type: 'Execute'}); + if (this.state.query !== null) { + this.dispatchAction({type: 'Execute', query: this.state.query.value}); + } }; onQueryTextareaKeyPress = (event: KeyboardEvent) => {