@abi-software/map-side-bar 2.2.1-alpha-1 → 2.2.1-alpha-3

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.
@@ -148,29 +148,6 @@ export class AlgoliaClient {
148
148
  return ub.replace('_', ':')
149
149
  }
150
150
 
151
- getAnatomyForDatasets(filter, query = '',){
152
- return new Promise(resolve => {
153
- this.index
154
- .search(query, {
155
- facets: ['*'],
156
- filters: filter,
157
- attributesToRetrieve: [
158
- 'objectID',
159
- 'anatomy.organ.curie',
160
- ],
161
- hitsPerPage: 999999,
162
- })
163
- .then(response => {
164
- // The line below restructures the response to be an array of objects with the dataset id and the curie
165
- let curieForDatsets = response.hits.map(h=>({
166
- id: h.objectID,
167
- terms: h.anatomy? h.anatomy.organ.map(o=>o.curie) : []
168
- }))
169
- resolve(curieForDatsets)
170
- })
171
- })
172
- }
173
-
174
151
  /**
175
152
  * Get Search results
176
153
  * This is using fetch from the Algolia API
@@ -220,15 +197,46 @@ export class AlgoliaClient {
220
197
  filters: filter,
221
198
  attributesToHighlight: [],
222
199
  attributesToRetrieve: [
200
+ 'objectID',
223
201
  'item.keywords.keyword',
224
202
  'anatomy.organ.name',
225
203
  'anatomy.organ.curie'
226
204
  ],
227
205
  })
228
206
  .then(response => {
229
- let anatomyAsUberons = this._processAnatomy(response.hits)
230
- resolve(anatomyAsUberons)
207
+ // Saving the line below incase we want to starty using keywords again
208
+ // let anatomyAsUberons = this._processAnatomy(response.hits)
209
+
210
+ resolve({
211
+ forFlatmap: this.processResultsForFlatmap(response.hits),
212
+ forScaffold: this.processResultsForScaffold(response.hits)
213
+ })
214
+ })
215
+ })
216
+ }
217
+ processResultsForFlatmap(hits) {
218
+ let curieForDatsets = hits.map(h=>({
219
+ id: h.objectID,
220
+ terms: h.anatomy? h.anatomy.organ.map(o=>o.curie) : []
221
+ }))
222
+ return curieForDatsets
223
+ }
224
+ processResultsForScaffold(hits) {
225
+ let numberOfDatasetsForAnatomy = {}
226
+ hits.forEach(hit => {
227
+ if (hit.anatomy && hit.anatomy.organ ) {
228
+ hit.anatomy.organ.forEach(anatomy => {
229
+ if (anatomy.name) {
230
+ if (numberOfDatasetsForAnatomy[anatomy.name]) {
231
+ numberOfDatasetsForAnatomy[anatomy.name]++
232
+ } else {
233
+ numberOfDatasetsForAnatomy[anatomy.name] = 1
234
+ }
235
+ }
231
236
  })
237
+ }
232
238
  })
239
+ return numberOfDatasetsForAnatomy
233
240
  }
241
+
234
242
  }
@@ -205,16 +205,16 @@ export default {
205
205
  */
206
206
  this.$emit('actionClick', payLoad)
207
207
  })
208
- EventBus.on('available-facets', (payLoad) => {
209
- this.$emit('search-changed', {
210
- type: 'available-facets',
211
- value: payLoad,
212
- })
208
+ EventBus.on('number-of-datasets-for-anatomies', (payLoad) => {
209
+ /**
210
+ * This emits a object with keys as anatomy and values as number of datasets for that anatomy.
211
+ * @arg payload
212
+ */
213
+ this.$emit('number-of-datasets-for-anatomies', payLoad)
213
214
  })
214
215
  EventBus.on('anatomy-in-datasets', (payLoad) => {
215
216
  /**
216
- * This event is emitted when the context is updated.
217
- * Example, context update on first load.
217
+ * This emits a lis of datasets, with the anatomy for each one. Used by flatmap for markers
218
218
  * @arg payload
219
219
  */
220
220
  this.$emit('anatomy-in-datasets', payLoad)
@@ -250,17 +250,12 @@ export default {
250
250
  // Algolia search
251
251
 
252
252
  this.loadingCards = true
253
- this.algoliaClient.getAnatomyForDatasets(getFilters(filters), query)
254
- .then((datasets) => {
255
- EventBus.emit('anatomy-in-datasets', datasets)
256
- })
257
253
  this.algoliaClient
258
254
  .anatomyInSearch(getFilters(filters), query)
259
- .then((anatomy) => {
260
- EventBus.emit('available-facets', {
261
- uberons: anatomy,
262
- labels: this.algoliaClient.anatomyFacetLabels,
263
- })
255
+ .then((r) => {
256
+ // Send result anatomy to the scaffold and flatmap
257
+ EventBus.emit('anatomy-in-datasets', r.forFlatmap)
258
+ EventBus.emit('number-of-datasets-for-anatomies', r.forScaffold)
264
259
  })
265
260
  this.algoliaClient
266
261
  .search(getFilters(filters), query, this.numberPerPage, this.page)