Skip to content

Commit

Permalink
fix: fixed releaseDate issue on import (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriocomo authored Jan 8, 2025
1 parent b8d0f27 commit 828736f
Show file tree
Hide file tree
Showing 15 changed files with 355 additions and 64 deletions.
100 changes: 90 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@
},
"dependencies": {
"@reduxjs/toolkit": "^1.9.5",
"axios": "^1.7.9",
"bootstrap": "^4.6.0",
"bootstrap-italia": "^2.8.8",
"copy-to-clipboard": "^3.3.3",
"countries-list": "^3.0.6",
"date-fns": "^4.1.0",
"design-react-kit": "^5.4.1",
"i18next": "^23.2.2",
"i18next-browser-languagedetector": "^7.2.0",
Expand Down Expand Up @@ -75,6 +77,7 @@
"@types/lodash": "^4.14.195",
"@types/mime-db": "^1.43.5",
"@types/node": "^20.3.1",
"@types/node-fetch": "^2.6.12",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/validator": "^13.7.17",
Expand All @@ -88,6 +91,7 @@
"gh-pages": "^5.0.0",
"globals": "^15.9.0",
"jest": "^26.6.3",
"node-fetch": "^3.3.2",
"release-it": "^17.4.0",
"swc-loader": "^0.2.3",
"ts-node": "^10.9.1",
Expand All @@ -96,4 +100,4 @@
"typescript-eslint": "^8.11.0",
"vite": "^5.4.1"
}
}
}
77 changes: 46 additions & 31 deletions src/app/components/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { FieldErrors, FieldPathByValue, FormProvider, Resolver, useForm } from "react-hook-form";
import PubliccodeYmlLanguages from "./PubliccodeYmlLanguages";

import { Col, Container, Icon, notify, Row } from "design-react-kit";
import { set } from "lodash";
import { useCallback, useEffect, useState } from "react";
import { FieldErrors, FieldPathByValue, FormProvider, Resolver, useForm } from "react-hook-form";
import useFormPersist from "react-hook-form-persist";
import { useTranslation } from "react-i18next";
import { RequiredDeep } from "type-fest";
import YAML from "yaml";
import licenses from "../../generated/licenses.json";
import { allLangs } from "../../i18n";
Expand All @@ -13,11 +13,19 @@ import { DEFAULT_COUNTRY_SECTIONS } from "../contents/constants";
import * as countrySection from "../contents/countrySpecificSection";
import developmentStatus from "../contents/developmentStatus";
import maintenanceTypes from "../contents/maintenanceTypes";
import mimeTypes from "../contents/mime-types";
import platforms from "../contents/platforms";
import PublicCode, { defaultItaly, LATEST_VERSION, PublicCodeWithDeprecatedFields } from "../contents/publiccode";
import { getPubliccodeYmlVersionList } from "../contents/publiccode-yml-version";
import softwareTypes from "../contents/softwareTypes";
import fileImporter from "../importers/file.importer";
import importFromGitlab from "../importers/gitlab.importer";
import importStandard from "../importers/standard.importer";
import linter from "../linter";
import publicCodeAdapter from "../publiccode-adapter";
import { isMinorThanLatest, toSemVerObject } from "../semver";
import { useAppDispatch, useAppSelector } from "../store";
import { resetPubliccodeYmlLanguages, setPubliccodeYmlLanguages } from "../store/publiccodeYmlLanguages";
import { validator } from "../validator";
import EditorBoolean from "./EditorBoolean";
import EditorContacts from "./EditorContacts";
Expand All @@ -30,21 +38,13 @@ import EditorMultiselect from "./EditorMultiselect";
import EditorRadio from "./EditorRadio";
import EditorScreenshots from "./EditorScreenshots";
import EditorSelect from "./EditorSelect";
import EditorUsedBy from "./EditorUsedBy";
import { Footer } from "./Foot";
import Head from "./Head";
import InfoBox from "./InfoBox";
import { YamlModal } from "./YamlModal";

import useFormPersist from "react-hook-form-persist";
import { RequiredDeep } from "type-fest";
import mimeTypes from "../contents/mime-types";
import { getPubliccodeYmlVersionList } from "../contents/publiccode-yml-version";
import { isMinorThanLatest, toSemVerObject } from "../semver";
import { resetPubliccodeYmlLanguages, setPubliccodeYmlLanguages } from "../store/publiccodeYmlLanguages";
import yamlSerializer from "../yaml-serializer";
import { removeDuplicate } from "../yaml-upload";
import EditorUsedBy from "./EditorUsedBy";
import PubliccodeYmlLanguages from "./PubliccodeYmlLanguages";
import { WarningModal } from "./WarningModal";
import { YamlModal } from "./YamlModal";

const PUBLIC_CODE_EDITOR_WARNINGS = 'PUBLIC_CODE_EDITOR_WARNINGS'

Expand Down Expand Up @@ -245,23 +245,19 @@ export default function Editor() {
const setFormDataAfterImport = async (
fetchData: () => Promise<PublicCode | null>
) => {
const publicCode = await fetchData();

if (publicCode) {
const values = { ...defaultValues, ...publicCode } as PublicCode;

if (publicCode.usedBy) {
values.usedBy = removeDuplicate(publicCode.usedBy)
}
try {
const publicCode = await fetchData().then(publicCode => {
return publicCodeAdapter({ publicCode, defaultValues: defaultValues as unknown as Partial<PublicCode> })
});

setLanguages(publicCode);
reset(values);
reset(publicCode);

checkPubliccodeYmlVersion(publicCode);

setPublicCodeImported(true);

const res = await checkWarnings(values)
const res = await checkWarnings(publicCode)

setWarnings(Array.from(res.warnings).map(([key, { message }]) => ({ key, message })));

Expand All @@ -278,22 +274,41 @@ export default function Editor() {
duration: _5_SECONDS
})
}


} catch (error: unknown) {
notify('Import error', (error as Error).message, {
dismissable: true,
state: "error",
})
}
};

const loadFileYamlHandler = async (file: File) => {
const fetchDataFn = () => yamlSerializer(file.stream());
const fetchDataFn = () => fileImporter(file);

await setFormDataAfterImport(fetchDataFn);
};

const loadRemoteYamlHandler = async (url: string) => {
const fetchDataFn = () =>
fetch(url)
.then((res) => res.body)
.then((res) => res && yamlSerializer(res));
const loadRemoteYamlHandler = async (urlValue: string) => {

try {
const url = new URL(urlValue);

const isGitlabRepo = url.hostname.includes('gitlab.com')

const fetchDataFn = isGitlabRepo
? async () => await importFromGitlab(url)
: async () => await importStandard(url)

await setFormDataAfterImport(fetchDataFn);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (error) {
notify(t('editor.notvalidurl'), t('editor.notvalidurl'), {
state: 'error'
})
}

await setFormDataAfterImport(fetchDataFn);
};
//#endregion

Expand Down
Loading

0 comments on commit 828736f

Please sign in to comment.