@abi-software/map-side-bar 2.5.3-beta.1 → 2.5.3-beta.11

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.
@@ -1,114 +1,33 @@
1
1
  <template>
2
- <div class="history-container" v-if="searchHistory.length">
3
- <div class="saved-search-history" v-if="savedSearchHistory.length">
4
- <template v-for="(item, i) in savedSearchHistory">
5
- <el-tag
6
- class="search-tag"
7
- v-if="i < 2"
8
- v-bind:key="i"
9
- @click="search(item)"
10
- size="large"
11
- >
12
- <template v-if="item.longLabel">
13
- <el-popover
14
- width="auto"
15
- trigger="hover"
16
- popper-class="popover-dropdown"
17
- >
18
- <template #reference>
19
- {{ item.label }}
20
- </template>
21
- {{ item.longLabel }}
22
- </el-popover>
23
- </template>
24
- <template v-else>
25
- {{ item.label }}
26
- </template>
27
- </el-tag>
28
- </template>
29
- </div>
30
- <div v-else>
31
- <span class="empty-saved-search">No Saved Searches</span>
32
- </div>
33
- <el-dropdown trigger="click" :max-height="350" :hide-on-click="false">
34
- <span class="el-dropdown-select">
35
- Search history
36
- <el-icon class="el-icon--right">
37
- <el-icon-arrow-down />
38
- </el-icon>
39
- </span>
40
- <template #dropdown>
41
- <el-dropdown-menu>
42
- <el-dropdown-item v-for="(item, i) in searchHistory">
43
- <div>
44
- <template v-if="item.longLabel">
45
- <el-popover
46
- width="auto"
47
- trigger="hover"
48
- popper-class="popover-dropdown"
49
- >
50
- <template #reference>
51
- {{ item.label }}
52
- </template>
53
- {{ item.longLabel }}
54
- </el-popover>
55
- </template>
56
- <template v-else>
57
- {{ item.label }}
58
- </template>
59
- </div>
60
- <div>
61
- <el-popover
62
- width="auto"
63
- trigger="hover"
64
- :teleported="true"
65
- :show-after="100"
66
- popper-class="popover-dropdown"
67
- >
68
- <template #reference>
69
- <el-button circle text size="small"
70
- @click="toggleSavedSearch(item)"
71
- :disabled="savedSearchHistory.length > 1 && !item.saved"
72
- >
73
- <el-icon color="#8300BF">
74
- <el-icon-star-filled v-if="item.saved" />
75
- <el-icon-star v-else />
76
- </el-icon>
77
- </el-button>
78
- </template>
79
- <span v-if="savedSearchHistory.length > 1 && !item.saved">
80
- Please unsave one before adding another.
81
- </span>
82
- <span v-else-if="item.saved">
83
- Remove from saved searches.
84
- </span>
85
- <span v-else>
86
- Add up to two saved searches.
87
- </span>
88
- </el-popover>
89
- <el-popover
90
- width="auto"
91
- trigger="hover"
92
- :teleported="true"
93
- :show-after="100"
94
- popper-class="popover-dropdown"
95
- >
96
- <template #reference>
97
- <el-button circle text size="small" @click="removeFromSavedSearch(item)">
98
- <el-icon color="#8300BF">
99
- <el-icon-delete />
100
- </el-icon>
101
- </el-button>
102
- </template>
103
- <span>
104
- Remove from search history.
105
- </span>
106
- </el-popover>
107
- </div>
108
- </el-dropdown-item>
109
- </el-dropdown-menu>
110
- </template>
111
- </el-dropdown>
2
+ <div class="history-container">
3
+ <!-- <span v-if="reversedSearchHistory.length > 0" class="title"> Search History </span> -->
4
+ <template v-for="(item, i) in reversedSearchHistory">
5
+ <el-tag
6
+ class="search-tag"
7
+ v-if="i < 3"
8
+ v-bind:key="i"
9
+ @click="search(item)"
10
+ size="large"
11
+ >
12
+ {{ item.search }}
13
+ </el-tag>
14
+ </template>
15
+ <el-select
16
+ v-if="reversedSearchHistory.length > 0"
17
+ :model-value="selectValue"
18
+ class="m-2 search-select"
19
+ placeholder="Full search History"
20
+ popper-class="sidebar-search-select-popper"
21
+ @change="selectChange"
22
+ :teleported="false"
23
+ >
24
+ <el-option
25
+ v-for="(item, i) in cascaderOptions"
26
+ :key="i"
27
+ :label="item.label"
28
+ :value="item.value"
29
+ />
30
+ </el-select>
112
31
  </div>
113
32
  </template>
114
33
 
@@ -116,25 +35,16 @@
116
35
  /* eslint-disable no-alert, no-console */
117
36
  import {
118
37
  ElTag as Tag,
119
- ElSelect as Select,
120
- ElDropdown as Dropdown,
121
- ElIcon as Icon,
38
+ ElSelect as Select
122
39
  } from 'element-plus'
123
40
 
124
41
  import EventBus from './EventBus.js'
125
42
 
126
- function generateUUID() {
127
- const arr = new Uint8Array(16);
128
- window.crypto.getRandomValues(arr);
129
-
130
- arr[6] = (arr[6] & 0x0f) | 0x40;
131
- arr[8] = (arr[8] & 0x3f) | 0x80;
132
-
133
- const hex = Array.from(arr)
134
- .map(byte => byte.toString(16).padStart(2, '0'))
135
- .join('');
136
-
137
- return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
43
+ // remove duplicates by stringifying the objects
44
+ const removeDuplicates = function (arrayOfAnything) {
45
+ return [...new Set(arrayOfAnything.map((e) => JSON.stringify(e)))].map((e) =>
46
+ JSON.parse(e)
47
+ )
138
48
  }
139
49
 
140
50
  export default {
@@ -146,16 +56,26 @@ export default {
146
56
  data() {
147
57
  return {
148
58
  searchHistory: [],
149
- savedSearchHistory: [],
59
+ selectValue: 'Full search history',
150
60
  }
151
61
  },
152
- mounted: function () {
153
- this.getSearchHistory()
154
- EventBus.on('search-changed', (data) => {
155
- this.setSearchHistory(data)
156
- });
157
- this.updateSearchHistory();
158
- this.savedSearchHistory = this.searchHistory.filter((item) => item.saved);
62
+ computed: {
63
+ reversedSearchHistory: function () {
64
+ return removeDuplicates(
65
+ this.searchHistory
66
+ .slice()
67
+ .reverse()
68
+ .filter((item) => item.search !== '')
69
+ )
70
+ },
71
+ cascaderOptions: function () {
72
+ return this.reversedSearchHistory.map((item) => {
73
+ return {
74
+ value: item.search,
75
+ label: item.search,
76
+ }
77
+ })
78
+ },
159
79
  },
160
80
  methods: {
161
81
  getSearchHistory() {
@@ -171,160 +91,58 @@ export default {
171
91
  localStorage.removeItem('sparc.science-sidebar-search-history')
172
92
  this.searchHistory = []
173
93
  },
174
- addSearchToHistory(filters = [], search = '') {
94
+ addSearchToHistory(filters, search) {
95
+ filters = [] // disable filters for now
175
96
  search = search.trim() // remove whitespace
176
-
177
- const isExistingItem = this.searchHistory.some((item) => (
178
- item.search === search &&
179
- JSON.stringify(item.filters) === JSON.stringify(filters)
180
- ));
181
-
182
- if (!isExistingItem) {
183
- const {label, longLabel} = this.searchHistoryItemLabel(search, filters);
184
- const newItem = {
185
- filters: filters,
186
- search: search,
187
- saved: false,
188
- label: label,
189
- longLabel: longLabel,
190
- id: generateUUID(),
191
- updated: (new Date()).getTime(),
192
- };
193
-
194
- this.searchHistory.push(newItem);
195
-
196
- // Save new data
97
+ let searchHistory = JSON.parse(
98
+ localStorage.getItem('sparc.science-sidebar-search-history')
99
+ )
100
+ if (searchHistory) {
101
+ searchHistory.push({ filters: filters, search: search })
102
+ this.searchHistory = removeDuplicates(searchHistory)
197
103
  localStorage.setItem(
198
104
  'sparc.science-sidebar-search-history',
199
- JSON.stringify(this.searchHistory)
200
- );
105
+ JSON.stringify(searchHistory)
106
+ )
107
+ } else {
108
+ localStorage.setItem(
109
+ 'sparc.science-sidebar-search-history',
110
+ JSON.stringify([{ filters: filters, search: search }])
111
+ )
201
112
  }
202
113
  },
203
- updateSearchHistory: function () {
204
- // Update for missing attributes
205
- this.searchHistory.forEach((item) => {
206
- if (!item.id) {
207
- item['id'] = generateUUID();
208
- }
209
- if (!item.label) {
210
- const {label, longLabel} = this.searchHistoryItemLabel(item.search, item.filters);
211
- item['label'] = label;
212
- item['longLabel'] = longLabel;
213
- }
214
- if (!item.saved) {
215
- item['saved'] = false;
216
- }
217
- if (!item.updated) {
218
- item['updated'] = (new Date()).getTime();
219
- }
220
- });
221
-
222
- // Sort by saved and updated
223
- this.searchHistory = this.searchHistory.sort((a, b) => {
224
- if (a.saved !== b.saved) {
225
- return b.saved - a.saved;
226
- }
227
- if (a.updated !== b.updated) {
228
- return a.updated - b.updated;
229
- }
230
- return 0;
231
- });
232
-
233
- // Save updated data
234
- localStorage.setItem(
235
- 'sparc.science-sidebar-search-history',
236
- JSON.stringify(this.searchHistory)
237
- )
238
- },
239
114
  search: function (item) {
240
115
  this.$emit('search', item)
241
116
  },
242
- searchHistoryItemLabel: function (search, filters) {
243
- let label = search ? `"${search.trim()}"` : '';
244
- let longLabel = '';
245
- let filterItems = [];
246
- let filterLabels = [];
247
-
248
- if (filters) {
249
- filterItems = filters.filter((filterItem) => filterItem.facet !== 'Show all');
250
- filterLabels = filterItems.map((item) => item.facet2 || item.facet);
251
- }
252
-
253
- if (label && filterItems.length) {
254
- longLabel += label;
255
- longLabel += `, ${filterLabels.join(', ')}`;
256
- label += ` (+${filterItems.length})`;
257
- }
258
-
259
- if (!label && filterItems.length) {
260
- label = filterItems[0].facet;
261
-
262
- if (filterItems.length > 1) {
263
- longLabel += `${filterLabels.join(', ')}`;
264
- label += ` (+${filterItems.length - 1})`;
265
- }
266
- }
267
-
268
- if (!label) {
269
- label = 'Unknown search';
270
- } else if (label.length > 15 && !longLabel) {
271
- longLabel = label;
272
- }
273
-
274
- return {label, longLabel};
275
- },
276
- toggleSavedSearch: function (item) {
277
- this.searchHistory.forEach((_item) => {
278
- if (_item.id === item.id) {
279
- _item.saved = !_item.saved;
280
- }
281
- });
282
- this.savedSearchHistory = this.searchHistory.filter((item) => item.saved);
283
- this.updateSearchHistory();
284
- },
285
- removeFromSavedSearch: function (item) {
286
- const itemIndex = this.searchHistory.findIndex((_item) => _item.id === item.id);
287
- this.searchHistory.splice(itemIndex, 1);
288
- this.savedSearchHistory = this.searchHistory.filter((item) => item.saved);
289
- this.updateSearchHistory();
117
+ selectChange: function (value) {
118
+ this.selectValue = value
119
+ this.search({ search: value })
290
120
  },
291
121
  },
122
+ mounted: function () {
123
+ this.getSearchHistory()
124
+ EventBus.on('search-changed', (data) => {
125
+ this.setSearchHistory(data)
126
+ })
127
+ },
292
128
  }
293
129
  </script>
294
130
 
295
131
  <style lang="scss" scoped>
296
132
  .history-container {
297
- display: flex;
298
- align-items: center;
299
- justify-content: space-between;
300
- padding-bottom: 6px;
301
- }
302
-
303
- .empty-saved-search {
304
- font-style: italic;
305
- font-size: 14px;
306
- font-weight: 400;
307
- color: var(--el-text-color-secondary);
308
- }
309
-
310
- .saved-search-history {
311
- display: flex;
312
- align-items: center;
313
- gap: 6px;
133
+ padding-bottom: 3px;
314
134
  }
315
135
 
316
136
  .search-tag.el-tag {
317
- margin: 0;
137
+ margin: 0 5px 5px 0;
318
138
  cursor: pointer;
139
+ max-width: 100px;
140
+ overflow: hidden;
141
+ text-overflow: ellipsis;
142
+ float: left;
319
143
  background: #f9f2fc!important;
320
144
  border-color: $app-primary-color!important;
321
145
  color:$app-primary-color!important;
322
-
323
- :deep(.el-tag__content) {
324
- max-width: 15ch;
325
- overflow: hidden;
326
- text-overflow: ellipsis;
327
- }
328
146
  }
329
147
 
330
148
  .title {
@@ -336,111 +154,22 @@ export default {
336
154
  align-items: center;
337
155
  }
338
156
 
339
- .el-dropdown {
157
+ .search-select {
158
+ float: right;
340
159
  width: 180px;
341
- position: relative;
342
- box-sizing: border-box;
343
- cursor: pointer;
344
- text-align: left;
345
- font-size: 14px;
346
- padding: 4px 12px;
347
- min-height: 32px;
348
- line-height: 24px;
349
- border-radius: var(--el-border-radius-base);
350
- background-color: var(--el-fill-color-blank);
351
- transition: var(--el-transition-duration);
352
- transform: translateZ(0);
353
- box-shadow: 0 0 0 1px var(--el-border-color) inset;
354
- cursor: pointer;
355
- }
356
-
357
- .el-dropdown-select {
358
- width: 100%;
359
- display: flex;
360
- align-items: center;
361
- justify-content: space-between;
362
- gap: 1rem;
363
-
364
- .el-icon {
365
- transform: rotate(0deg);
366
- transition: transform 0.25s linear;
367
- }
368
-
369
- &[aria-expanded="true"] {
370
- .el-icon {
371
- transform: rotate(180deg);
372
- }
373
- }
374
- }
375
-
376
- :deep(.el-dropdown-menu__item) {
377
- justify-content: space-between;
378
- gap: 0.5rem;
379
- cursor: default;
380
- position: relative;
381
-
382
- > div:first-child {
383
- max-width: 148px;
384
- text-overflow: ellipsis;
385
- overflow: hidden;
386
- }
387
-
388
- + .el-dropdown-menu__item {
389
- &::before {
390
- content: "";
391
- display: block;
392
- width: calc(100% - 32px);
393
- border-top: 1px solid var(--el-border-color);
394
- position: absolute;
395
- top: 0;
396
- }
397
- }
398
-
399
- &:hover,
400
- &:focus,
401
- &:active {
402
- color: inherit;
403
- background-color: var(--el-bg-color-page);
404
- }
405
-
406
- i {
407
- margin: 0;
408
- }
409
160
  }
410
161
  </style>
411
162
 
412
163
  <style lang="scss">
413
- .el-dropdown__popper {
164
+ .sidebar-search-select-popper {
414
165
  font-family: Asap;
415
166
  font-size: 14px;
416
- font-weight: 400;
167
+ font-weight: 500;
417
168
  font-stretch: normal;
418
169
  font-style: normal;
419
170
  line-height: normal;
420
171
  letter-spacing: normal;
421
172
  color: #292b66;
422
- min-width: 180px;
423
- width: fit-content;
424
-
425
- .el-button + .el-button {
426
- margin: 0;
427
- }
428
- }
429
-
430
- .el-popover.el-popper.popover-dropdown {
431
- padding: 4px 10px;
432
- width: max-content;
433
- max-width: 240px;
434
- font-family: Asap;
435
- font-size: 12px;
436
- color: inherit;
437
- background: #f3ecf6 !important;
438
- border: 1px solid $app-primary-color;
439
-
440
- & .el-popper__arrow::before {
441
- border: 1px solid;
442
- border-color: $app-primary-color;
443
- background: #f3ecf6;
444
- }
173
+ max-width: 200px;
445
174
  }
446
175
  </style>
@@ -95,7 +95,6 @@ var handleErrors = async function (response) {
95
95
  }
96
96
 
97
97
  var initial_state = {
98
- filters: [],
99
98
  searchInput: '',
100
99
  lastSearch: '',
101
100
  results: [],
@@ -227,33 +226,28 @@ export default {
227
226
  this.searchInput = ''
228
227
  this.resetPageNavigation()
229
228
  this.searchAlgolia(this.filters, this.searchInput)
230
- this.$refs.searchHistory.selectValue = 'Search history'
229
+ this.$refs.searchHistory.selectValue = 'Full search history'
231
230
  },
232
231
  searchEvent: function (event = false) {
233
232
  if (event.keyCode === 13 || event instanceof MouseEvent) {
234
- this.searchAndFilterUpdate();
233
+ this.resetPageNavigation()
234
+ this.searchAlgolia(this.filters, this.searchInput)
235
+ this.$refs.searchHistory.selectValue = 'Full search history'
236
+ this.$refs.searchHistory.addSearchToHistory(
237
+ this.filters,
238
+ this.searchInput
239
+ )
235
240
  }
236
241
  },
237
242
  filterUpdate: function (filters) {
238
243
  this.filters = [...filters]
239
- this.searchAndFilterUpdate();
244
+ this.resetPageNavigation()
245
+ this.searchAlgolia(filters, this.searchInput)
240
246
  this.$emit('search-changed', {
241
247
  value: filters,
242
248
  type: 'filter-update',
243
249
  })
244
250
  },
245
- searchAndFilterUpdate: function () {
246
- this.resetPageNavigation();
247
- this.searchAlgolia(this.filters, this.searchInput);
248
- this.$refs.searchHistory.selectValue = 'Search history';
249
- // save history only if there has value
250
- if (this.filters.length || this.searchInput?.trim()) {
251
- this.$refs.searchHistory.addSearchToHistory(
252
- this.filters,
253
- this.searchInput
254
- );
255
- }
256
- },
257
251
  searchAlgolia(filters, query = '') {
258
252
  // Algolia search
259
253
 
@@ -16,17 +16,10 @@ declare module 'vue' {
16
16
  ElCascader: typeof import('element-plus/es')['ElCascader']
17
17
  ElCol: typeof import('element-plus/es')['ElCol']
18
18
  ElDrawer: typeof import('element-plus/es')['ElDrawer']
19
- ElDropdown: typeof import('element-plus/es')['ElDropdown']
20
- ElDropdownItem: typeof import('element-plus/es')['ElDropdownItem']
21
- ElDropdownMenu: typeof import('element-plus/es')['ElDropdownMenu']
22
19
  ElIcon: typeof import('element-plus/es')['ElIcon']
23
- ElIconArrowDown: typeof import('@element-plus/icons-vue')['ArrowDown']
24
20
  ElIconArrowLeft: typeof import('@element-plus/icons-vue')['ArrowLeft']
25
21
  ElIconArrowRight: typeof import('@element-plus/icons-vue')['ArrowRight']
26
- ElIconDelete: typeof import('@element-plus/icons-vue')['Delete']
27
22
  ElIconLocation: typeof import('@element-plus/icons-vue')['Location']
28
- ElIconStar: typeof import('@element-plus/icons-vue')['Star']
29
- ElIconStarFilled: typeof import('@element-plus/icons-vue')['StarFilled']
30
23
  ElIconWarning: typeof import('@element-plus/icons-vue')['Warning']
31
24
  ElIconWarnTriangleFilled: typeof import('@element-plus/icons-vue')['WarnTriangleFilled']
32
25
  ElInput: typeof import('element-plus/es')['ElInput']
@@ -36,7 +29,6 @@ declare module 'vue' {
36
29
  ElRow: typeof import('element-plus/es')['ElRow']
37
30
  ElSelect: typeof import('element-plus/es')['ElSelect']
38
31
  ElTag: typeof import('element-plus/es')['ElTag']
39
- ExternalResourceCard: typeof import('./components/ExternalResourceCard.vue')['default']
40
32
  ImageGallery: typeof import('./components/ImageGallery.vue')['default']
41
33
  SearchFilters: typeof import('./components/SearchFilters.vue')['default']
42
34
  SearchHistory: typeof import('./components/SearchHistory.vue')['default']