Skip to content

Commit

Permalink
fixing small clear state issues
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Sebastian <[email protected]>
  • Loading branch information
paulstn committed Oct 3, 2023
1 parent a33ae31 commit d70de7c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ export interface CreateAccelerationForm {
formErrors: FormErrorsType;
}

export type AsyncQueryLoadingStatus = "SUCCESS" | "FAILED" | "RUNNING" | "SCHEDULED | CANCELED"
export type AsyncQueryLoadingStatus = "SUCCESS" | "FAILED" | "RUNNING" | "SCHEDULED" | "CANCELED"
41 changes: 27 additions & 14 deletions public/components/Main/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -449,16 +449,28 @@ export class Main extends React.Component<MainProps, MainState> {

const queryId: string = _.get(responseObj, 'queryId');

// clear state from previous results and start async loading
this.setState({
queryTranslations: [],
queryResultsTable: [],
queryResults: [],
queryResultsCSV: [],
queryResultsJSON: [],
queryResultsTEXT: [],
messages: [],
selectedTabId: MESSAGE_TAB_LABEL,
selectedTabName: MESSAGE_TAB_LABEL,
itemIdToExpandedRowMap: {},
asyncLoading: true,
asyncLoadingStatus: 'SCHEDULED',
asyncJobId: queryId,
});
this.callGetStartPolling(queries);
const interval = setInterval(() => {
console.log('interval iteration');
if (!this.state.asyncLoading) {
clearInterval(interval);
}
this.callGetStartPolling(queries, queryId);
this.callGetStartPolling(queries);
}, 2 * 1000);
}
}
Expand All @@ -467,18 +479,20 @@ export class Main extends React.Component<MainProps, MainState> {
}
};

callGetStartPolling = async (queries: string[], jobId: string) => {
callGetStartPolling = async (queries: string[]) => {
const nextP = Promise.all([
this.httpClient.get('/api/spark_sql_console/get/' + jobId).catch((error: any) => {
this.setState({
messages: [
{
text: error.message,
className: 'error-message',
},
],
});
}),
this.httpClient
.get('/api/spark_sql_console/get/' + this.state.asyncJobId)
.catch((error: any) => {
this.setState({
messages: [
{
text: error.message,
className: 'error-message',
},
],
});
}),
]);

return await Promise.all([nextP]).then(([response]) => {
Expand All @@ -504,7 +518,6 @@ export class Main extends React.Component<MainProps, MainState> {
asyncLoadingStatus: status,
});
} else if (_.isEqual(status, 'FAILED') || _.isEqual(status, 'CANCELLED')) {
console.log('fail or cancel');
this.setState({
asyncLoading: false,
asyncLoadingStatus: status,
Expand Down

0 comments on commit d70de7c

Please sign in to comment.