Skip to content

Commit

Permalink
Add empty tree state for SQL sidebar (#292) (#294)
Browse files Browse the repository at this point in the history
* add empty tree and copy update



* update release notes



* add cancel query fix



---------


(cherry picked from commit d052907)

Signed-off-by: Shenoy Pratik <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 7dda568 commit e409f07
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 447 deletions.
107 changes: 55 additions & 52 deletions common/utils/async_query_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const executeAsyncQuery = (
) => {
let jobId: string | undefined;
let isQueryFulfilled = false;
let isQueryCancelled = false;
const http = coreRefs.http!;

const getJobId = () => {
Expand Down Expand Up @@ -73,67 +74,69 @@ export const executeAsyncQuery = (
};

const pollQueryStatus = (id: string, callback: PollingCallback) => {
http
.get(ASYNC_QUERY_JOB_ENDPOINT + id)
.then((res: AsyncApiResponse) => {
const status = res.data.resp.status.toLowerCase();
const errorDetailsMessage = res.data.resp.error ?? '';
switch (status) {
case AsyncQueryStatus.Pending:
case AsyncQueryStatus.Running:
case AsyncQueryStatus.Scheduled:
case AsyncQueryStatus.Waiting:
callback({ ...res });
setTimeout(() => pollQueryStatus(id, callback), POLL_INTERVAL_MS);
break;
!isQueryCancelled &&
http
.get(ASYNC_QUERY_JOB_ENDPOINT + id)
.then((res: AsyncApiResponse) => {
const status = res.data.resp.status.toLowerCase();
const errorDetailsMessage = res.data.resp.error ?? '';
switch (status) {
case AsyncQueryStatus.Pending:
case AsyncQueryStatus.Running:
case AsyncQueryStatus.Scheduled:
case AsyncQueryStatus.Waiting:
callback({ ...res });
setTimeout(() => pollQueryStatus(id, callback), POLL_INTERVAL_MS);
break;

case AsyncQueryStatus.Failed:
case AsyncQueryStatus.Cancelled:
isQueryFulfilled = true;
case AsyncQueryStatus.Failed:
case AsyncQueryStatus.Cancelled:
isQueryFulfilled = true;

if (status === AsyncQueryStatus.Failed) {
RaiseErrorToast({
errorToastMessage: 'Query failed',
errorDetailsMessage,
});
}
if (onErrorCallback) {
onErrorCallback(errorDetailsMessage);
}
callback({ ...res });
break;
if (status === AsyncQueryStatus.Failed) {
RaiseErrorToast({
errorToastMessage: 'Query failed',
errorDetailsMessage,
});
}
if (onErrorCallback) {
onErrorCallback(errorDetailsMessage);
}
callback({ ...res });
break;

case AsyncQueryStatus.Success:
isQueryFulfilled = true;
callback({ ...res });
break;
case AsyncQueryStatus.Success:
isQueryFulfilled = true;
callback({ ...res });
break;

default:
console.error('Unrecognized status:', status);
RaiseErrorToast({
errorToastMessage: 'Unrecognized status recieved',
errorDetailsMessage: 'Unrecognized status recieved - ' + errorDetailsMessage,
});
if (onErrorCallback) {
onErrorCallback(errorDetailsMessage);
}
callback({ ...res });
}
})
.catch((err) => {
console.error('Error occurred while polling query status:', err);
isQueryFulfilled = true;
callback({
data: {
ok: true,
resp: { status: AsyncQueryStatus.Failed, error: 'Failed to query status' },
},
default:
console.error('Unrecognized status:', status);
RaiseErrorToast({
errorToastMessage: 'Unrecognized status recieved',
errorDetailsMessage: 'Unrecognized status recieved - ' + errorDetailsMessage,
});
if (onErrorCallback) {
onErrorCallback(errorDetailsMessage);
}
callback({ ...res });
}
})
.catch((err) => {
console.error('Error occurred while polling query status:', err);
isQueryFulfilled = true;
callback({
data: {
ok: true,
resp: { status: AsyncQueryStatus.Failed, error: 'Failed to query status' },
},
});
});
});
};

const cancelQuery = () => {
if (jobId && !isQueryFulfilled) {
isQueryCancelled = true;
http.delete(ASYNC_QUERY_JOB_ENDPOINT + jobId).catch((err) => {
console.error('Error occurred while cancelling query:', err);
RaiseErrorToast({
Expand Down
Loading

0 comments on commit e409f07

Please sign in to comment.