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 <insert diff number>)

Reviewed By: jknoxville

Differential Revision: D21788244

fbshipit-source-id: 8fb8ecb8f8df84f4854f70432e7a1fdb531403e9
This commit is contained in:
Chaiwat Ekkaewnumchai
2020-06-02 01:44:21 -07:00
committed by Facebook GitHub Bot
parent df480bd57a
commit d6b617a952

View File

@@ -219,6 +219,7 @@ type PreviousPageEvent = {
type ExecuteEvent = { type ExecuteEvent = {
type: 'Execute'; type: 'Execute';
query: string;
}; };
type RefreshEvent = { type RefreshEvent = {
@@ -602,45 +603,38 @@ export default class DatabasesPlugin extends FlipperPlugin<
'Execute', 'Execute',
( (
state: DatabasesPluginState, state: DatabasesPluginState,
_results: ExecuteEvent, event: ExecuteEvent,
): DatabasesPluginState => { ): DatabasesPluginState => {
const timeBefore = Date.now(); const timeBefore = Date.now();
if ( const {query} = event;
this.state.query !== null && this.databaseClient
typeof this.state.query !== 'undefined' .getExecution({databaseId: state.selectedDatabase, value: query})
) { .then((data) => {
this.databaseClient this.setState({
.getExecution({ error: null,
databaseId: state.selectedDatabase, executionTime: Date.now() - timeBefore,
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});
}); });
} 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; let newHistory = this.state.queryHistory;
const newQuery = this.state.query; const newQuery = this.state.query;
if ( if (
@@ -964,7 +958,9 @@ export default class DatabasesPlugin extends FlipperPlugin<
}; };
onExecuteClicked = () => { onExecuteClicked = () => {
this.dispatchAction({type: 'Execute'}); if (this.state.query !== null) {
this.dispatchAction({type: 'Execute', query: this.state.query.value});
}
}; };
onQueryTextareaKeyPress = (event: KeyboardEvent) => { onQueryTextareaKeyPress = (event: KeyboardEvent) => {