@nyris/nyris-webapp 0.3.9 → 0.3.14
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.
- package/build/asset-manifest.json +11 -11
- package/build/index.html +1 -1
- package/build/js/settings.example.js +30 -0
- package/build/{precache-manifest.a97813497ab8d37548141e5e2618d0dc.js → precache-manifest.fa9930c6ba4e9fb0ebad3869127ef308.js} +9 -9
- package/build/service-worker.js +1 -1
- package/build/static/css/main.6633770c.chunk.css +2 -0
- package/build/static/css/main.6633770c.chunk.css.map +1 -0
- package/build/static/js/2.0798bb8b.chunk.js +3 -0
- package/build/static/js/{2.6e13adbe.chunk.js.LICENSE.txt → 2.0798bb8b.chunk.js.LICENSE.txt} +0 -0
- package/build/static/js/2.0798bb8b.chunk.js.map +1 -0
- package/build/static/js/main.31212715.chunk.js +2 -0
- package/build/static/js/main.31212715.chunk.js.map +1 -0
- package/package.json +2 -2
- package/public/js/settings.example.js +30 -0
- package/src/App.tsx +221 -203
- package/src/actions/nyrisAppActions.ts +69 -65
- package/src/actions/searchActions.ts +288 -196
- package/src/components/FiltersList.tsx +106 -57
- package/src/components/Header.tsx +29 -17
- package/src/components/SelectedFiltersSummary.tsx +84 -0
- package/src/components/Sidebar.tsx +41 -34
- package/src/epics/index.ts +128 -108
- package/src/epics/search.ts +114 -82
- package/src/index.css +95 -6
- package/src/index.tsx +89 -95
- package/src/utils.ts +5 -0
- package/build/static/css/main.0481043c.chunk.css +0 -2
- package/build/static/css/main.0481043c.chunk.css.map +0 -1
- package/build/static/js/2.6e13adbe.chunk.js +0 -3
- package/build/static/js/2.6e13adbe.chunk.js.map +0 -1
- package/build/static/js/main.f5da7aa4.chunk.js +0 -2
- package/build/static/js/main.f5da7aa4.chunk.js.map +0 -1
|
@@ -1,217 +1,309 @@
|
|
|
1
|
-
import {CanvasWithId} from "../types";
|
|
2
|
-
import {
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
11
|
+
| { url: string }
|
|
12
|
+
| { file: File }
|
|
13
|
+
| { image: HTMLCanvasElement };
|
|
8
14
|
|
|
9
15
|
export type SearchAction =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
34
|
-
|
|
55
|
+
name: string;
|
|
56
|
+
score: number;
|
|
35
57
|
}
|
|
36
58
|
|
|
37
59
|
export interface SearchState {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
73
|
-
|
|
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,
|
|
84
96
|
});
|
|
85
|
-
export const
|
|
86
|
-
|
|
87
|
-
|
|
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,
|
|
128
|
+
});
|
|
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
|
-
|
|
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
|
-
}
|
|
182
160
|
|
|
183
|
-
|
|
184
|
-
|
|
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;
|
|
185
275
|
};
|
|
186
276
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
values = new Array<string>(value);
|
|
197
|
-
}
|
|
198
|
-
selectedFilters.set(key, values);
|
|
199
|
-
}
|
|
200
|
-
console.log(selectedFilters);
|
|
201
|
-
return selectedFilters;
|
|
277
|
+
function ADDtoSelectedfilters(
|
|
278
|
+
selectedFilters: Map<string, string[]>,
|
|
279
|
+
key: string,
|
|
280
|
+
value: string
|
|
281
|
+
): Map<string, string[]> {
|
|
282
|
+
let values = selectedFilters.get(key) || new Array<string>();
|
|
283
|
+
values.push(value);
|
|
284
|
+
selectedFilters.set(key, values);
|
|
285
|
+
return selectedFilters;
|
|
202
286
|
}
|
|
203
287
|
|
|
204
|
-
function RemoveFromSelectedFilters(
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
288
|
+
function RemoveFromSelectedFilters(
|
|
289
|
+
selectedFilters: Map<string, string[]>,
|
|
290
|
+
key: string,
|
|
291
|
+
value: string
|
|
292
|
+
): Map<string, string[]> {
|
|
293
|
+
let values = selectedFilters.get(key);
|
|
294
|
+
if (values) {
|
|
295
|
+
values = values.filter((x) => x !== value);
|
|
296
|
+
selectedFilters.set(key, values);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
return selectedFilters;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function UpdateFilters(filters: Filter[], key: string, values: string[]) {
|
|
303
|
+
if (filters && filters.length > 0 && filters.find((x) => x.key === key)) {
|
|
304
|
+
let idx = filters.findIndex((x) => x.key === key);
|
|
305
|
+
filters[idx].values = values;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return filters;
|
|
217
309
|
}
|
|
@@ -1,67 +1,116 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import React, { useEffect, useState } from "react";
|
|
2
|
+
import { Filter } from "@nyris/nyris-api";
|
|
3
|
+
import {
|
|
4
|
+
addToSelectedFilters,
|
|
5
|
+
removeFromSelectedFilters,
|
|
6
|
+
filterChanged,
|
|
7
|
+
searchFilters,
|
|
8
|
+
} from "../actions/searchActions";
|
|
9
|
+
import { useDispatch } from "react-redux";
|
|
10
|
+
import { RiArrowDropUpLine, RiArrowDropDownLine } from "react-icons/ri";
|
|
11
|
+
import { capitalizeFirstLetter } from "../utils";
|
|
12
|
+
import { AiOutlineSearch } from "react-icons/ai";
|
|
7
13
|
|
|
8
14
|
interface FilterProps {
|
|
9
|
-
|
|
10
|
-
|
|
15
|
+
filter: Filter;
|
|
16
|
+
selectedValues?: string[];
|
|
11
17
|
}
|
|
12
18
|
|
|
19
|
+
const FiltersList: React.FC<FilterProps> = ({ filter, selectedValues }) => {
|
|
20
|
+
const dispatch = useDispatch();
|
|
21
|
+
const [isCollapsed, setIsCollapsed] = useState(false);
|
|
22
|
+
const [searchInp, setSearchInp] = useState("");
|
|
23
|
+
const handleToggler = () => {
|
|
24
|
+
if (isCollapsed) {
|
|
25
|
+
setIsCollapsed(false);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
setIsCollapsed(true);
|
|
29
|
+
};
|
|
30
|
+
const onFilterChanged = (
|
|
31
|
+
e: React.ChangeEvent<HTMLInputElement>,
|
|
32
|
+
value: string
|
|
33
|
+
) => {
|
|
34
|
+
if (e.target.checked) {
|
|
35
|
+
if (filter.key) dispatch(addToSelectedFilters(filter.key, value));
|
|
36
|
+
} else {
|
|
37
|
+
if (filter.key) dispatch(removeFromSelectedFilters(filter.key, value));
|
|
38
|
+
}
|
|
39
|
+
dispatch(filterChanged());
|
|
40
|
+
};
|
|
13
41
|
|
|
42
|
+
const handleChangeOnSearchInputTyped = (
|
|
43
|
+
e: React.ChangeEvent<HTMLInputElement>
|
|
44
|
+
) => {
|
|
45
|
+
setSearchInp(e.target.value);
|
|
46
|
+
};
|
|
14
47
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const onFilterChanged=(e: React.ChangeEvent<HTMLInputElement>,value:string) =>{
|
|
19
|
-
if (e.target.checked) {
|
|
20
|
-
if(filter.key)
|
|
21
|
-
dispatch(addToSelectedFilters(filter.key , value));
|
|
22
|
-
} else {
|
|
23
|
-
if(filter.key)
|
|
24
|
-
dispatch(removeFromSelectedFilters(filter.key, value));
|
|
25
|
-
}
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (searchInp === "") {
|
|
50
|
+
dispatch(searchFilters(filter.key!, ""));
|
|
26
51
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return (
|
|
31
|
-
<div>
|
|
32
|
-
<div className='item'>
|
|
33
|
-
<RiLayoutGridLine className="sidebar-icon" />
|
|
34
|
-
<span className="sidebar-text"> {filter.key}</span>
|
|
35
|
-
</div>
|
|
36
|
-
|
|
37
|
-
<div className='item'>
|
|
38
|
-
<div className="list-container">
|
|
39
|
-
|
|
40
|
-
{filter.values.slice(0, 6).map((item, index) => {
|
|
41
|
-
const checked = selectedValues && selectedValues.includes(item);
|
|
42
|
-
return (
|
|
43
|
-
|
|
44
|
-
<div key={index}>
|
|
45
|
-
|
|
46
|
-
<input value={item} checked={checked ? true: false} type="checkbox" onChange={(e)=>onFilterChanged(e,item)} />
|
|
47
|
-
<label className='itemLabel'>{item}</label>
|
|
48
|
-
</div>
|
|
49
|
-
)
|
|
50
|
-
})}
|
|
51
|
-
</div>
|
|
52
|
-
</div>
|
|
53
|
-
|
|
54
|
-
</div>
|
|
55
|
-
|
|
56
|
-
);
|
|
52
|
+
if (searchInp.length > 3) {
|
|
53
|
+
dispatch(searchFilters(filter.key!, searchInp));
|
|
57
54
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
}, [searchInp, filter.key, dispatch]);
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<div>
|
|
59
|
+
<div className="item">
|
|
60
|
+
<span className="sidebar-text">
|
|
61
|
+
{capitalizeFirstLetter(filter.key!)}
|
|
62
|
+
</span>
|
|
63
|
+
<RiArrowDropUpLine
|
|
64
|
+
className={
|
|
65
|
+
isCollapsed ? "sidebar-icon" : "sidebar-icon collapsedHide"
|
|
66
|
+
}
|
|
67
|
+
onClick={() => handleToggler()}
|
|
68
|
+
/>
|
|
69
|
+
<RiArrowDropDownLine
|
|
70
|
+
className={
|
|
71
|
+
isCollapsed ? "sidebar-icon collapsedHide" : "sidebar-icon"
|
|
72
|
+
}
|
|
73
|
+
onClick={() => handleToggler()}
|
|
74
|
+
/>
|
|
75
|
+
</div>
|
|
76
|
+
|
|
77
|
+
<div
|
|
78
|
+
className={
|
|
79
|
+
isCollapsed ? "list-container" : "list-container collapsedHide"
|
|
80
|
+
}
|
|
81
|
+
>
|
|
82
|
+
<div className="searchBar">
|
|
83
|
+
<input
|
|
84
|
+
id="searchQueryInput"
|
|
85
|
+
name="searchQueryInput"
|
|
86
|
+
placeholder="Search"
|
|
87
|
+
value={searchInp}
|
|
88
|
+
onChange={(e) => handleChangeOnSearchInputTyped(e)}
|
|
89
|
+
/>
|
|
90
|
+
<button id="searchQuerySubmit" type="submit" name="searchQuerySubmit">
|
|
91
|
+
<AiOutlineSearch />
|
|
92
|
+
</button>
|
|
93
|
+
</div>
|
|
94
|
+
{filter &&
|
|
95
|
+
filter.values &&
|
|
96
|
+
filter.values.length > 0 &&
|
|
97
|
+
filter.values.map((item, index) => {
|
|
98
|
+
const checked = selectedValues && selectedValues.includes(item);
|
|
99
|
+
return (
|
|
100
|
+
<div key={index}>
|
|
101
|
+
<input
|
|
102
|
+
value={item}
|
|
103
|
+
checked={checked ? true : false}
|
|
104
|
+
type="checkbox"
|
|
105
|
+
onChange={(e) => onFilterChanged(e, item)}
|
|
106
|
+
/>
|
|
107
|
+
<span className="itemLabel">{item}</span>
|
|
108
|
+
</div>
|
|
109
|
+
);
|
|
110
|
+
})}
|
|
111
|
+
</div>
|
|
112
|
+
</div>
|
|
63
113
|
);
|
|
64
|
-
|
|
65
|
-
}
|
|
114
|
+
};
|
|
66
115
|
|
|
67
|
-
export default FiltersList;
|
|
116
|
+
export default FiltersList;
|