Skip to content
Snippets Groups Projects
Commit 93557fa0 authored by Tore.Brede's avatar Tore.Brede
Browse files

GREG-214: Adding nno and eng acronyms

parent 7456aac3
No related branches found
No related tags found
1 merge request!284GREG-214: Switching to showing orgreg ID in dropdown for units
Pipeline #116283 passed
...@@ -7,6 +7,8 @@ type OuData = { ...@@ -7,6 +7,8 @@ type OuData = {
en: string en: string
orgreg_id?: string orgreg_id?: string
acronym_nob?: string acronym_nob?: string
acronym_nno?: string
acronym_eng?: string
} }
function useOus(): OuData[] | undefined { function useOus(): OuData[] | undefined {
......
...@@ -18,7 +18,7 @@ import React, { ...@@ -18,7 +18,7 @@ import React, {
} from 'react' } from 'react'
import { addDays } from 'date-fns/fp' import { addDays } from 'date-fns/fp'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import useOus, { enSort, nbSort } from 'hooks/useOus' import useOus, { enSort, nbSort, OuData } from 'hooks/useOus'
import useRoleTypes, { RoleTypeData } from 'hooks/useRoleTypes' import useRoleTypes, { RoleTypeData } from 'hooks/useRoleTypes'
import { getOuName, isValidEmail } from 'utils' import { getOuName, isValidEmail } from 'utils'
import { FeatureContext } from 'contexts' import { FeatureContext } from 'contexts'
...@@ -143,6 +143,20 @@ const StepPersonForm = forwardRef( ...@@ -143,6 +143,20 @@ const StepPersonForm = forwardRef(
return true return true
} }
function getAcronym(ouData: OuData) {
switch (i18n.language) {
case 'en':
return ouData.acronym_eng ?? ouData.acronym_nob
case 'nn':
return ouData.acronym_nno ?? ouData.acronym_nob
default:
// There should always be a Norwegian bokmaal acronym set
return ouData.acronym_nob
}
}
return ( return (
<> <>
<Typography <Typography
...@@ -243,8 +257,7 @@ const StepPersonForm = forwardRef( ...@@ -243,8 +257,7 @@ const StepPersonForm = forwardRef(
.sort(i18n.language === 'en' ? enSort : nbSort) .sort(i18n.language === 'en' ? enSort : nbSort)
.map((ou) => ( .map((ou) => (
<MenuItem key={ou.id.toString()} value={ou.id}> <MenuItem key={ou.id.toString()} value={ou.id}>
{getOuName(ou)} ({ou.acronym_nob ?? ''}) ( {getOuName(ou)} ({getAcronym(ou)}) ({ou.orgreg_id ?? ''})
{ou.orgreg_id ?? ''})
</MenuItem> </MenuItem>
))} ))}
</TextField> </TextField>
......
...@@ -29,4 +29,12 @@ class SponsorOrgUnitsSerializer(ModelSerializer): ...@@ -29,4 +29,12 @@ class SponsorOrgUnitsSerializer(ModelSerializer):
class Meta: class Meta:
model = OrganizationalUnit model = OrganizationalUnit
fields = ["id", "nb", "en", "orgreg_id", "acronym_nob"] fields = [
"id",
"nb",
"en",
"orgreg_id",
"acronym_nob",
"acronym_nno",
"acronym_eng",
]
...@@ -491,6 +491,24 @@ class OrganizationalUnit(BaseModel): ...@@ -491,6 +491,24 @@ class OrganizationalUnit(BaseModel):
.first() .first()
) )
@property
def acronym_nno(self) -> Optional[str]:
"""Gets the Norwegian nynorsk acronym if it exists"""
return (
self.identifiers.filter(name="acronym_nno")
.values_list("value", flat=True)
.first()
)
@property
def acronym_eng(self) -> Optional[str]:
"""Gets the English acronym if it exists"""
return (
self.identifiers.filter(name="acronym_eng")
.values_list("value", flat=True)
.first()
)
def __repr__(self) -> str: def __repr__(self) -> str:
return "{}(id={!r}, name_en={!r}, parent={!r})".format( return "{}(id={!r}, name_en={!r}, parent={!r})".format(
self.__class__.__name__, self.pk, self.name_en, self.parent self.__class__.__name__, self.pk, self.name_en, self.parent
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment