@@ -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" ;
@@ -130,6 +131,7 @@ const resolver: Resolver<PublicCode | PublicCodeWithDeprecatedFields> = async (
130131const defaultValues = {
131132 publiccodeYmlVersion : LATEST_VERSION ,
132133 legal : { } ,
134+ organisation : { } ,
133135 localisation : { availableLanguages : [ ] } ,
134136 maintenance : { contacts : undefined , contractors : undefined } ,
135137 platforms : [ ] ,
@@ -149,7 +151,7 @@ const isNotTheSameVersion = (version1: string, version2: string) => {
149151
150152export default function Editor ( ) {
151153 //#region UI
152- const { t } = useTranslation ( ) ;
154+ const { t, i18n } = useTranslation ( ) ;
153155 const { countrySections } = useCountryStore ( ) ;
154156 const { resetWarnings, setWarnings } = useWarningStore ( ) ;
155157 const {
@@ -164,6 +166,14 @@ export default function Editor() {
164166 const { languages, setLanguages, resetLanguages } = useLanguagesStore ( ) ;
165167 const { setCountrySections } = useCountryStore ( ) ;
166168
169+ const organisations = organisationData . flatMap ( data =>
170+ data . organisations . map ( organisation => ( {
171+ text : getLocalizedText ( organisation . name , i18n . language ) ,
172+ value : organisation . id ,
173+ group : getLocalizedText ( data . name , i18n . language ) + " (" + getLocalizedText ( data . abbreviation , i18n . language ) + ")" ,
174+ } ) )
175+ ) ;
176+
167177 const getNestedValue = (
168178 obj : PublicCodeWithDeprecatedFields ,
169179 path : string
@@ -249,14 +259,31 @@ export default function Editor() {
249259 [ setValue ]
250260 ) ;
251261
262+ const updateOrganisation = useCallback (
263+ ( value : Partial < PublicCode > ) => {
264+ const uri = value . organisation ?. uri ;
265+
266+ if ( uri ) {
267+ const organisation = organisations . find ( o => o . value === uri ) ;
268+ setValue ( "organisation.name" , organisation ?. text ) ;
269+ } else {
270+ setValue ( "organisation" , undefined )
271+ }
272+ } ,
273+ [ organisations , setValue ]
274+ )
275+
252276 useEffect ( ( ) => {
253277 const subscription = watch ( ( value , { name } ) => {
254278 if ( name === "maintenance.type" ) {
255279 resetMaintenance ( value as PublicCode ) ;
256280 }
281+ if ( name === "organisation.uri" ) {
282+ updateOrganisation ( value as PublicCode )
283+ }
257284 } ) ;
258285 return ( ) => subscription . unsubscribe ( ) ;
259- } , [ watch , resetMaintenance ] ) ;
286+ } , [ watch , resetMaintenance , updateOrganisation ] ) ;
260287 //#endregion
261288
262289 //#region form action handlers
@@ -534,6 +561,13 @@ export default function Editor() {
534561 < span >
535562 < EditorInput < "landingURL" > fieldName = "landingURL" />
536563 </ span >
564+ < div className = "mt-5" >
565+ < EditorSelect < "organisation.uri" >
566+ fieldName = "organisation.uri"
567+ data = { organisations }
568+ filter = "contains"
569+ />
570+ </ div >
537571 < span >
538572 < EditorInput < "isBasedOn" > fieldName = "isBasedOn" />
539573 </ span >
0 commit comments