-
Notifications
You must be signed in to change notification settings - Fork 12
/
HomeLocales.jsx
116 lines (105 loc) · 3.74 KB
/
HomeLocales.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import React from 'react';
import {
Accordion, AccordionSummary, AccordionDetails,
Table, TableBody, Tooltip
} from '@mui/material';
import {
Info as InfoIcon
} from '@mui/icons-material'
import { get, isEmpty, forEach, map, groupBy, without, keys, compact } from 'lodash';
import TabCountLabel from '../common/TabCountLabel';
import LocalizedTextRow from './LocalizedTextRow';
const ACCORDIAN_HEADING_STYLES = {
fontWeight: 'bold',
}
const ACCORDIAN_DETAILS_STYLES = {
maxHeight: '300px', overflow: 'auto', display: 'inline-block', width: '100%', padding: '0'
}
const None = () => {
return <div style={{padding: '20px', fontWeight: '300'}}>None</div>
}
const groupLocales = (locales, source) => {
const groupedBySource = {defaultLocales: {}, supportedLocales: {}, rest: {}}
const grouped = groupBy(locales, 'locale')
const supportedLocales = get(source, 'supported_locales') || []
if(get(source, 'default_locale'))
groupedBySource.defaultLocales[source.default_locale] = grouped[source.default_locale]
forEach(supportedLocales, locale => {
if(locale !== source.default_locale)
groupedBySource.supportedLocales[locale] = grouped[locale]
})
forEach(
without(keys(grouped), ...compact([get(source, 'default_locale'), ...supportedLocales])),
locale => groupedBySource.rest[locale] = grouped[locale]
)
return groupedBySource
}
const HomeLocales = ({ concept, label, locales, source, tooltip, isDescription }) => {
const count = locales.length;
const groupedLocales = groupLocales(locales, source)
return (
<Accordion defaultExpanded>
<AccordionSummary
className='light-gray-bg less-paded-accordian-header'
expandIcon={<span />}
aria-controls="panel1a-content"
>
<span className='flex-vertical-center' style={{width: '100%', justifyContent: 'space-between'}}>
<TabCountLabel label={label} count={count} style={ACCORDIAN_HEADING_STYLES} />
{
tooltip &&
<span className='flex-vertical-center' style={{marginLeft: '10px'}}>
<Tooltip title={tooltip}>
<InfoIcon fontSize='small' color='action' />
</Tooltip>
</span>
}
</span>
</AccordionSummary>
<AccordionDetails style={ACCORDIAN_DETAILS_STYLES}>
{
isEmpty(locales) ?
None() :
<Table size="small" aria-label="concept-home-mappings" className='nested-mappings'>
<TableBody>
{
map(groupedLocales.defaultLocales, (localizedTexts, locale) => (
<LocalizedTextRow
concept={concept}
key={locale}
locale={locale}
localizedTexts={localizedTexts}
isDescription={isDescription}
/>
))
}
{
map(groupedLocales.supportedLocales, (localizedTexts, locale) => (
<LocalizedTextRow
concept={concept}
key={locale}
locale={locale}
localizedTexts={localizedTexts}
isDescription={isDescription}
/>
))
}
{
map(groupedLocales.rest, (localizedTexts, locale) => (
<LocalizedTextRow
concept={concept}
key={locale}
locale={locale}
localizedTexts={localizedTexts}
isDescription={isDescription}
/>
))
}
</TableBody>
</Table>
}
</AccordionDetails>
</Accordion>
)
}
export default HomeLocales;