Skip to content

Commit 0f66652

Browse files
committed
fix: show it.countryExtendedVersion only if it is imported and its value is wrong
1 parent d09defa commit 0f66652

File tree

3 files changed

+57
-14
lines changed

3 files changed

+57
-14
lines changed

src/app/components/Editor.tsx

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import mimeTypes from "../contents/mime-types";
2222
import platforms from "../contents/platforms";
2323
import 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";
3334
import {
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";
4143
import linter from "../linter";
4244
import publicCodeAdapter from "../publiccode-adapter";
4345
import { 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">

src/app/contents/publiccode.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import scopes from "./scopes";
55
import softwareTypes from "./softwareTypes";
66

77
export const LATEST_VERSION = "0.4.0"
8+
export const IT_COUNTRY_EXTENSION_VERSION = '1.0'
89

910
// https://yml.publiccode.tools/schema.core.html
1011
export default interface PublicCode {
@@ -34,7 +35,7 @@ export default interface PublicCode {
3435

3536
export interface PublicCodeWithDeprecatedFields {
3637
monochromeLogo: string;
37-
legal: Pick<Legal, 'authorsFile'>
38+
legal: Pick<Legal, 'authorsFile'>
3839
inputTypes?: Array<string>,
3940
outputTypes?: Array<string>,
4041
description: Record<string, Pick<Description, 'genericName'>>

src/app/lib/store.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { create } from "zustand";
2+
import { persist } from "zustand/middleware";
23
import { Warning } from "../components/WarningBox";
34
import {
45
DEFAULT_COUNTRY_SECTIONS,
56
FALLBACK_LANGUAGE,
67
} from "../contents/constants";
7-
import { persist } from "zustand/middleware";
88

99
export type CountrySection = "none" | "all" | "italy";
1010

@@ -24,6 +24,11 @@ type YamlStore = {
2424
resetYaml: () => void;
2525
};
2626

27+
type ITCountrySpecificStore = {
28+
showCountryExtensionVersion: boolean
29+
setShowCountryExtensionVersion: (value: boolean) => void
30+
};
31+
2732
type LanguagesStore = {
2833
languages: string[];
2934
setLanguages: (data: string[]) => void;
@@ -116,6 +121,20 @@ export const useYamlStore = create<YamlStore>()(
116121
)
117122
);
118123

124+
export const useITCountrySpecific = create<ITCountrySpecificStore>()(persist(
125+
(set) => ({
126+
showCountryExtensionVersion: false,
127+
setShowCountryExtensionVersion: (showCountryExtensionVersion: boolean) => {
128+
set((state) => ({ ...state, showCountryExtensionVersion }))
129+
}
130+
}),
131+
{
132+
name: "itCountrySpecific-store",
133+
partialize: (state => ({
134+
showCountryExtensionVersion: state.showCountryExtensionVersion
135+
}))
136+
}));
137+
119138
export const useWarningStore = create<WarningStore>()(
120139
persist(
121140
(set) => ({

0 commit comments

Comments
 (0)