mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Reversed history direction for explore
- _.reverse() was modifying state.history
This commit is contained in:
parent
eaff7b0f68
commit
cda3b01781
@ -289,10 +289,10 @@ export class Explore extends React.Component<any, IExploreState> {
|
||||
const ts = Date.now();
|
||||
queries.forEach(q => {
|
||||
const { query } = q;
|
||||
history = [...history, { query, ts }];
|
||||
history = [{ query, ts }, ...history];
|
||||
});
|
||||
if (history.length > MAX_HISTORY_ITEMS) {
|
||||
history = history.slice(history.length - MAX_HISTORY_ITEMS);
|
||||
history = history.slice(0, MAX_HISTORY_ITEMS);
|
||||
}
|
||||
// Combine all queries of a datasource type into one history
|
||||
const historyKey = `grafana.explore.history.${datasourceId}`;
|
||||
|
@ -35,7 +35,7 @@ export function addHistoryMetadata(item: Suggestion, history: any[]): Suggestion
|
||||
const cutoffTs = Date.now() - HISTORY_COUNT_CUTOFF;
|
||||
const historyForItem = history.filter(h => h.ts > cutoffTs && h.query === item.label);
|
||||
const count = historyForItem.length;
|
||||
const recent = historyForItem.pop();
|
||||
const recent = historyForItem[0];
|
||||
let hint = `Queried ${count} times in the last 24h.`;
|
||||
if (recent) {
|
||||
const lastQueried = moment(recent.ts).fromNow();
|
||||
@ -189,11 +189,10 @@ class PromQueryField extends React.Component<PromQueryFieldProps, PromQueryField
|
||||
if (history && history.length > 0) {
|
||||
const historyItems = _.chain(history)
|
||||
.uniqBy('query')
|
||||
.takeRight(HISTORY_ITEM_COUNT)
|
||||
.take(HISTORY_ITEM_COUNT)
|
||||
.map(h => h.query)
|
||||
.map(wrapLabel)
|
||||
.map(item => addHistoryMetadata(item, history))
|
||||
.reverse()
|
||||
.value();
|
||||
|
||||
suggestions.push({
|
||||
|
Loading…
Reference in New Issue
Block a user