@nyris/nyris-webapp 0.3.9 → 0.3.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/build/asset-manifest.json +11 -11
  2. package/build/index.html +1 -1
  3. package/build/{precache-manifest.a97813497ab8d37548141e5e2618d0dc.js → precache-manifest.1b00dd5c15aa0815244681503d6fa9da.js} +9 -9
  4. package/build/service-worker.js +1 -1
  5. package/build/static/css/main.0c9239ba.chunk.css +2 -0
  6. package/build/static/css/main.0c9239ba.chunk.css.map +1 -0
  7. package/build/static/js/2.520bb6d6.chunk.js +3 -0
  8. package/build/static/js/{2.6e13adbe.chunk.js.LICENSE.txt → 2.520bb6d6.chunk.js.LICENSE.txt} +0 -0
  9. package/build/static/js/2.520bb6d6.chunk.js.map +1 -0
  10. package/build/static/js/main.ef6a9744.chunk.js +2 -0
  11. package/build/static/js/main.ef6a9744.chunk.js.map +1 -0
  12. package/package.json +2 -2
  13. package/src/App.tsx +333 -188
  14. package/src/actions/nyrisAppActions.ts +69 -65
  15. package/src/actions/searchActions.ts +301 -195
  16. package/src/components/CategoryFilter.tsx +16 -13
  17. package/src/components/Codes.tsx +20 -16
  18. package/src/components/ExampleImages.tsx +27 -17
  19. package/src/components/Feedback.tsx +78 -48
  20. package/src/components/FiltersList.tsx +113 -58
  21. package/src/components/Header.tsx +29 -17
  22. package/src/components/PredictedCategories.tsx +15 -12
  23. package/src/components/Result.tsx +186 -113
  24. package/src/components/SelectedFiltersSummary.tsx +85 -0
  25. package/src/components/Sidebar.tsx +44 -34
  26. package/src/epics/index.ts +173 -104
  27. package/src/epics/search.ts +214 -139
  28. package/src/index.css +95 -6
  29. package/src/index.tsx +147 -145
  30. package/src/utils.ts +5 -0
  31. package/build/static/css/main.0481043c.chunk.css +0 -2
  32. package/build/static/css/main.0481043c.chunk.css.map +0 -1
  33. package/build/static/js/2.6e13adbe.chunk.js +0 -3
  34. package/build/static/js/2.6e13adbe.chunk.js.map +0 -1
  35. package/build/static/js/main.f5da7aa4.chunk.js +0 -2
  36. package/build/static/js/main.f5da7aa4.chunk.js.map +0 -1
@@ -1,76 +1,80 @@
1
- import {AppAction} from "../types";
2
-
3
-
4
- export type NyrisAppPart = 'start' | 'camera' | 'results';
5
- export type NyrisFeedbackState = 'hidden' | 'question' | 'positive' | 'negative';
1
+ import { AppAction } from "../types";
6
2
 
3
+ export type NyrisAppPart = "start" | "camera" | "results";
4
+ export type NyrisFeedbackState =
5
+ | "hidden"
6
+ | "question"
7
+ | "positive"
8
+ | "negative";
7
9
 
8
10
  export interface NyrisAppState {
9
- showPart: NyrisAppPart,
10
- feedbackState: NyrisFeedbackState
11
+ showPart: NyrisAppPart;
12
+ feedbackState: NyrisFeedbackState;
11
13
  }
12
14
 
13
15
  export type NyrisAction =
14
- | { type: 'SHOW_START' }
15
- | { type: 'SHOW_CAMERA' }
16
- | { type: 'SHOW_RESULTS' }
17
- | { type: 'SHOW_FEEDBACK' }
18
- | { type: 'HIDE_FEEDBACK' }
19
- | { type: 'RESULT_LINK_CLICKED', position: number, url: string}
20
- | { type: 'RESULT_IMAGE_CLICKED', position: number, url: string}
21
-
16
+ | { type: "SHOW_START" }
17
+ | { type: "SHOW_CAMERA" }
18
+ | { type: "SHOW_RESULTS" }
19
+ | { type: "SHOW_FEEDBACK" }
20
+ | { type: "HIDE_FEEDBACK" }
21
+ | { type: "RESULT_LINK_CLICKED"; position: number; url: string }
22
+ | { type: "RESULT_IMAGE_CLICKED"; position: number; url: string };
22
23
 
23
- export const showCamera = () :NyrisAction => ({type: 'SHOW_CAMERA'});
24
- export const showStart = () :NyrisAction => ({type: 'SHOW_START'});
25
- export const showResults = () :NyrisAction => ({type: 'SHOW_RESULTS'});
26
- export const showFeedback = () :NyrisAction => ({type: 'SHOW_FEEDBACK'});
27
- export const hideFeedback = () :NyrisAction => ({type: 'HIDE_FEEDBACK'});
24
+ export const showCamera = (): NyrisAction => ({ type: "SHOW_CAMERA" });
25
+ export const showStart = (): NyrisAction => ({ type: "SHOW_START" });
26
+ export const showResults = (): NyrisAction => ({ type: "SHOW_RESULTS" });
27
+ export const showFeedback = (): NyrisAction => ({ type: "SHOW_FEEDBACK" });
28
+ export const hideFeedback = (): NyrisAction => ({ type: "HIDE_FEEDBACK" });
28
29
 
29
- const initialNyrisState : NyrisAppState = {
30
- showPart: 'start',
31
- feedbackState: 'hidden'
30
+ const initialNyrisState: NyrisAppState = {
31
+ showPart: "start",
32
+ feedbackState: "hidden",
32
33
  };
33
34
 
34
- export function reducer(state : NyrisAppState = initialNyrisState, action: AppAction) : NyrisAppState {
35
- switch (action.type) {
36
- case 'SHOW_START':
37
- return {
38
- ...state,
39
- showPart: 'start'
40
- };
41
- case 'SHOW_CAMERA':
42
- return {
43
- ...state,
44
- showPart: 'camera'
45
- };
46
- case 'SEARCH_REQUEST_START':
47
- case 'REGION_REQUEST_START':
48
- case 'SHOW_RESULTS':
49
- return {
50
- ...state,
51
- showPart: 'results'
52
- };
53
- case 'SHOW_FEEDBACK':
54
- return {
55
- ...state,
56
- feedbackState: 'question'
57
- };
58
- case 'HIDE_FEEDBACK':
59
- return {
60
- ...state,
61
- feedbackState: 'hidden'
62
- };
63
- case 'FEEDBACK_SUBMIT_POSITIVE':
64
- return {
65
- ...state,
66
- feedbackState: 'positive'
67
- };
68
- case 'FEEDBACK_SUBMIT_NEGATIVE':
69
- return {
70
- ...state,
71
- feedbackState: 'negative'
72
- };
73
- default:
74
- return state;
75
- }
35
+ export function reducer(
36
+ state: NyrisAppState = initialNyrisState,
37
+ action: AppAction
38
+ ): NyrisAppState {
39
+ switch (action.type) {
40
+ case "SHOW_START":
41
+ return {
42
+ ...state,
43
+ showPart: "start",
44
+ };
45
+ case "SHOW_CAMERA":
46
+ return {
47
+ ...state,
48
+ showPart: "camera",
49
+ };
50
+ case "SEARCH_REQUEST_START":
51
+ case "REGION_REQUEST_START":
52
+ case "SHOW_RESULTS":
53
+ return {
54
+ ...state,
55
+ showPart: "results",
56
+ };
57
+ case "SHOW_FEEDBACK":
58
+ return {
59
+ ...state,
60
+ feedbackState: "question",
61
+ };
62
+ case "HIDE_FEEDBACK":
63
+ return {
64
+ ...state,
65
+ feedbackState: "hidden",
66
+ };
67
+ case "FEEDBACK_SUBMIT_POSITIVE":
68
+ return {
69
+ ...state,
70
+ feedbackState: "positive",
71
+ };
72
+ case "FEEDBACK_SUBMIT_NEGATIVE":
73
+ return {
74
+ ...state,
75
+ feedbackState: "negative",
76
+ };
77
+ default:
78
+ return state;
79
+ }
76
80
  }
@@ -1,217 +1,323 @@
1
- import {CanvasWithId} from "../types";
2
- import {Code, RectCoords, Region, selectFirstCenteredRegion,Filter} from '@nyris/nyris-api';
1
+ import { CanvasWithId } from "../types";
2
+ import {
3
+ Code,
4
+ RectCoords,
5
+ Region,
6
+ selectFirstCenteredRegion,
7
+ Filter,
8
+ } from "@nyris/nyris-api";
3
9
 
4
10
  export type ImageSourceType =
5
- | { url: string }
6
- | { file: File }
7
- | { image: HTMLCanvasElement }
11
+ | { url: string }
12
+ | { file: File }
13
+ | { image: HTMLCanvasElement };
8
14
 
9
15
  export type SearchAction =
10
- | { type: 'FEEDBACK_SUBMIT_POSITIVE' }
11
- | { type: 'FEEDBACK_SUBMIT_NEGATIVE' }
12
- | { type: 'IMAGE_LOADED', image: CanvasWithId, }
13
- | { type: 'REGION_REQUEST_START', image: HTMLCanvasElement }
14
- | { type: 'REGION_REQUEST_SUCCEED', regions: Region[] }
15
- | { type: 'REGION_REQUEST_FAIL', reason: string, exception: any }
16
- | { type: 'SEARCH_REQUEST_START', image: HTMLCanvasElement, normalizedRect?: RectCoords , selectedFilters?: Filter[] }
17
- | { type: 'SEARCH_REQUEST_START', file: File }
18
- | { type: 'SEARCH_REQUEST_SUCCEED', results: any[], requestId: string, duration: number, categoryPredictions: CategoryPrediction[], codes: Code[] }
19
- | { type: 'SEARCH_REQUEST_FAIL', reason: string, exception?: any }
20
- | { type: 'REGION_CHANGED', normalizedRect: RectCoords}
21
- | { type: 'LOAD_IMAGE'} & ImageSourceType
22
- | { type: 'LOAD_FILE', file: File}
23
- | { type: 'CAD_LOADED', file: File}
24
- | { type: 'LOAD_FILTERS'}
25
- | { type: 'LOAD_FILTERS_SUCCESS', filters: Filter[]}
26
- | { type: 'LOAD_FILTERS_FAIL', reason: string, exception: any}
27
- | { type: 'ADD_TO_SELECTEDFILTERS', key: string, value : string}
28
- | { type: 'REMOVE_FROM_SELECTEDFILTERS', key: string , value: string}
29
- | { type: 'CLEAR_SELECTED_FILTERS'}
30
-
16
+ | { type: "FEEDBACK_SUBMIT_POSITIVE" }
17
+ | { type: "FEEDBACK_SUBMIT_NEGATIVE" }
18
+ | { type: "IMAGE_LOADED"; image: CanvasWithId }
19
+ | { type: "REGION_REQUEST_START"; image: HTMLCanvasElement }
20
+ | { type: "REGION_REQUEST_SUCCEED"; regions: Region[] }
21
+ | { type: "REGION_REQUEST_FAIL"; reason: string; exception: any }
22
+ | {
23
+ type: "SEARCH_REQUEST_START";
24
+ image: HTMLCanvasElement;
25
+ normalizedRect?: RectCoords;
26
+ selectedFilters?: Filter[];
27
+ }
28
+ | { type: "SEARCH_REQUEST_START"; file: File }
29
+ | {
30
+ type: "SEARCH_REQUEST_SUCCEED";
31
+ results: any[];
32
+ requestId: string;
33
+ duration: number;
34
+ categoryPredictions: CategoryPrediction[];
35
+ codes: Code[];
36
+ }
37
+ | { type: "SEARCH_REQUEST_FAIL"; reason: string; exception?: any }
38
+ | { type: "REGION_CHANGED"; normalizedRect: RectCoords }
39
+ | ({ type: "LOAD_IMAGE" } & ImageSourceType)
40
+ | { type: "LOAD_FILE"; file: File }
41
+ | { type: "CAD_LOADED"; file: File }
42
+ | { type: "LOAD_FILTERS" }
43
+ | { type: "LOAD_FILTERS_SUCCESS"; filters: Filter[] }
44
+ | { type: "LOAD_FILTERS_FAIL"; reason: string; exception: any }
45
+ | { type: "ADD_TO_SELECTEDFILTERS"; key: string; value: string }
46
+ | { type: "REMOVE_FROM_SELECTEDFILTERS"; key: string; value: string }
47
+ | { type: "CLEAR_SELECTED_FILTERS" }
48
+ | { type: "SEARCH_FILTERS"; key: string; value: string }
49
+ | { type: "FILTER_CHANGED" }
50
+ | { type: "FILTER_CHANGED_FAIL" }
51
+ | { type: "CLEAR_REQUEST_IMAGE" }
52
+ | { type: "UPDATE_FILTERS"; key: string; values: string[] };
31
53
 
32
54
  interface CategoryPrediction {
33
- name: string,
34
- score: number
55
+ name: string;
56
+ score: number;
35
57
  }
36
58
 
37
59
  export interface SearchState {
38
- results: any[]
39
- duration?: number
40
- requestId?: string
41
- sessionId?: string
42
- regions: Region[]
43
- selectedRegion: RectCoords
44
- fetchingRegions: boolean
45
- fetchingResults: boolean
46
- filterOptions: string[]
47
- requestImage?: CanvasWithId
48
- requestCadFile?: File
49
- categoryPredictions: CategoryPrediction[]
50
- codes: Code[],
51
- errorMessage: string,
52
- filters:Filter[],
53
- selectedFilters: Map<string, string[]>
60
+ results: any[];
61
+ duration?: number;
62
+ requestId?: string;
63
+ sessionId?: string;
64
+ regions: Region[];
65
+ selectedRegion: RectCoords;
66
+ fetchingRegions: boolean;
67
+ fetchingResults: boolean;
68
+ filterOptions: string[];
69
+ requestImage?: CanvasWithId;
70
+ requestCadFile?: File;
71
+ categoryPredictions: CategoryPrediction[];
72
+ codes: Code[];
73
+ errorMessage: string;
74
+ filters: Filter[];
75
+ selectedFilters: Map<string, string[]>;
54
76
  }
55
77
 
56
- const initialState : SearchState = {
57
- results: [],
58
- regions: [],
59
- selectedRegion: {x1: 0.1, x2: 0.9, y1: 0.1, y2: 0.9},
60
- requestImage: undefined,
61
- fetchingResults: false,
62
- fetchingRegions: false,
63
- filterOptions: [],
64
- categoryPredictions: [],
65
- codes: [],
66
- errorMessage: '',
67
- filters: [],
68
- selectedFilters: new Map<string,string[]>()
78
+ const initialState: SearchState = {
79
+ results: [],
80
+ regions: [],
81
+ selectedRegion: { x1: 0.1, x2: 0.9, y1: 0.1, y2: 0.9 },
82
+ requestImage: undefined,
83
+ fetchingResults: false,
84
+ fetchingRegions: false,
85
+ filterOptions: [],
86
+ categoryPredictions: [],
87
+ codes: [],
88
+ errorMessage: "",
89
+ filters: [],
90
+ selectedFilters: new Map<string, string[]>(),
69
91
  };
70
92
 
71
-
72
- export const loadFile = (file: File ): SearchAction => ({ type: 'LOAD_FILE', file });
73
- export const loadUrl = (url: string): SearchAction => ({ type: 'LOAD_IMAGE', url });
74
- export const loadCanvas = (image: HTMLCanvasElement): SearchAction => ({ type: 'LOAD_IMAGE', image });
75
- export const imageLoaded = (image: HTMLCanvasElement, id: string): SearchAction => ({ type: 'IMAGE_LOADED', image: {canvas: image, id: id} });
76
- export const cadFileLoaded = (file: File, id: string): SearchAction => ({ type: 'CAD_LOADED', file});
77
- export const selectionChanged = (normalizedRect: RectCoords) : SearchAction => ({ type: 'REGION_CHANGED', normalizedRect });
78
- export const searchRegions = (image: HTMLCanvasElement): SearchAction => ({ type: 'REGION_REQUEST_START', image });
79
- export const searchOffersForImage = (image: HTMLCanvasElement, normalizedRect?: RectCoords, selectedFilters?: Filter[]) : SearchAction => ({
80
- type: 'SEARCH_REQUEST_START',
81
- image,
82
- normalizedRect,
83
- selectedFilters
93
+ export const loadFile = (file: File): SearchAction => ({
94
+ type: "LOAD_FILE",
95
+ file,
96
+ });
97
+ export const loadUrl = (url: string): SearchAction => ({
98
+ type: "LOAD_IMAGE",
99
+ url,
100
+ });
101
+ export const loadCanvas = (image: HTMLCanvasElement): SearchAction => ({
102
+ type: "LOAD_IMAGE",
103
+ image,
104
+ });
105
+ export const imageLoaded = (
106
+ image: HTMLCanvasElement,
107
+ id: string
108
+ ): SearchAction => ({ type: "IMAGE_LOADED", image: { canvas: image, id: id } });
109
+ export const cadFileLoaded = (file: File, id: string): SearchAction => ({
110
+ type: "CAD_LOADED",
111
+ file,
112
+ });
113
+ export const selectionChanged = (normalizedRect: RectCoords): SearchAction => ({
114
+ type: "REGION_CHANGED",
115
+ normalizedRect,
116
+ });
117
+ export const searchRegions = (image: HTMLCanvasElement): SearchAction => ({
118
+ type: "REGION_REQUEST_START",
119
+ image,
120
+ });
121
+ export const searchOffersForImage = (
122
+ image: HTMLCanvasElement,
123
+ normalizedRect?: RectCoords
124
+ ): SearchAction => ({
125
+ type: "SEARCH_REQUEST_START",
126
+ image,
127
+ normalizedRect,
84
128
  });
85
- export const searchOffersForCad = (file: File) : SearchAction => ({
86
- type: 'SEARCH_REQUEST_START',
87
- file
129
+ export const searchOffersForCad = (file: File): SearchAction => ({
130
+ type: "SEARCH_REQUEST_START",
131
+ file,
132
+ });
133
+ export const submitPositiveFeedback = (): SearchAction => ({
134
+ type: "FEEDBACK_SUBMIT_POSITIVE",
135
+ });
136
+ export const submitNegativeFeedback = (): SearchAction => ({
137
+ type: "FEEDBACK_SUBMIT_NEGATIVE",
138
+ });
139
+ export const loadFilters = (): SearchAction => ({ type: "LOAD_FILTERS" });
140
+ export const addToSelectedFilters = (
141
+ key: string,
142
+ value: string
143
+ ): SearchAction => ({ type: "ADD_TO_SELECTEDFILTERS", key, value });
144
+ export const removeFromSelectedFilters = (
145
+ key: string,
146
+ value: string
147
+ ): SearchAction => ({ type: "REMOVE_FROM_SELECTEDFILTERS", key, value });
148
+ export const clearAllSelectedFilters = () => ({
149
+ type: "CLEAR_SELECTED_FILTERS",
150
+ });
151
+ export const searchFilters = (key: string, value: string): SearchAction => ({
152
+ type: "SEARCH_FILTERS",
153
+ key,
154
+ value,
155
+ });
156
+ export const filterChanged = (): SearchAction => ({ type: "FILTER_CHANGED" });
157
+ export const clearRequestImage = (): SearchAction => ({
158
+ type: "CLEAR_REQUEST_IMAGE",
88
159
  });
89
- export const submitPositiveFeedback = () : SearchAction => ({ type: 'FEEDBACK_SUBMIT_POSITIVE'});
90
- export const submitNegativeFeedback = () : SearchAction => ({ type: 'FEEDBACK_SUBMIT_NEGATIVE'});
91
- export const loadFilters = (): SearchAction => ({type: 'LOAD_FILTERS'});
92
- export const addToSelectedFilters =(key: string , value: string): SearchAction => ({type : 'ADD_TO_SELECTEDFILTERS' , key , value});
93
- export const removeFromSelectedFilters = (key: string, value: string) : SearchAction => ({type: 'REMOVE_FROM_SELECTEDFILTERS', key, value});
94
- export const reducer = (state : SearchState = initialState, action: SearchAction) => {
95
- switch (action.type) {
96
- case "IMAGE_LOADED":
97
- let { image } = action;
98
- console.log('image', image)
99
- return {
100
- ...initialState,
101
- requestImage: image,
102
- selectedFilters: state.selectedFilters
103
160
 
104
- };
105
- case "CAD_LOADED":
106
- let { file } = action;
107
- return {
108
- ...initialState,
109
- requestCadFile: file
110
- }
111
- case 'REGION_REQUEST_START':
112
- return {
113
- ...state,
114
- fetchingRegions: true
115
- };
116
- case "REGION_REQUEST_SUCCEED":
117
- return {
118
- ...state,
119
- fetchingRegions: false,
120
- regions: action.regions,
121
- selectedRegion: selectFirstCenteredRegion(action.regions, 0.3, state.selectedRegion)
122
- };
123
- case "REGION_REQUEST_FAIL":
124
- return {
125
- ...state,
126
- fetchingRegions: false,
127
- errorMessage: action.exception.response.data.detail
128
- };
129
- case "SEARCH_REQUEST_START":
130
- return {
131
- ...state,
132
- fetchingResults: true
133
- };
134
- case "SEARCH_REQUEST_SUCCEED":
135
- let { results, requestId, duration, categoryPredictions, codes } = action;
136
- return {
137
- ...state,
138
- results,
139
- requestId,
140
- fetchingResults: false,
141
- sessionId: state.sessionId || requestId,
142
- categoryPredictions,
143
- codes,
144
- duration
145
- };
146
- case "SEARCH_REQUEST_FAIL":
147
- return {
148
- ...state,
149
- fetchingResults: false,
150
- errorMessage: action.reason
151
- };
152
- case "REGION_CHANGED":
153
- return {
154
- ...state,
155
- selectedRegion: action.normalizedRect
156
- };
157
- case "LOAD_FILTERS_SUCCESS":
158
- return {
159
- ...state,
160
- filters: action.filters
161
- };
162
- case "LOAD_FILTERS_FAIL":
163
- return {
164
- ...state,
165
- errorMessage: action.exception.response.data.detail
166
- }
167
- case "ADD_TO_SELECTEDFILTERS":
168
- return {
169
- ...state,
170
- selectedFilters : ADDtoSelectedfilters(state.selectedFilters, action.key, action.value)
171
- }
172
- case "REMOVE_FROM_SELECTEDFILTERS":
173
- return {
174
- ...state,
175
- selectedFilters : RemoveFromSelectedFilters(state.selectedFilters, action.key, action.value)
176
- }
177
- case "CLEAR_SELECTED_FILTERS":
178
- return {
179
- ...state,
180
- selectedFilters : new Map<string,string[]>()
181
- }
161
+ export const reducer = (
162
+ state: SearchState = initialState,
163
+ action: SearchAction
164
+ ) => {
165
+ switch (action.type) {
166
+ case "IMAGE_LOADED":
167
+ let { image } = action;
168
+ console.log("image", image);
169
+ return {
170
+ ...initialState,
171
+ requestImage: image,
172
+ selectedFilters: state.selectedFilters,
173
+ };
174
+ case "CAD_LOADED":
175
+ let { file } = action;
176
+ return {
177
+ ...initialState,
178
+ requestCadFile: file,
179
+ };
180
+ case "REGION_REQUEST_START":
181
+ return {
182
+ ...state,
183
+ fetchingRegions: true,
184
+ };
185
+ case "REGION_REQUEST_SUCCEED":
186
+ return {
187
+ ...state,
188
+ fetchingRegions: false,
189
+ regions: action.regions,
190
+ selectedRegion: selectFirstCenteredRegion(
191
+ action.regions,
192
+ 0.3,
193
+ state.selectedRegion
194
+ ),
195
+ };
196
+ case "REGION_REQUEST_FAIL":
197
+ return {
198
+ ...state,
199
+ fetchingRegions: false,
200
+ errorMessage: action.exception.response.data.detail,
201
+ };
202
+ case "SEARCH_REQUEST_START":
203
+ return {
204
+ ...state,
205
+ fetchingResults: true,
206
+ };
207
+ case "SEARCH_REQUEST_SUCCEED":
208
+ let { results, requestId, duration, categoryPredictions, codes } = action;
209
+ return {
210
+ ...state,
211
+ results,
212
+ requestId,
213
+ fetchingResults: false,
214
+ sessionId: state.sessionId || requestId,
215
+ categoryPredictions,
216
+ codes,
217
+ duration,
218
+ };
219
+ case "SEARCH_REQUEST_FAIL":
220
+ return {
221
+ ...state,
222
+ fetchingResults: false,
223
+ errorMessage: action.reason,
224
+ };
225
+ case "REGION_CHANGED":
226
+ return {
227
+ ...state,
228
+ selectedRegion: action.normalizedRect,
229
+ };
230
+ case "LOAD_FILTERS_SUCCESS":
231
+ return {
232
+ ...state,
233
+ filters: action.filters,
234
+ };
235
+ case "LOAD_FILTERS_FAIL":
236
+ return {
237
+ ...state,
238
+ errorMessage: action.exception.response.data.detail,
239
+ };
240
+ case "ADD_TO_SELECTEDFILTERS":
241
+ return {
242
+ ...state,
243
+ selectedFilters: ADDtoSelectedfilters(
244
+ state.selectedFilters,
245
+ action.key,
246
+ action.value
247
+ ),
248
+ };
249
+ case "REMOVE_FROM_SELECTEDFILTERS":
250
+ return {
251
+ ...state,
252
+ selectedFilters: RemoveFromSelectedFilters(
253
+ state.selectedFilters,
254
+ action.key,
255
+ action.value
256
+ ),
257
+ };
258
+ case "CLEAR_SELECTED_FILTERS":
259
+ return {
260
+ ...state,
261
+ selectedFilters: new Map<string, string[]>(),
262
+ };
263
+ case "CLEAR_REQUEST_IMAGE":
264
+ return {
265
+ ...state,
266
+ requestImage: undefined,
267
+ };
268
+ case "UPDATE_FILTERS":
269
+ return {
270
+ ...state,
271
+ filters: UpdateFilters(state.filters, action.key, action.values),
272
+ };
273
+ }
274
+ return state;
275
+ };
182
276
 
277
+ function ADDtoSelectedfilters(
278
+ selectedFilters: Map<string, string[]>,
279
+ key: string,
280
+ value: string
281
+ ): Map<string, string[]> {
282
+ if (selectedFilters) {
283
+ let values = selectedFilters.get(key);
284
+ if (values) {
285
+ values.push(value);
286
+ } else {
287
+ values = new Array<string>(value);
183
288
  }
184
- return state;
185
- };
289
+ selectedFilters.set(key, values);
290
+ }
291
+ console.log(selectedFilters);
292
+ return selectedFilters;
293
+ }
186
294
 
187
- function ADDtoSelectedfilters(selectedFilters: Map<string, string[]>, key: string, value: string): Map<string, string[]> {
188
- if(selectedFilters)
189
- {
190
- let values = selectedFilters.get(key);
191
- if (values){
192
- values.push(value);
193
- }
194
- else
195
- {
196
- values = new Array<string>(value);
197
- }
198
- selectedFilters.set(key, values);
199
- }
200
- console.log(selectedFilters);
201
- return selectedFilters;
295
+ function RemoveFromSelectedFilters(
296
+ selectedFilters: Map<string, string[]>,
297
+ key: string,
298
+ value: string
299
+ ): Map<string, string[]> {
300
+ if (selectedFilters) {
301
+ let values = selectedFilters.get(key);
302
+ if (values) {
303
+ values = values.filter((x) => x !== value);
304
+ selectedFilters.set(key, values);
305
+ }
306
+ }
307
+ console.log(selectedFilters);
308
+ return selectedFilters;
202
309
  }
203
310
 
204
- function RemoveFromSelectedFilters(selectedFilters: Map<string, string[]>, key: string, value: string): Map<string, string[]> {
205
- if(selectedFilters)
206
- {
207
- let values = selectedFilters.get(key);
208
- if (values)
209
- {
210
- values = values.filter(x => x!== value);
211
- selectedFilters.set(key, values);
212
- }
213
-
214
- }
215
- console.log(selectedFilters);
216
- return selectedFilters;
311
+ function UpdateFilters(filters: Filter[], key: string, values: string[]) {
312
+ console.log(filters);
313
+ console.log(key);
314
+ console.log(values);
315
+ console.log(filters.find((x) => x.key === key));
316
+ if (filters && filters.length > 0 && filters.find((x) => x.key === key)) {
317
+ let idx = filters.findIndex((x) => x.key === key);
318
+ filters[idx].values = values;
319
+ console.log(filters);
320
+ }
321
+
322
+ return filters;
217
323
  }