@@ -12,7 +12,8 @@ import useFormPersist from "react-hook-form-persist";
1212import { useTranslation } from "react-i18next" ;
1313import { RequiredDeep } from "type-fest" ;
1414import licenses from "../../generated/licenses.json" ;
15- import { allLangs , displayName } from "../../i18n" ;
15+ import organisationData from "../data/organisations.json" ;
16+ import { allLangs , displayName , getLocalizedText } from "../../i18n" ;
1617import categories from "../contents/categories" ;
1718import { DEFAULT_COUNTRY_SECTIONS } from "../contents/constants" ;
1819import * as countrySection from "../contents/countrySpecificSection" ;
@@ -128,6 +129,7 @@ const resolver: Resolver<PublicCode | PublicCodeWithDeprecatedFields> = async (
128129const defaultValues = {
129130 publiccodeYmlVersion : LATEST_VERSION ,
130131 legal : { } ,
132+ organisation : { } ,
131133 localisation : { availableLanguages : [ ] } ,
132134 maintenance : { contacts : undefined , contractors : undefined } ,
133135 platforms : [ ] ,
@@ -147,7 +149,7 @@ const isNotTheSameVersion = (version1: string, version2: string) => {
147149
148150export default function Editor ( ) {
149151 //#region UI
150- const { t } = useTranslation ( ) ;
152+ const { t, i18n } = useTranslation ( ) ;
151153 const { countrySections } = useCountryStore ( ) ;
152154 const { resetWarnings, setWarnings } = useWarningStore ( ) ;
153155 const {
@@ -161,6 +163,15 @@ export default function Editor() {
161163 } = useYamlStore ( ) ;
162164 const { languages, setLanguages, resetLanguages } = useLanguagesStore ( ) ;
163165 const { setCountrySections } = useCountryStore ( ) ;
166+
167+ const organisations = organisationData . flatMap ( data =>
168+ data . organisations . map ( organisation => ( {
169+ text : getLocalizedText ( organisation . name , i18n . language ) ,
170+ value : organisation . id ,
171+ group : getLocalizedText ( data . name , i18n . language ) + " (" + getLocalizedText ( data . abbreviation , i18n . language ) + ")" ,
172+ } ) )
173+ ) ;
174+
164175 const { showCountryExtensionVersion, setShowCountryExtensionVersion } =
165176 useITCountrySpecific ( ) ;
166177 const getNestedValue = (
@@ -283,14 +294,31 @@ export default function Editor() {
283294 [ setValue ]
284295 ) ;
285296
297+ const updateOrganisation = useCallback (
298+ ( value : Partial < PublicCode > ) => {
299+ const uri = value . organisation ?. uri ;
300+
301+ if ( uri ) {
302+ const organisation = organisations . find ( o => o . value === uri ) ;
303+ setValue ( "organisation.name" , organisation ?. text ) ;
304+ } else {
305+ setValue ( "organisation" , undefined )
306+ }
307+ } ,
308+ [ organisations , setValue ]
309+ )
310+
286311 useEffect ( ( ) => {
287312 const subscription = watch ( ( value , { name } ) => {
288313 if ( name === "maintenance.type" ) {
289314 resetMaintenance ( value as PublicCode ) ;
290315 }
316+ if ( name === "organisation.uri" ) {
317+ updateOrganisation ( value as PublicCode )
318+ }
291319 } ) ;
292320 return ( ) => subscription . unsubscribe ( ) ;
293- } , [ watch , resetMaintenance ] ) ;
321+ } , [ watch , resetMaintenance , updateOrganisation ] ) ;
294322 //#endregion
295323
296324 //#region form action handlers
@@ -579,9 +607,13 @@ export default function Editor() {
579607 < span >
580608 < EditorInput < "isBasedOn" > fieldName = "isBasedOn" />
581609 </ span >
582- < span >
583- < EditorInput < "organisation.uri" > fieldName = "organisation.uri" />
584- </ span >
610+ < div className = "mt-5" >
611+ < EditorSelect < "organisation.uri" >
612+ fieldName = "organisation.uri"
613+ data = { organisations }
614+ filter = "contains"
615+ />
616+ </ div >
585617 < div className = "mt-4 mb-4" >
586618 < EditorFundedBy />
587619 </ div >
0 commit comments