Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] UI fixes for loading state, empty tree, added toast for error, fixed no indicies error #177

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions common/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,6 @@ export const POLL_INTERVAL_MS = 2000;
export const ASYNC_QUERY_ENDPOINT = '/api/spark_sql_console';
export const ASYNC_QUERY_JOB_ENDPOINT = ASYNC_QUERY_ENDPOINT + '/job/';
export const ASYNC_QUERY_SESSION_ID = 'async-query-session-id';

export const SAMPLE_PPL_QUERY = 'source = <datasource>.<database>.<table> | head 10';
export const SAMPLE_SQL_QUERY = 'select * from <datasource>.<database>.<table> limit 10';
37 changes: 37 additions & 0 deletions common/toast/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { ToastInputFields } from '../../../../src/core/public';
import { coreRefs } from '../../public/framework/core_refs';

type Color = 'success' | 'primary' | 'warning' | 'danger' | undefined;

export const useToast = () => {
const toasts = coreRefs.toasts!;

const setToast = (title: string, color: Color = 'success', text?: string) => {
const newToast: ToastInputFields = {
id: new Date().toISOString(),
title,
text,
};
switch (color) {
case 'danger': {
toasts.addDanger(newToast);
break;
}
case 'warning': {
toasts.addWarning(newToast);
break;
}
default: {
toasts.addSuccess(newToast);
break;
}
}
};

return { setToast };
};
5 changes: 3 additions & 2 deletions common/utils/async_query_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ export const pollQueryStatus = (id: string, http: CoreStart['http'], callback) =
callback({ status: status });
setTimeout(() => pollQueryStatus(id, http, callback), POLL_INTERVAL_MS);
} else if (status === 'failed') {
callback({ status: 'FAILED', results: [] });
const results = res.data.resp;
callback({ status: 'FAILED', error: results.error });
} else if (status === 'success') {
const results = _.get(res.data.resp, 'datarows');
callback({ status: 'SUCCESS', results: results });
}
})
.catch((err) => {
console.error(err);
callback([]);
callback({ status: 'FAILED', error: 'Failed to fetch data' });
});
};
Loading
Loading