Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#1648 | sorting suggestions by weight from r…
Browse files Browse the repository at this point in the history
…epo summary | others sorted alphabatically
  • Loading branch information
snyaggarwal committed Aug 10, 2023
1 parent 7529c64 commit 4ecfa39
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/common/utils.js
Expand Up @@ -905,6 +905,7 @@ export const sortValuesBySourceSummary = (data, summary, summaryField, isLocale)
return d
})
const summaryValues = get(summary, summaryField)
let suggested = []
if(summaryValues) {
const usedValues = map(summaryValues, value => value[0])
usedValues.forEach(used => {
Expand All @@ -913,14 +914,27 @@ export const sortValuesBySourceSummary = (data, summary, summaryField, isLocale)
const _used = used?.toLowerCase()?.replace('-', '')?.replace('_', '')?.replace(' ', '')
return _used === id
})
if(_used)
_used.resultType = 'Suggested'
if(_used) {
suggested.push({..._used, resultType: 'Suggested'})
_data = reject(_data, {id: _used?.id})
}
})
}
let values = orderBy(_data, ['resultType', 'name'], ['desc', 'asc'])

let values = [...suggested, ...orderBy(_data, 'name', 'asc')]

if(isLocale) {
values = uniqBy([{...find(values, {id: summary.default_locale}), resultType: 'Suggested'}, ...orderBy(filter(values, val => (summary.supported_locales || []).includes(val.id)).map(val => ({...val, resultType: 'Suggested'})), ['name'], ['asc']), ...values], 'id')
values = uniqBy(
[
{...find(values, {id: summary.default_locale}), resultType: 'Suggested'},
...filter(
values,
val => (summary.supported_locales || []).includes(val.id)
).map(val => ({...val, resultType: 'Suggested'})),
...values
],
'id'
)
}

return values
Expand Down

0 comments on commit 4ecfa39

Please sign in to comment.