-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add organisation select #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
75c5f9c
e5f3cc4
60860cf
9a3c73a
6ee57a2
99afe66
3caa87a
34efd62
6798670
20b5b57
958e8d3
cc93394
a22edeb
c8bf770
f3f13f6
770f90f
1fc36f6
022c560
b562733
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,8 @@ import useFormPersist from "react-hook-form-persist"; | |
| import { useTranslation } from "react-i18next"; | ||
| import { RequiredDeep } from "type-fest"; | ||
| import licenses from "../../generated/licenses.json"; | ||
| import { allLangs, displayName } from "../../i18n"; | ||
| import organisationData from "../data/organisations.json"; | ||
| import { allLangs, displayName, getLocalizedText } from "../../i18n"; | ||
| import categories from "../contents/categories"; | ||
| import { DEFAULT_COUNTRY_SECTIONS } from "../contents/constants"; | ||
| import * as countrySection from "../contents/countrySpecificSection"; | ||
|
|
@@ -130,6 +131,7 @@ const resolver: Resolver<PublicCode | PublicCodeWithDeprecatedFields> = async ( | |
| const defaultValues = { | ||
| publiccodeYmlVersion: LATEST_VERSION, | ||
| legal: {}, | ||
| organisation: {}, | ||
| localisation: { availableLanguages: [] }, | ||
| maintenance: { contacts: undefined, contractors: undefined }, | ||
| platforms: [], | ||
|
|
@@ -149,7 +151,7 @@ const isNotTheSameVersion = (version1: string, version2: string) => { | |
|
|
||
| export default function Editor() { | ||
| //#region UI | ||
| const { t } = useTranslation(); | ||
| const { t, i18n } = useTranslation(); | ||
| const { countrySections } = useCountryStore(); | ||
| const { resetWarnings, setWarnings } = useWarningStore(); | ||
| const { | ||
|
|
@@ -164,6 +166,14 @@ export default function Editor() { | |
| const { languages, setLanguages, resetLanguages } = useLanguagesStore(); | ||
| const { setCountrySections } = useCountryStore(); | ||
|
|
||
| const organisations = organisationData.flatMap(data => | ||
| data.organisations.map(organisation => ({ | ||
| text: getLocalizedText(organisation.name, i18n.language), | ||
| value: organisation.id, | ||
| group: getLocalizedText(data.name, i18n.language) + " (" + getLocalizedText(data.abbreviation, i18n.language) + ")", | ||
| })) | ||
| ); | ||
|
|
||
| const getNestedValue = ( | ||
| obj: PublicCodeWithDeprecatedFields, | ||
| path: string | ||
|
|
@@ -249,14 +259,31 @@ export default function Editor() { | |
| [setValue] | ||
| ); | ||
|
|
||
| const updateOrganisation = useCallback( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is the usage of useCallback necessary here?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not move the function inside |
||
| (value: Partial<PublicCode>) => { | ||
| const uri = value.organisation?.uri; | ||
|
|
||
| if (uri) { | ||
| const organisation = organisations.find(o => o.value === uri); | ||
| setValue("organisation.name", organisation?.text); | ||
| } else { | ||
| setValue("organisation", undefined) | ||
| } | ||
| }, | ||
| [organisations, setValue] | ||
| ) | ||
|
|
||
| useEffect(() => { | ||
| const subscription = watch((value, { name }) => { | ||
| if (name === "maintenance.type") { | ||
| resetMaintenance(value as PublicCode); | ||
| } | ||
| if (name === "organisation.uri") { | ||
| updateOrganisation(value as PublicCode) | ||
| } | ||
| }); | ||
| return () => subscription.unsubscribe(); | ||
| }, [watch, resetMaintenance]); | ||
| }, [watch, resetMaintenance, updateOrganisation]); | ||
| //#endregion | ||
|
|
||
| //#region form action handlers | ||
|
|
@@ -534,6 +561,13 @@ export default function Editor() { | |
| <span> | ||
| <EditorInput<"landingURL"> fieldName="landingURL" /> | ||
| </span> | ||
| <div className="mt-5"> | ||
| <EditorSelect<"organisation.uri"> | ||
| fieldName="organisation.uri" | ||
| data={organisations} | ||
| filter="contains" | ||
| /> | ||
| </div> | ||
| <span> | ||
| <EditorInput<"isBasedOn"> fieldName="isBasedOn" /> | ||
| </span> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Data | ||
|
|
||
| ## Organisations | ||
|
|
||
| The data in the file `organisations.json` originates from the following sources: | ||
|
|
||
| - The seven departements and the Federal Chancellery (`departements.json`) | ||
| ``` | ||
| https://ld.admin.ch/sparql/#query=PREFIX%20schema%3A%20%3Chttp%3A%2F%2Fschema.org%2F%3E%0APREFIX%20rdf%3A%20%3Chttp%3A%2F%2Fwww.w3.org%2F1999%2F02%2F22-rdf-syntax-ns%23%3E%0APREFIX%20rdfs%3A%20%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E%0A%0ASELECT%20DISTINCT%20%3Fdepartment%20%3FnameDepDe%20%3FnameDepFr%20%3FnameDepIt%20%3FnameDepEn%20%3FaltNameDepDe%20%3FaltNameDepFr%20%3FaltNameDepIt%20%3FaltNameDepEn%20%3Foffice%20%3FnameDe%20%3FnameFr%20%3FnameIt%20%3FnameEn%20WHERE%20%7B%0A%20%20%0A%20%20%3Fdepartment%20schema%3AinDefinedTermSet%20%3Chttps%3A%2F%2Fld.admin.ch%2Fdimension%2Fdepartment%3E.%0A%0A%20%20OPTIONAL%20%7B%20%3Fdepartment%20schema%3Aname%20%3FnameDe.%20FILTER(lang(%3FnameDe)%20%3D%20%22de%22)%20%7D%0A%20%20OPTIONAL%20%7B%20%3Fdepartment%20schema%3Aname%20%3FnameFr.%20FILTER(lang(%3FnameFr)%20%3D%20%22fr%22)%20%7D%0A%20%20OPTIONAL%20%7B%20%3Fdepartment%20schema%3Aname%20%3FnameIt.%20FILTER(lang(%3FnameIt)%20%3D%20%22it%22)%20%7D%0A%20%20OPTIONAL%20%7B%20%3Fdepartment%20schema%3Aname%20%3FnameEn.%20FILTER(lang(%3FnameEn)%20%3D%20%22en%22)%20%7D%0A%0A%20%20OPTIONAL%20%7B%20%3Fdepartment%20schema%3AalternateName%20%3FaltNameDe.%20FILTER(lang(%3FaltNameDe)%20%3D%20%22de%22)%20%7D%0A%20%20OPTIONAL%20%7B%20%3Fdepartment%20schema%3AalternateName%20%3FaltNameFr.%20FILTER(lang(%3FaltNameFr)%20%3D%20%22fr%22)%20%7D%0A%20%20OPTIONAL%20%7B%20%3Fdepartment%20schema%3AalternateName%20%3FaltNameIt.%20FILTER(lang(%3FaltNameIt)%20%3D%20%22it%22)%20%7D%0A%20%20OPTIONAL%20%7B%20%3Fdepartment%20schema%3AalternateName%20%3FaltNameEn.%20FILTER(lang(%3FaltNameEn)%20%3D%20%22en%22)%20%7D%0A%20%20%0A%20%20OPTIONAL%20%7B%20%3Fdepartment%20schema%3Aname%20%3FnameDepDe.%20FILTER(lang(%3FnameDepDe)%20%3D%20%22de%22)%20%7D%0A%20%20OPTIONAL%20%7B%20%3Fdepartment%20schema%3Aname%20%3FnameDepFr.%20FILTER(lang(%3FnameDepFr)%20%3D%20%22fr%22)%20%7D%0A%20%20OPTIONAL%20%7B%20%3Fdepartment%20schema%3Aname%20%3FnameDepIt.%20FILTER(lang(%3FnameDepIt)%20%3D%20%22it%22)%20%7D%0A%20%20OPTIONAL%20%7B%20%3Fdepartment%20schema%3Aname%20%3FnameDepEn.%20FILTER(lang(%3FnameDepEn)%20%3D%20%22en%22)%20%7D%0A%0A%20%20OPTIONAL%20%7B%20%3Fdepartment%20schema%3AalternateName%20%3FaltNameDepDe.%20FILTER(lang(%3FaltNameDepDe)%20%3D%20%22de%22)%20%7D%0A%20%20OPTIONAL%20%7B%20%3Fdepartment%20schema%3AalternateName%20%3FaltNameDepFr.%20FILTER(lang(%3FaltNameDepFr)%20%3D%20%22fr%22)%20%7D%0A%20%20OPTIONAL%20%7B%20%3Fdepartment%20schema%3AalternateName%20%3FaltNameDepIt.%20FILTER(lang(%3FaltNameDepIt)%20%3D%20%22it%22)%20%7D%0A%20%20OPTIONAL%20%7B%20%3Fdepartment%20schema%3AalternateName%20%3FaltNameDepEn.%20FILTER(lang(%3FaltNameDepEn)%20%3D%20%22en%22)%20%7D%0A%0A%7D%0A&endpoint=https%3A%2F%2Fld.admin.ch%2Fquery&requestMethod=POST&tabTitle=Query&headers=%7B%7D&contentTypeConstruct=text%2Fturtle&contentTypeSelect=application%2Fsparql-results%2Bjson&outputFormat=table&outputSettings=%7B%22isEllipsed%22%3Atrue%2C%22compact%22%3Afalse%7D | ||
| ``` | ||
|
|
||
| - All offices of the seven departments (`offices.json`) | ||
| ``` | ||
| https://ld.admin.ch/sparql/#query=PREFIX%20schema%3A%20%3Chttp%3A%2F%2Fschema.org%2F%3E%0APREFIX%20rdf%3A%20%3Chttp%3A%2F%2Fwww.w3.org%2F1999%2F02%2F22-rdf-syntax-ns%23%3E%0APREFIX%20rdfs%3A%20%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E%0A%0ASELECT%20DISTINCT%20%3Fdepartment%20%3FnameDepDe%20%3FnameDepFr%20%3FnameDepIt%20%3FnameDepEn%20%3FaltNameDepDe%20%3FaltNameDepFr%20%3FaltNameDepIt%20%3FaltNameDepEn%20%3Foffice%20%3FnameDe%20%3FnameFr%20%3FnameIt%20%3FnameEn%20WHERE%20%7B%0A%20%0A%20%20%3Foffice%20schema%3AinDefinedTermSet%20%3Chttps%3A%2F%2Fld.admin.ch%2Foffice%3E.%0A%20%20%3Foffice%20schema%3AparentOrganization%20%3Fdepartment.%0A%0A%20%20OPTIONAL%20%7B%20%3Foffice%20schema%3Aname%20%3FnameDe.%20FILTER(lang(%3FnameDe)%20%3D%20%22de%22)%20%7D%0A%20%20OPTIONAL%20%7B%20%3Foffice%20schema%3Aname%20%3FnameFr.%20FILTER(lang(%3FnameFr)%20%3D%20%22fr%22)%20%7D%0A%20%20OPTIONAL%20%7B%20%3Foffice%20schema%3Aname%20%3FnameIt.%20FILTER(lang(%3FnameIt)%20%3D%20%22it%22)%20%7D%0A%20%20OPTIONAL%20%7B%20%3Foffice%20schema%3Aname%20%3FnameEn.%20FILTER(lang(%3FnameEn)%20%3D%20%22en%22)%20%7D%0A%0A%20%20OPTIONAL%20%7B%20%3Foffice%20schema%3AalternateName%20%3FaltNameDe.%20FILTER(lang(%3FaltNameDe)%20%3D%20%22de%22)%20%7D%0A%20%20OPTIONAL%20%7B%20%3Foffice%20schema%3AalternateName%20%3FaltNameFr.%20FILTER(lang(%3FaltNameFr)%20%3D%20%22fr%22)%20%7D%0A%20%20OPTIONAL%20%7B%20%3Foffice%20schema%3AalternateName%20%3FaltNameIt.%20FILTER(lang(%3FaltNameIt)%20%3D%20%22it%22)%20%7D%0A%20%20OPTIONAL%20%7B%20%3Foffice%20schema%3AalternateName%20%3FaltNameEn.%20FILTER(lang(%3FaltNameEn)%20%3D%20%22en%22)%20%7D%0A%20%20%0A%20%20%3Fdepartment%20schema%3AinDefinedTermSet%20%3Chttps%3A%2F%2Fld.admin.ch%2Fdepartment%3E.%0A%20%20%0A%20%20OPTIONAL%20%7B%20%3Fdepartment%20schema%3Aname%20%3FnameDepDe.%20FILTER(lang(%3FnameDepDe)%20%3D%20%22de%22)%20%7D%0A%20%20OPTIONAL%20%7B%20%3Fdepartment%20schema%3Aname%20%3FnameDepFr.%20FILTER(lang(%3FnameDepFr)%20%3D%20%22fr%22)%20%7D%0A%20%20OPTIONAL%20%7B%20%3Fdepartment%20schema%3Aname%20%3FnameDepIt.%20FILTER(lang(%3FnameDepIt)%20%3D%20%22it%22)%20%7D%0A%20%20OPTIONAL%20%7B%20%3Fdepartment%20schema%3Aname%20%3FnameDepEn.%20FILTER(lang(%3FnameDepEn)%20%3D%20%22en%22)%20%7D%0A%0A%20%20OPTIONAL%20%7B%20%3Fdepartment%20schema%3AalternateName%20%3FaltNameDepDe.%20FILTER(lang(%3FaltNameDepDe)%20%3D%20%22de%22)%20%7D%0A%20%20OPTIONAL%20%7B%20%3Fdepartment%20schema%3AalternateName%20%3FaltNameDepFr.%20FILTER(lang(%3FaltNameDepFr)%20%3D%20%22fr%22)%20%7D%0A%20%20OPTIONAL%20%7B%20%3Fdepartment%20schema%3AalternateName%20%3FaltNameDepIt.%20FILTER(lang(%3FaltNameDepIt)%20%3D%20%22it%22)%20%7D%0A%20%20OPTIONAL%20%7B%20%3Fdepartment%20schema%3AalternateName%20%3FaltNameDepEn.%20FILTER(lang(%3FaltNameDepEn)%20%3D%20%22en%22)%20%7D%0A%0A%7D%0A&endpoint=https%3A%2F%2Fld.admin.ch%2Fquery&requestMethod=POST&tabTitle=Query&headers=%7B%7D&contentTypeConstruct=text%2Fturtle&contentTypeSelect=application%2Fsparql-results%2Bjson&outputFormat=table&outputSettings=%7B%22pageSize%22%3A-1%7D | ||
| ``` | ||
|
|
||
| It can be (re-)generated by running: | ||
|
|
||
| ```bash | ||
| npx run build:organisations | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that there should be a note in the readme that this script should be run.
or run it as a post install script
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script is documented in the following README.
I added an additional post install script.