Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#1078 | sorting concepts locales with prefer…
Browse files Browse the repository at this point in the history
…red, name/description-type and name/description
  • Loading branch information
snyaggarwal committed Nov 1, 2021
1 parent 78bb2ab commit 98abcc9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions src/components/concepts/HomeLocales.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import {
Info as InfoIcon
} from '@mui/icons-material'
import { get, isEmpty, forEach, map, groupBy, without, keys, compact, omitBy } from 'lodash';
import { get, isEmpty, forEach, map, groupBy, without, keys, compact, has } from 'lodash';
import TabCountLabel from '../common/TabCountLabel';
import LocalizedTextRow from './LocalizedTextRow';

Expand All @@ -30,13 +30,16 @@ const groupLocales = (locales, source) => {
groupedBySource.defaultLocales[source.default_locale] = grouped[source.default_locale]

forEach(supportedLocales, locale => {
if(locale !== source.default_locale)
if(locale !== source.default_locale && has(grouped, locale))
groupedBySource.supportedLocales[locale] = grouped[locale]
})

forEach(
without(keys(grouped), ...compact([get(source, 'default_locale'), ...supportedLocales])),
locale => groupedBySource.rest[locale] = grouped[locale]
locale => {
if(has(grouped, locale))
groupedBySource.rest[locale] = grouped[locale]
}
)

return groupedBySource
Expand Down Expand Up @@ -73,7 +76,7 @@ const HomeLocales = ({ concept, label, locales, source, tooltip, isDescription }
<Table size="small" aria-label="concept-home-mappings" className='nested-mappings'>
<TableBody>
{
map(omitBy(groupedLocales.defaultLocales, isEmpty), (localizedTexts, locale) => (
map(groupedLocales.defaultLocales, (localizedTexts, locale) => (
<LocalizedTextRow
concept={concept}
key={locale}
Expand All @@ -84,7 +87,7 @@ const HomeLocales = ({ concept, label, locales, source, tooltip, isDescription }
))
}
{
map(omitBy(groupedLocales.supportedLocales, isEmpty), (localizedTexts, locale) => (
map(groupedLocales.supportedLocales, (localizedTexts, locale) => (
<LocalizedTextRow
concept={concept}
key={locale}
Expand All @@ -95,7 +98,7 @@ const HomeLocales = ({ concept, label, locales, source, tooltip, isDescription }
))
}
{
map(omitBy(groupedLocales.rest, isEmpty), (localizedTexts, locale) => (
map(groupedLocales.rest, (localizedTexts, locale) => (
<LocalizedTextRow
concept={concept}
key={locale}
Expand Down
2 changes: 1 addition & 1 deletion src/components/concepts/LocalizedTextRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const LocalizedTextRow = ({concept, locale, localizedTexts, isDescription}) => {
</TableCell>
</TableRow>
{
map(orderBy(localizedTexts, [text => get(text, nameAttr, '').toLowerCase()], ['asc']), localizedText => {
map(orderBy(localizedTexts, ['locale_preferred', typeAttr, nameAttr], ['desc', 'asc', 'asc']), localizedText => {
const type = get(localizedText, typeAttr)
return (
<TableRow
Expand Down

0 comments on commit 98abcc9

Please sign in to comment.