1
1
import { createRequestActionTypes , createApiRequest } from '../utils' ;
2
2
import '../../services/api' ;
3
+ import { getValueFromLS , parseJson } from '../../utils/utils' ;
4
+ import { QUERIES_HISTORY_KEY } from '../../utils/constants' ;
5
+
6
+ const MAXIMUM_QUERIES_IN_HISTORY = 20 ;
3
7
4
8
const SEND_QUERY = createRequestActionTypes ( 'query' , 'SEND_QUERY' ) ;
5
9
const CHANGE_USER_INPUT = 'query/CHANGE_USER_INPUT' ;
@@ -9,6 +13,10 @@ const GO_TO_NEXT_QUERY = 'query/GO_TO_NEXT_QUERY';
9
13
const SELECT_RUN_ACTION = 'query/SELECT_RUN_ACTION' ;
10
14
const MONACO_HOT_KEY = 'query/MONACO_HOT_KEY' ;
11
15
16
+ const queriesHistoryInitial = parseJson ( getValueFromLS ( QUERIES_HISTORY_KEY , [ ] ) ) ;
17
+
18
+ const sliceLimit = queriesHistoryInitial . length - MAXIMUM_QUERIES_IN_HISTORY ;
19
+
12
20
export const RUN_ACTIONS_VALUES = {
13
21
script : 'execute-script' ,
14
22
scan : 'execute-scan' ,
@@ -25,7 +33,7 @@ const initialState = {
25
33
loading : false ,
26
34
input : '' ,
27
35
history : {
28
- queries : [ ] ,
36
+ queries : queriesHistoryInitial . slice ( sliceLimit < 0 ? 0 : sliceLimit ) ,
29
37
currentIndex : - 1 ,
30
38
} ,
31
39
runAction : RUN_ACTIONS_VALUES . script ,
@@ -76,7 +84,10 @@ const executeQuery = (state = initialState, action) => {
76
84
77
85
case SAVE_QUERY_TO_HISTORY : {
78
86
const query = action . data ;
79
- const newQueries = [ ...state . history . queries , query ] ;
87
+ const newQueries = [ ...state . history . queries , query ] . slice (
88
+ state . history . queries . length >= MAXIMUM_QUERIES_IN_HISTORY ? 1 : 0 ,
89
+ ) ;
90
+ window . localStorage . setItem ( QUERIES_HISTORY_KEY , JSON . stringify ( newQueries ) ) ;
80
91
const currentIndex = newQueries . length - 1 ;
81
92
82
93
return {
0 commit comments