Skip to content

Commit

Permalink
Fix ordering lost when the user refreshes the browser
Browse files Browse the repository at this point in the history
  • Loading branch information
stratoula committed Jul 13, 2022
1 parent 1cb55f1 commit 1d40c5d
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
import { useMemo, useEffect, useState, useCallback } from 'react';
import { isEqual } from 'lodash';
import { History } from 'history';
import { isOfAggregateQueryType, getIndexPatternFromSQLQuery } from '@kbn/es-query';
import {
isOfAggregateQueryType,
getIndexPatternFromSQLQuery,
AggregateQuery,
Query,
} from '@kbn/es-query';
import { getState } from '../services/discover_state';
import { getStateDefaults } from '../utils/get_state_defaults';
import { DiscoverServices } from '../../../build_services';
Expand Down Expand Up @@ -74,6 +79,7 @@ export function useDiscoverState({

const [state, setState] = useState(appStateContainer.getState());
const [documentStateCols, setDocumentStateCols] = useState<string[]>([]);
const [sqlQuery] = useState<AggregateQuery | Query | undefined>(state.query);

/**
* Search session logic
Expand Down Expand Up @@ -247,13 +253,13 @@ export function useDiscoverState({
if (documentState.result?.length) {
const firstRow = documentState.result[0];
const columns = Object.keys(firstRow.raw).slice(0, MAX_NUM_OF_COLUMNS);
if (!isEqual(columns, documentStateCols)) {
return Object.keys(firstRow.raw).slice(0, MAX_NUM_OF_COLUMNS);
if (!isEqual(columns, documentStateCols) && !isEqual(state.query, sqlQuery)) {
return columns;
}
return [];
}
return [];
}, [documentState.result, documentStateCols]);
}, [documentState.result, documentStateCols, sqlQuery, state.query]);

useEffect(() => {
async function fetchDataview() {
Expand Down

0 comments on commit 1d40c5d

Please sign in to comment.