Skip to content

Commit

Permalink
Nit
Browse files Browse the repository at this point in the history
  • Loading branch information
stratoula committed Nov 13, 2024
1 parent 497d247 commit 2099375
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/kbn-esql-editor/src/history_local_storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ const sortDates = (date1?: string, date2?: string) => {
export const getHistoryItems = (sortDirection: 'desc' | 'asc'): QueryHistoryItem[] => {
const localStorageString = localStorage.getItem(QUERY_HISTORY_ITEM_KEY) ?? '[]';
const historyItems: QueryHistoryItem[] = JSON.parse(localStorageString);

// for backwards compatibility
historyItems.forEach((item) => {
item.timeRan = item.timeRan ? new Date(item.timeRan).toISOString() : undefined;
});

const sortedByDate = historyItems.sort((a, b) => {
return sortDirection === 'desc'
? sortDates(b.timeRan, a.timeRan)
Expand All @@ -60,11 +66,7 @@ export const addQueriesToCache = (
const queries = getHistoryItems('desc');
queries.forEach((queryItem) => {
const trimmedQueryString = getTrimmedQuery(queryItem.queryString);
const updatedQueryItem = {
...queryItem,
timeRan: queryItem.timeRan ? new Date(queryItem.timeRan).toISOString() : undefined,
};
cachedQueries.set(trimmedQueryString, updatedQueryItem);
cachedQueries.set(trimmedQueryString, queryItem);
});
const trimmedQueryString = getTrimmedQuery(item.queryString);

Expand Down

0 comments on commit 2099375

Please sign in to comment.