Skip to content

Commit

Permalink
experiment a way to display HAL wording
Browse files Browse the repository at this point in the history
  • Loading branch information
JeromeBu committed Feb 21, 2024
1 parent 38602af commit 32461c1
Show file tree
Hide file tree
Showing 12 changed files with 250 additions and 88 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"dependencies": {
"@codegouvfr/react-dsfr": "^1.0.0",
"@codegouvfr/sill": "^1.20.4",
"@codegouvfr/sill": "^1.20.5",
"@emotion/react": "^11.11.0",
"@emotion/styled": "^11.11.0",
"@mui/icons-material": "^5.0.4",
Expand Down
4 changes: 4 additions & 0 deletions src/core/adapter/sillApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export function createSillApi(params: {
};

const sillApi: SillApi = {
"getExternalSoftwareDataOrigin": memoize(
() => trpcClient.getExternalSoftwareDataOrigin.query(),
{ "promise": true }
),
"getRedirectUrl": params => trpcClient.getRedirectUrl.query(params),
"getApiVersion": memoize(() => trpcClient.getApiVersion.query(), {
"promise": true
Expand Down
1 change: 1 addition & 0 deletions src/core/adapter/sillApiMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { assert } from "tsafe/assert";
import type { ApiTypes } from "@codegouvfr/sill";

export const sillApi: SillApi = {
"getExternalSoftwareDataOrigin": memoize(async () => "wikidata", { "promise": true }),
"getRedirectUrl": async () => undefined,
"getApiVersion": memoize(async () => "0.0.0", { "promise": true }),
"getOidcParams": memoize(
Expand Down
1 change: 1 addition & 0 deletions src/core/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export async function bootstrapCore(

await Promise.all([
dispatch(usecases.sillApiVersion.protectedThunks.initialize()),
dispatch(usecases.externalDataOrigin.protectedThunks.initialize()),
dispatch(usecases.softwareCatalog.protectedThunks.initialize()),
dispatch(usecases.generalStats.protectedThunks.initialize()),
dispatch(usecases.redirect.protectedThunks.initialize())
Expand Down
6 changes: 6 additions & 0 deletions src/core/ports/SillApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import { assert, type Equals } from "tsafe/assert";
import type { TrpcRouterInput, TrpcRouterOutput } from "@codegouvfr/sill";

export type SillApi = {
getExternalSoftwareDataOrigin: {
(params: TrpcRouterInput["getExternalSoftwareDataOrigin"]): Promise<
TrpcRouterOutput["getExternalSoftwareDataOrigin"]
>;
clear: () => void;
};
getRedirectUrl: (
params: TrpcRouterInput["getRedirectUrl"]
) => Promise<TrpcRouterOutput["getRedirectUrl"]>;
Expand Down
2 changes: 2 additions & 0 deletions src/core/usecases/externalDataOrigin/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./state";
export * from "./thunks";
3 changes: 3 additions & 0 deletions src/core/usecases/externalDataOrigin/state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const name = "externalDataOrigin";

export const reducer = null;
33 changes: 33 additions & 0 deletions src/core/usecases/externalDataOrigin/thunks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { ExternalDataOrigin } from "@codegouvfr/sill";
import type { Thunks } from "core/bootstrap";
import { createUsecaseContextApi } from "redux-clean-architecture";

const { getContext, setContext } = createUsecaseContextApi<{
externalDataOrigin: ExternalDataOrigin;
}>();

export const thunks = {
"getExternalDataOrigin":
() =>
(...args): ExternalDataOrigin => {
const [, , rootContext] = args;

const { externalDataOrigin } = getContext(rootContext);

return externalDataOrigin;
}
} satisfies Thunks;

export const protectedThunks = {
"initialize":
() =>
async (...args) => {
const [, , rootContext] = args;

const { sillApi } = rootContext;

setContext(rootContext, {
"externalDataOrigin": await sillApi.getExternalSoftwareDataOrigin()
});
}
} satisfies Thunks;
2 changes: 2 additions & 0 deletions src/core/usecases/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import * as readme from "./readme";
import * as redirect from "./redirect";
import * as declarationRemoval from "./declarationRemoval";
import * as userProfile from "./userProfile";
import * as externalDataOrigin from "./externalDataOrigin";

export const usecases = {
softwareCatalog,
Expand All @@ -22,6 +23,7 @@ export const usecases = {
instanceForm,
userAccountManagement,
sillApiVersion,
externalDataOrigin,
softwareUserAndReferent,
generalStats,
userAuthentication,
Expand Down
242 changes: 180 additions & 62 deletions src/ui/i18n/i18n.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { createI18nApi, declareComponentKeys } from "i18nifty";
import { languages, type Language } from "@codegouvfr/sill";
import { languages, type Language, type ExternalDataOrigin } from "@codegouvfr/sill";
import { assert } from "tsafe/assert";
import type { Equals } from "tsafe";
import { statefulObservableToStatefulEvt } from "powerhooks/tools/StatefulObservable/statefulObservableToStatefulEvt";
import { z } from "zod";
import { createUnionSchema } from "ui/tools/zod/createUnionSchema";
import { DeclarationType } from "../shared/DeclarationRemovalModal";
import { ReactNode } from "react";

export { declareComponentKeys };
export { languages };
Expand Down Expand Up @@ -340,36 +341,10 @@ const {
"Operating system on which the software can be installed"
},
"SoftwareFormStep2": {
"wikidata id": "Wikidata item",
"wikidata id hint": ({
wikidataUrl,
exampleSoftwareName,
wikidataPageExampleUrl,
softwareSillUrl
}) => (
<>
Fill up a name or directly the id (of the form <code>Qxxxxx</code>
) to associate the software with an existing entry{" "}
<a href={wikidataUrl} target="_blank" rel="noreferrer">
Wikidata
</a>
.
<br />
Most general information, such as the logo or the URL of the code
repository, is extracted from Wikidata. If the software you want
to add does not have a Wikidata entry yet, you can create one .
Find here an{" "}
<a href={wikidataPageExampleUrl} target="_blank" rel="noreferrer">
example of a Wikidata entry
</a>
&nbsp; for the software&nbsp;
<a href={softwareSillUrl} target="_blank" rel="noreferrer">
{exampleSoftwareName}
</a>{" "}
</>
),
"wikidata id information":
"This information will automatically populate other fields",
"external id": externalId("en"),
"external id hint": externalIdHint("en"),
// "wikidata id information":
// "This information will automatically populate other fields",
"comptoir du libre id": "Comptoir du Libre identifier (optional)",
"comptoir du libre id hint":
"If you the software is listed in the Comptoir du Libre you can add its identifier here. The identifier is either a numeric id or the url of the product page.",
Expand Down Expand Up @@ -1034,37 +1009,8 @@ const {
"Système d'exploitation sur lequel le logiciel peut être installé"
},
"SoftwareFormStep2": {
"wikidata id": "Fiche Wikidata",
"wikidata id hint": ({
wikidataUrl,
wikidataPageExampleUrl,
exampleSoftwareName,
softwareSillUrl
}) => (
<>
Renseignez le nom du logiciel ou directement l'identifiant (de la
forme <code>QXXXXX</code>) pour associer le logiciel à une fiche
existante{" "}
<a href={wikidataUrl} target="_blank" rel="noreferrer">
Wikidata
</a>
.
<br />
La plupart des informations générales, telles que le logo ou l'URL
du dépôt de code, sont extraites de Wikidata. Si le logiciel que
vous souhaitez ajouter ne possède pas encore de fiche sur
Wikidata, vous pouvez en créer une. Vous trouverez ici un{" "}
<a href={wikidataPageExampleUrl} target="_blank" rel="noreferrer">
exemple de fiche Wikidata
</a>{" "}
pour le logiciel&nbsp;
<a href={softwareSillUrl} target="_blank" rel="noreferrer">
{exampleSoftwareName}
</a>.{" "}
</>
),
"wikidata id information":
"Cette information remplira automatiquement d'autres champs",
"external id": externalId("fr"),
"external id hint": externalIdHint("fr"),
"comptoir du libre id": "Identifiant Comptoir du Libre (Optionnel)",
"comptoir du libre id hint":
"Si le logiciel est présent sur le comptoir du libre vous pouvez renseigner son identifiant ou l'URL de sa fiche",
Expand Down Expand Up @@ -1515,3 +1461,175 @@ const declarationTypeToEnglish: Record<DeclarationType, string> = {
user: "user",
referent: "referent"
};

type I18nTextByExternalSourceByLanguage = Record<
Language,
Record<ExternalDataOrigin, ReactNode>
>;

const linksByExternalDataSource: Record<
ExternalDataOrigin,
{
externalSourceUrl: string;
externalSourcePageExampleUrl: string;
softwareSillUrl: string;
exampleSoftwareName: string;
}
> = {
wikidata: {
"externalSourceUrl": "https://www.wikidata.org/wiki",
"externalSourcePageExampleUrl": "https://www.wikidata.org/wiki/Q107693197",
"softwareSillUrl": "https://code.gouv.fr/sill/detail?name=Keycloakify",
"exampleSoftwareName": "Keycloakify"
},
HAL: {
"externalSourceUrl": "https://hal.science",
"externalSourcePageExampleUrl": "https://hal.science/hal-02818886v1",
"softwareSillUrl": "",
"exampleSoftwareName": ""
}
};

function externalId(language: Language) {
return (externalDataOrigin: ExternalDataOrigin) => {
const externalIdBySource: I18nTextByExternalSourceByLanguage = {
fr: {
wikidata: "Fiche Wikidata",
HAL: "Fiche HAL"
},
en: {
wikidata: "Wikidata item",
HAL: "HAL item"
}
};

return externalIdBySource[language][externalDataOrigin];
};
}

function externalIdHint(language: Language) {
return (externalDataOrigin: ExternalDataOrigin) => {
const {
exampleSoftwareName,
externalSourcePageExampleUrl,
externalSourceUrl,
softwareSillUrl
} = linksByExternalDataSource[externalDataOrigin];

const externalIdHintByExternalSourceByLanguage: I18nTextByExternalSourceByLanguage =
{
fr: {
wikidata: (
<>
Renseignez le nom du logiciel ou directement l'identifiant (de
la forme <code>QXXXXX</code>) pour associer le logiciel à une
fiche existante{" "}
<a href={externalSourceUrl} target="_blank" rel="noreferrer">
Wikidata
</a>
.
<br />
La plupart des informations générales, telles que le logo ou
l'URL du dépôt de code, sont extraites de Wikidata. Si le
logiciel que vous souhaitez ajouter ne possède pas encore de
fiche sur Wikidata, vous pouvez en créer une. Vous trouverez
ici un{" "}
<a
href={externalSourcePageExampleUrl}
target="_blank"
rel="noreferrer"
>
exemple de fiche Wikidata
</a>{" "}
pour le logiciel&nbsp;
<a href={softwareSillUrl} target="_blank" rel="noreferrer">
{exampleSoftwareName}
</a>
.{" "}
</>
),
HAL: (
<>
Renseignez le nom du logiciel ou directement l'identifiant
(attention, les identifiants HAL sont de la forme
hal-123123v1, il faut fournir uniquement le numéro (sans
'hal-' et sans version), dans ce cas '123123') pour associer
le logiciel à une fiche existante{" "}
<a href={externalSourceUrl} target="_blank" rel="noreferrer">
HAL
</a>
.
<br />
La plupart des informations générales, telles que l'URL du
dépôt de code, sont extraites de HAL. Si le logiciel que vous
souhaitez ajouter ne possède pas encore de fiche sur HAL, vous
pouvez en créer une. Vous trouverez ici un{" "}
<a
href={externalSourcePageExampleUrl}
target="_blank"
rel="noreferrer"
>
exemple de fiche HAL
</a>
.
</>
)
},
en: {
wikidata: (
<>
Fill up a name or directly the id (of the form{" "}
<code>Qxxxxx</code>) to associate the software with an
existing entry{" "}
<a href={externalSourceUrl} target="_blank" rel="noreferrer">
Wikidata
</a>
.
<br />
Most general information, such as the logo or the URL of the
code repository, is extracted from Wikidata. If the software
you want to add does not have a Wikidata entry yet, you can
create one . Find here an{" "}
<a
href={externalSourcePageExampleUrl}
target="_blank"
rel="noreferrer"
>
example of a Wikidata entry
</a>
&nbsp; for the software&nbsp;
<a href={softwareSillUrl} target="_blank" rel="noreferrer">
{exampleSoftwareName}
</a>{" "}
</>
),
HAL: (
<>
Fill up a name or directly the id (careful, HAL ids look like
'hal-123123v1', but only the number should be provided
(without 'hal-' or the version), in this case it should be
'123123') to associate the software with an existing entry{" "}
<a href={externalSourceUrl} target="_blank" rel="noreferrer">
Wikidata
</a>
.
<br />
Most general information, such as the URL of the code
repository, is extracted from HAL. If the software you want to
add does not have a Hal entry yet, you can create one. Find
here an{" "}
<a
href={externalSourcePageExampleUrl}
target="_blank"
rel="noreferrer"
>
example of an HAL entry
</a>
</>
)
}
};

return externalIdHintByExternalSourceByLanguage[language][externalDataOrigin];
};
}
Loading

0 comments on commit 32461c1

Please sign in to comment.