1
- import { useTranslation } from 'next-i18next' ;
2
- import { useMemo } from 'react' ;
3
- import { Schema } from '@app/common/interfaces/schema.interface' ;
1
+ import { useTranslation } from 'next-i18next' ;
2
+ import { useMemo } from 'react' ;
3
+ import { Schema } from '@app/common/interfaces/schema.interface' ;
4
4
import router from 'next/router' ;
5
5
import {
6
6
DescriptionList ,
7
7
DescriptionListTitle
8
8
} from '@app/modules/schema-view/metadata-and-files/metadata-and-files.styles' ;
9
- import { Grid } from '@mui/material' ;
10
- import { Heading } from 'suomifi-ui-components' ;
9
+ import { Grid } from '@mui/material' ;
10
+ import { Heading } from 'suomifi-ui-components' ;
11
+ import { getLanguageVersion } from '@app/common/utils/get-language-version' ;
12
+ import getOrganizations from '@app/common/utils/get-organizations' ;
11
13
12
14
export default function MetadataAndFiles ( { schemaDetails } : { schemaDetails ?: Schema } ) {
13
15
const { t } = useTranslation ( 'common' ) ;
14
- const lang = router . locale ;
16
+ const lang = router . locale ?? '' ;
17
+
18
+ // TODO: Editing -> Only edit with permission, we have util has-permission
15
19
16
- // TODO: Only edit with permission, we have util has-permission
17
- // TODO: Get organization names neatly
18
- // Locale: Object.entries(schemaDetails.label).find((t) => t[0] === lang)?.[1] ?? ''
19
- // Organization: see datamodel-ui/src/modules/model/model-info-view.tsx
20
20
interface SchemaDisplay {
21
21
[ key :string ] : string ;
22
22
}
@@ -38,24 +38,21 @@ export default function MetadataAndFiles({ schemaDetails }: { schemaDetails?: Sc
38
38
}
39
39
) ;
40
40
}
41
- function languageFinder ( langTaggedData : { [ key :string ] : string } ) {
42
- const primaryOption = Object . entries ( langTaggedData ) . find ( ( t ) => t [ 0 ] === lang ) ?. [ 1 ] ;
43
- const englishOption = Object . entries ( langTaggedData ) . find ( ( t ) => t [ 0 ] === 'en' ) ?. [ 1 ] ;
44
- return primaryOption ?? englishOption ;
45
- }
41
+ const organizations = getOrganizations ( schemaDetails . organizations , lang )
42
+ . map ( ( org ) => org . label ) . join ( ', ' ) ;
46
43
return (
47
44
{
48
45
schemaPid : schemaDetails ?. pid ?? '' ,
49
46
schemaLabel : schemaDetails ?. label
50
- ? languageFinder ( schemaDetails . label ) ?? ''
47
+ ? getLanguageVersion ( { data : schemaDetails . label , lang , appendLocale : true } )
51
48
: '' ,
52
49
schemaDescription : schemaDetails ?. description
53
- ? languageFinder ( schemaDetails . description ) ?? ''
50
+ ? getLanguageVersion ( { data : schemaDetails . description , lang , appendLocale : true } ) ?? ''
54
51
: '' ,
55
52
schemaCreated : schemaDetails ?. created ?? '' ,
56
53
schemaModified : schemaDetails ?. modified ?? '' ,
57
54
schemaState : schemaDetails ?. state ?? '' ,
58
- schemaOrganizations : schemaDetails ?. organizations . toString ( ) ?? '' ,
55
+ schemaOrganizations : organizations ,
59
56
schemaVisibility : schemaDetails ?. visibility ?? '' ,
60
57
schemaFormat : schemaDetails ?. format ?? '' ,
61
58
schemaVersionLabel : schemaDetails ?. versionLabel ?? '' ,
0 commit comments