From 73a377b82190d3b33a331fe16843d4bd123c2173 Mon Sep 17 00:00:00 2001 From: moonbreeze Date: Wed, 6 Dec 2023 13:20:54 +0300 Subject: [PATCH] fix(query-tracker): dynamic system columns' content is now displayed correctly [#192] --- .../src/ui/pages/query-tracker/module/api.ts | 27 ++++++++++++++++--- .../module/query_result/actions.ts | 4 +++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/packages/ui/src/ui/pages/query-tracker/module/api.ts b/packages/ui/src/ui/pages/query-tracker/module/api.ts index b0f4e1291..70d5df14b 100644 --- a/packages/ui/src/ui/pages/query-tracker/module/api.ts +++ b/packages/ui/src/ui/pages/query-tracker/module/api.ts @@ -277,18 +277,37 @@ type QueryResult = { yql_type_registry: TypeArray[]; }; +type QueryResultRows = QueryResult['rows']; +type QueryResultRowSet = QueryResultRows[number]; + +/** + * Format limitations dictate system column names being prefixed by double dollar sign instead + * of a single on, here we just replace the stuff + */ +const mapQueryRowNames = (rows: QueryResultRows) => { + const replaceReg = /^\$\$/; + const replaceRows = (rowSet: QueryResultRowSet) => + Object.keys(rowSet).reduce( + (result, next) => ({...result, [next.replace(replaceReg, '$')]: rowSet[next]}), + {} as QueryResultRowSet, + ); + + return rows.map(replaceRows); +}; + export function readQueryResults( query_id: string, result_index = 0, cursor: {start: number; end: number}, + columns: string[], settings: { cellsSize: number; }, ): ThunkAction, RootState, any, any> { - return (_dispatch, getState) => { + return async (_dispatch, getState) => { const state = getState(); const {stage} = getQueryTrackerRequestOptions(state); - return ytApiV4Id.readQueryResults(YTApiId.readQueryResults, { + const result = (await ytApiV4Id.readQueryResults(YTApiId.readQueryResults, { parameters: { stage, query_id, @@ -298,6 +317,7 @@ export function readQueryResults( output_format: { $value: 'web_json', $attributes: { + column_names: columns, value_format: 'yql', field_weight_limit: settings?.cellsSize, encode_utf8: 'false', @@ -306,7 +326,8 @@ export function readQueryResults( }, }, setup: getQTApiSetup(), - }); + })) as QueryResult; + return {...result, rows: mapQueryRowNames(result.rows)}; }; } diff --git a/packages/ui/src/ui/pages/query-tracker/module/query_result/actions.ts b/packages/ui/src/ui/pages/query-tracker/module/query_result/actions.ts index 86b08858b..e1d9245ac 100644 --- a/packages/ui/src/ui/pages/query-tracker/module/query_result/actions.ts +++ b/packages/ui/src/ui/pages/query-tracker/module/query_result/actions.ts @@ -149,6 +149,7 @@ export function loadQueryResult( start: 0, end: settings.pageSize, }, + columns.map(({name}) => name), {cellsSize: settings.cellSize}, ), ), @@ -205,6 +206,8 @@ export function updateQueryResult( const startPage = page * settings.pageSize; const endPage = startPage + settings.pageSize; + const cols = + (await dispatch(getQueryResultMeta(queryId, resultIndex)))?.schema.$value ?? []; const result = await wrapApiPromiseByToaster( dispatch( readQueryResults( @@ -214,6 +217,7 @@ export function updateQueryResult( start: page * settings.pageSize, end: endPage, }, + cols.map(({name}) => name), {cellsSize: settings.cellSize}, ), ),