@@ -14,32 +14,26 @@ import HistoryQuery from './HistoryQuery';
14
14
const MAX_QUERY_SIZE = 100000 ;
15
15
const MAX_HISTORY_LENGTH = 20 ;
16
16
17
- const shouldSaveQuery = ( nextProps , current , lastQuerySaved ) => {
18
- if ( nextProps . queryID === current . queryID ) {
19
- return false ;
20
- }
17
+ const shouldSaveQuery = ( query , variables , lastQuerySaved ) => {
21
18
try {
22
- parse ( nextProps . query ) ;
19
+ parse ( query ) ;
23
20
} catch ( e ) {
24
21
return false ;
25
22
}
26
23
// Don't try to save giant queries
27
- if ( nextProps . query . length > MAX_QUERY_SIZE ) {
24
+ if ( query . length > MAX_QUERY_SIZE ) {
28
25
return false ;
29
26
}
30
27
if ( ! lastQuerySaved ) {
31
28
return true ;
32
29
}
33
- if (
34
- JSON . stringify ( nextProps . query ) === JSON . stringify ( lastQuerySaved . query )
35
- ) {
30
+ if ( JSON . stringify ( query ) === JSON . stringify ( lastQuerySaved . query ) ) {
36
31
if (
37
- JSON . stringify ( nextProps . variables ) ===
38
- JSON . stringify ( lastQuerySaved . variables )
32
+ JSON . stringify ( variables ) === JSON . stringify ( lastQuerySaved . variables )
39
33
) {
40
34
return false ;
41
35
}
42
- if ( ! nextProps . variables && ! lastQuerySaved . variables ) {
36
+ if ( variables && ! lastQuerySaved . variables ) {
43
37
return false ;
44
38
}
45
39
}
@@ -71,25 +65,6 @@ export class QueryHistory extends React.Component {
71
65
this . state = { queries } ;
72
66
}
73
67
74
- componentWillReceiveProps ( nextProps ) {
75
- if (
76
- shouldSaveQuery ( nextProps , this . props , this . historyStore . fetchRecent ( ) )
77
- ) {
78
- const item = {
79
- query : nextProps . query ,
80
- variables : nextProps . variables ,
81
- operationName : nextProps . operationName ,
82
- } ;
83
- this . historyStore . push ( item ) ;
84
- const historyQueries = this . historyStore . items ;
85
- const favoriteQueries = this . favoriteStore . items ;
86
- const queries = historyQueries . concat ( favoriteQueries ) ;
87
- this . setState ( {
88
- queries,
89
- } ) ;
90
- }
91
- }
92
-
93
68
render ( ) {
94
69
const queries = this . state . queries . slice ( ) . reverse ( ) ;
95
70
const queryNodes = queries . map ( ( query , i ) => {
@@ -114,6 +89,22 @@ export class QueryHistory extends React.Component {
114
89
) ;
115
90
}
116
91
92
+ updateHistory = ( query , variables , operationName ) => {
93
+ if ( shouldSaveQuery ( query , variables , this . historyStore . fetchRecent ( ) ) ) {
94
+ this . historyStore . push ( {
95
+ query,
96
+ variables,
97
+ operationName,
98
+ } ) ;
99
+ const historyQueries = this . historyStore . items ;
100
+ const favoriteQueries = this . favoriteStore . items ;
101
+ const queries = historyQueries . concat ( favoriteQueries ) ;
102
+ this . setState ( {
103
+ queries,
104
+ } ) ;
105
+ }
106
+ } ;
107
+
117
108
toggleFavorite = ( query , variables , operationName , label , favorite ) => {
118
109
const item = {
119
110
query,
0 commit comments