@@ -22,6 +22,7 @@ import mimeTypes from "../contents/mime-types";
2222import platforms from "../contents/platforms" ;
2323import PublicCode , {
2424 defaultItaly ,
25+ IT_COUNTRY_EXTENSION_VERSION ,
2526 LATEST_VERSION ,
2627 PublicCodeWithDeprecatedFields ,
2728} from "../contents/publiccode" ;
@@ -33,11 +34,12 @@ import importStandard from "../importers/standard.importer";
3334import {
3435 CountrySection ,
3536 useCountryStore ,
37+ useITCountrySpecific ,
3638 useLanguagesStore ,
3739 useWarningStore ,
38- useYamlStore ,
40+ useYamlStore
3941} from "../lib/store" ;
40- import { getYaml , collectRemovedKeys } from "../lib/utils" ;
42+ import { collectRemovedKeys , getYaml } from "../lib/utils" ;
4143import linter from "../linter" ;
4244import publicCodeAdapter from "../publiccode-adapter" ;
4345import { toSemVerObject } from "../semver" ;
@@ -163,7 +165,7 @@ export default function Editor() {
163165 } = useYamlStore ( ) ;
164166 const { languages, setLanguages, resetLanguages } = useLanguagesStore ( ) ;
165167 const { setCountrySections } = useCountryStore ( ) ;
166-
168+ const { showCountryExtensionVersion , setShowCountryExtensionVersion } = useITCountrySpecific ( ) ;
167169 const getNestedValue = (
168170 obj : PublicCodeWithDeprecatedFields ,
169171 path : string
@@ -215,13 +217,31 @@ export default function Editor() {
215217 setPubliccodeYmlVersion ( publiccodeYmlVersion ) ;
216218 } , [ ] ) ;
217219
220+ const checkItCountryExtensionVersion = useCallback ( ( publicCode : PublicCode ) => {
221+ const { it } = publicCode
222+ if ( ! it ) {
223+ return ;
224+ }
225+
226+ const { countryExtensionVersion } = it ;
227+ const isCountryExtensionVersionDefined = Boolean ( countryExtensionVersion ) ;
228+ const isDifferentFromSpecificDefinedValue = Boolean ( IT_COUNTRY_EXTENSION_VERSION !== countryExtensionVersion )
229+
230+ const countryExtensionVersionVisible =
231+ isCountryExtensionVersionDefined &&
232+ isDifferentFromSpecificDefinedValue
233+
234+ setShowCountryExtensionVersion ( countryExtensionVersionVisible )
235+ } , [ ] )
236+
218237 useFormPersist ( "form-values" , {
219238 watch,
220239 setValue,
221240 onDataRestored : useCallback (
222241 ( pc : PublicCode ) => {
223242 setLanguages ( Object . keys ( pc ?. description ) ) ;
224243 checkPubliccodeYmlVersion ( pc ) ;
244+ checkItCountryExtensionVersion ( pc )
225245 } ,
226246 [ setLanguages ]
227247 ) ,
@@ -334,6 +354,7 @@ export default function Editor() {
334354 reset ( publicCode ) ;
335355 }
336356
357+ checkItCountryExtensionVersion ( publicCode ) ;
337358 checkPubliccodeYmlVersion ( publicCode ) ;
338359 setIsPublicCodeImported ( true ) ;
339360
@@ -351,7 +372,7 @@ export default function Editor() {
351372
352373 const processImported = async ( raw : PublicCode ) => {
353374 try {
354- try { getValues ( ) ; } catch { }
375+ try { getValues ( ) ; } catch { }
355376 const adapted = publicCodeAdapter ( {
356377 publicCode : raw as PublicCode ,
357378 defaultValues : defaultValues as unknown as Partial < PublicCode > ,
@@ -671,15 +692,17 @@ export default function Editor() {
671692 < div >
672693 < h4 > { t ( "countrySpecificSection.italy" ) } </ h4 >
673694 </ div >
674- < div className = "mt-5" >
675- < div className = "form-group" >
676- < EditorSelect < "it.countryExtensionVersion" >
677- fieldName = "it.countryExtensionVersion"
678- data = { [ { text : "1.0" , value : "1.0" } ] }
679- required
680- />
695+ { isPublicCodeImported && showCountryExtensionVersion &&
696+ < div className = "mt-5" >
697+ < div className = "form-group" >
698+ < EditorSelect < "it.countryExtensionVersion" >
699+ fieldName = "it.countryExtensionVersion"
700+ data = { [ { text : IT_COUNTRY_EXTENSION_VERSION , value : IT_COUNTRY_EXTENSION_VERSION } ] }
701+ required
702+ />
703+ </ div >
681704 </ div >
682- </ div >
705+ }
683706 < div className = "mt-4" >
684707 < h5 > { t ( "publiccodeyml.it.conforme.label" ) } </ h5 >
685708 < div className = "row" >
0 commit comments