From 607b01c2aa3625b165eed789dbf000cd046b92ce Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 8 Nov 2023 21:09:06 +0000 Subject: [PATCH] Revert "Support dark mode and session for sql, minor bug fixes (#165) (#169)" This reverts commit 0f5673ab4911f1ce9fc75eb2865aa52c1cf70200. --- common/constants/index.ts | 10 +- common/utils/async_query_helpers.ts | 62 ---- public/ace-themes/sql_console.js | 19 + .../Main/__snapshots__/main.test.tsx.snap | 63 ++-- public/components/Main/main.tsx | 17 +- public/components/PPLPage/PPLPage.tsx | 9 +- .../__snapshots__/PPLPage.test.tsx.snap | 12 +- .../components/QueryResults/QueryResults.tsx | 2 +- .../QueryResults/QueryResultsBody.tsx | 43 ++- .../QueryResultsBody.test.tsx.snap | 348 +++++++++--------- public/components/SQLPage/SQLPage.tsx | 10 +- .../__snapshots__/SQLPage.test.tsx.snap | 16 +- public/components/SQLPage/table_view.tsx | 12 +- public/components/SQLPage/utils.tsx | 51 +++ .../selectors/index_type_selector.tsx | 2 +- .../selectors/source_selector.tsx | 2 +- public/index.scss | 142 +++++++ public/index.ts | 3 + public/utils/PanelWrapper.tsx | 20 +- webpack.config.js | 43 +++ 20 files changed, 529 insertions(+), 357 deletions(-) delete mode 100644 common/utils/async_query_helpers.ts create mode 100644 public/ace-themes/sql_console.js create mode 100644 public/components/SQLPage/utils.tsx create mode 100644 public/index.scss create mode 100644 webpack.config.js diff --git a/common/constants/index.ts b/common/constants/index.ts index 0f78c810..db990084 100644 --- a/common/constants/index.ts +++ b/common/constants/index.ts @@ -16,7 +16,7 @@ export const TREE_ITEM_MATERIALIZED_VIEW_DEFAULT_NAME = `materialized_view`; export const TREE_ITEM_DATABASE_NAME_DEFAULT_NAME = `database`; export const TREE_ITEM_TABLE_NAME_DEFAULT_NAME = `table`; export const TREE_ITEM_LOAD_MATERIALIZED_BADGE_NAME = `Load Materialized View`; -export const TREE_ITEM_BADGE_NAME = `badge`; +export const TREE_ITEM_BADGE_NAME =`badge` export const LOAD_OPENSEARCH_INDICES_QUERY = `SHOW tables LIKE '%';`; export const SKIPPING_INDEX_QUERY = `CREATE SKIPPING INDEX ON myS3.logs_db.http_logs (status VALUE_SET) @@ -89,8 +89,6 @@ export const ACCELERATION_INDEX_NAME_INFO = `All OpenSearch acceleration indices - All user given index names must be in lowercase letters. Index name cannot begin with underscores. Spaces, commas, and characters -, :, ", *, +, /, \, |, ?, #, >, or < are not allowed. `; -export const FETCH_OPENSEARCH_INDICES_PATH = '/api/sql_console/sqlquery'; -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 SIDEBAR_POLL_INTERVAL_MS = 5000; + +export const FETCH_OPENSEARCH_INDICES_PATH = '/api/sql_console/sqlquery' \ No newline at end of file diff --git a/common/utils/async_query_helpers.ts b/common/utils/async_query_helpers.ts deleted file mode 100644 index 689727b3..00000000 --- a/common/utils/async_query_helpers.ts +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import _ from 'lodash'; -import { CoreStart } from '../../../../src/core/public'; -import { - ASYNC_QUERY_ENDPOINT, - ASYNC_QUERY_JOB_ENDPOINT, - ASYNC_QUERY_SESSION_ID, - POLL_INTERVAL_MS, -} from '../constants'; - -export const setAsyncSessionId = (value: string | null) => { - if (value === null) sessionStorage.removeItem(ASYNC_QUERY_SESSION_ID); - else sessionStorage.setItem(ASYNC_QUERY_SESSION_ID, value); -}; - -export const getAsyncSessionId = () => { - return sessionStorage.getItem(ASYNC_QUERY_SESSION_ID); -}; - -export const getJobId = (query: {}, http: CoreStart['http'], callback) => { - http - .post(ASYNC_QUERY_ENDPOINT, { - body: JSON.stringify({ ...query, sessionId: getAsyncSessionId() ?? undefined }), - }) - .then((res) => { - const id = res.data.resp.queryId; - setAsyncSessionId(_.get(res.data.resp, 'sessionId', null)); - callback(id); - }) - .catch((err) => { - console.error(err); - }); -}; - -export const pollQueryStatus = (id: string, http: CoreStart['http'], callback) => { - http - .get(ASYNC_QUERY_JOB_ENDPOINT + id) - .then((res) => { - const status = res.data.resp.status.toLowerCase(); - if ( - status === 'pending' || - status === 'running' || - status === 'scheduled' || - status === 'waiting' - ) { - setTimeout(() => pollQueryStatus(id, http, callback), POLL_INTERVAL_MS); - } else if (status === 'failed') { - callback([]); - } else if (status === 'success') { - const results = _.get(res.data.resp, 'datarows'); - callback(results); - } - }) - .catch((err) => { - console.error(err); - callback([]); - }); -}; diff --git a/public/ace-themes/sql_console.js b/public/ace-themes/sql_console.js new file mode 100644 index 00000000..b0d4898c --- /dev/null +++ b/public/ace-themes/sql_console.js @@ -0,0 +1,19 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import * as ace from 'brace'; + +ace.define('ace/theme/sql_console', ['require', 'exports', 'module', 'ace/lib/dom'], function ( + acequire, + exports, + module +) { + exports.isDark = false; + exports.cssClass = 'ace-sql-console'; + exports.cssText = require('../index.scss'); + + const dom = acequire('../lib/dom'); + dom.importCssString(exports.cssText, exports.cssClass); +}); diff --git a/public/components/Main/__snapshots__/main.test.tsx.snap b/public/components/Main/__snapshots__/main.test.tsx.snap index f34fea4e..6d65fd66 100644 --- a/public/components/Main/__snapshots__/main.test.tsx.snap +++ b/public/components/Main/__snapshots__/main.test.tsx.snap @@ -296,7 +296,7 @@ exports[`
spec click clear button 1`] = ` />
spec click clear button 1`] = `