diff --git a/src/core/adapter/sillApi.ts b/src/core/adapter/sillApi.ts index fe394a24..5255094b 100644 --- a/src/core/adapter/sillApi.ts +++ b/src/core/adapter/sillApi.ts @@ -59,9 +59,10 @@ export function createSillApi(params: { "getInstances": memoize(() => trpcClient.getInstances.query(), { "promise": true }), - "getWikidataOptions": params => trpcClient.getWikidataOptions.query(params), - "getSoftwareFormAutoFillDataFromWikidataAndOtherSources": params => - trpcClient.getSoftwareFormAutoFillDataFromWikidataAndOtherSources.query( + "getExternalSoftwareOptions": params => + trpcClient.getExternalSoftwareOptions.query(params), + "getSoftwareFormAutoFillDataFromExternalSoftwareAndOtherSources": params => + trpcClient.getSoftwareFormAutoFillDataFromExternalSoftwareAndOtherSources.query( params ), "createSoftware": async params => { diff --git a/src/core/adapter/sillApiMock.ts b/src/core/adapter/sillApiMock.ts index 44165fcc..37331c05 100644 --- a/src/core/adapter/sillApiMock.ts +++ b/src/core/adapter/sillApiMock.ts @@ -1,3 +1,4 @@ +import { SoftwareExternalDataOption } from "@codegouvfr/sill/core/ports/GetSoftwareExternalDataOptions"; import memoize from "memoizee"; import type { SillApi } from "../ports/SillApi"; import { id } from "tsafe/id"; @@ -45,7 +46,7 @@ export const sillApi: SillApi = { }, { "promise": true } ), - "getWikidataOptions": async ({ queryString }) => { + "getExternalSoftwareOptions": async ({ queryString }) => { if (queryString === "") { return []; } @@ -54,15 +55,17 @@ export const sillApi: SillApi = { return options; }, - "getSoftwareFormAutoFillDataFromWikidataAndOtherSources": async ({ wikidataId }) => { + "getSoftwareFormAutoFillDataFromExternalSoftwareAndOtherSources": async ({ + externalId + }) => { await new Promise(resolve => setTimeout(resolve, 1)); return { - wikidataId, + externalId, "comptoirDuLibreId": 123, - "softwareName": `Software ${wikidataId}`, - "softwareDescription": `Software ${wikidataId} description`, - "softwareLicense": `Software ${wikidataId} license`, + "softwareName": `Software ${externalId}`, + "softwareDescription": `Software ${externalId} description`, + "softwareLicense": `Software ${externalId} license`, "softwareMinimalVersion": `1.3.4`, "softwareLogoUrl": undefined, "keywords": [] @@ -86,7 +89,8 @@ export const sillApi: SillApi = { "versionMin": "3.9.0", "comptoirDuLibreServiceProviderCount": 0, "comptoirDuLibreId": formData.comptoirDuLibreId, - "wikidataId": formData.wikidataId, + "externalId": formData.externalId, + "externalDataOrigin": "wikidata", "license": formData.softwareLicense, "officialWebsiteUrl": undefined, "documentationUrl": undefined, @@ -139,7 +143,8 @@ export const sillApi: SillApi = { "versionMin": "3.9.0", "comptoirDuLibreServiceProviderCount": 0, "comptoirDuLibreId": formData.comptoirDuLibreId, - "wikidataId": formData.wikidataId, + "externalId": formData.externalId, + "externalDataOrigin": "wikidata", "license": formData.softwareLicense, "officialWebsiteUrl": undefined, "documentationUrl": undefined, @@ -234,49 +239,55 @@ export const sillApi: SillApi = { } }; -const options = [ +const options: (SoftwareExternalDataOption & { isInSill: boolean })[] = [ { - "wikidataId": "Q110492908", + "externalId": "Q110492908", "label": "Onyxia", "description": "A data science oriented container launcher", - "isInSill": true, - "isLibreSoftware": true + "isLibreSoftware": true, + "externalDataOrigin": "wikidata", + "isInSill": true }, { - "wikidataId": "Q107693197", + "externalId": "Q107693197", "label": "Keycloakify", "description": "Build tool for creating Keycloak themes using React", - "isInSill": true, - "isLibreSoftware": true + "isLibreSoftware": true, + "externalDataOrigin": "wikidata", + "isInSill": true }, { - "wikidataId": "Q8038", + "externalId": "Q8038", "description": "image retouching and editing tool", "label": "GIMP", - "isInSill": true, - "isLibreSoftware": true + "isLibreSoftware": true, + "externalDataOrigin": "wikidata", + "isInSill": true }, { - "wikidataId": "Q10135", + "externalId": "Q10135", "description": "office suite supported by the free software community", "label": "LibreOffice", - "isInSill": true, - "isLibreSoftware": true + "isLibreSoftware": true, + "externalDataOrigin": "wikidata", + "isInSill": true }, { - "wikidataId": "Q19841877", + "externalId": "Q19841877", "description": "source code editor developed by Microsoft", "label": "Visual Studio Code", - "isInSill": true, - "isLibreSoftware": true + "isLibreSoftware": true, + "externalDataOrigin": "wikidata", + "isInSill": true }, { - "wikidataId": "Q50938515", + "externalId": "Q50938515", "description": "decentralized video hosting network, based on free/libre software", "label": "PeerTube", - "isInSill": true, - "isLibreSoftware": true + "isLibreSoftware": true, + "externalDataOrigin": "wikidata", + "isInSill": true } ]; @@ -296,13 +307,15 @@ const softwares = [ { "description": "team collaboration and videoconferencing application developed by Microsoft", - "wikidataId": "Q28406404", + "externalId": "Q28406404", "label": "Microsoft Teams", "isLibreSoftware": false, - "isInSill": false + "isInSill": false, + "externalDataOrigin": "wikidata" } ], - "wikidataId": "Q25874683", + "externalId": "Q25874683", + "externalDataOrigin": "wikidata", "license": "AGPL-3.0-or-later", "officialWebsiteUrl": undefined, "documentationUrl": undefined, @@ -350,13 +363,15 @@ const softwares = [ { "description": "team collaboration and videoconferencing application developed by Microsoft", - "wikidataId": "Q28406404", + "externalId": "Q28406404", "label": "Microsoft Teams", "isLibreSoftware": false, - "isInSill": false + "isInSill": false, + "externalDataOrigin": "wikidata" } ], - "wikidataId": "Q10135", + "externalId": "Q10135", + "externalDataOrigin": "wikidata", "license": "MPL-2.0", "officialWebsiteUrl": "https://www.libreoffice.org/", "documentationUrl": "https://www.libreoffice.org/", @@ -417,7 +432,8 @@ const softwares = [ "comptoirDuLibreId": 38, "annuaireCnllServiceProviders": [], "similarSoftwares": [], - "wikidataId": "Q10135", + "externalId": "Q10135", + "externalDataOrigin": "wikidata", "softwareType": { "type": "cloud" }, @@ -468,7 +484,8 @@ const softwares = [ "comptoirDuLibreId": 62, "annuaireCnllServiceProviders": [], "similarSoftwares": [], - "wikidataId": "Q171477", + "externalId": "Q171477", + "externalDataOrigin": "wikidata", "license": "GPL-2.0-only", "officialWebsiteUrl": "https://www.wikidata.org/wiki/Q171477", "documentationUrl": undefined, @@ -521,13 +538,15 @@ const softwares = [ { "description": "team collaboration and videoconferencing application developed by Microsoft", - "wikidataId": "Q28406404", + "externalId": "Q28406404", "label": "Microsoft Teams", "isLibreSoftware": false, - "isInSill": false + "isInSill": false, + "externalDataOrigin": "wikidata" } ], - "wikidataId": "Q7715973", + "externalId": "Q7715973", + "externalDataOrigin": "wikidata", "license": "N/A", "officialWebsiteUrl": "https://www.debian.org/", "documentationUrl": undefined, @@ -581,7 +600,8 @@ const softwares = [ "comptoirDuLibreServiceProviderCount": 9, "comptoirDuLibreId": 80, "annuaireCnllServiceProviders": [], - "wikidataId": "Q483604", + "externalId": "Q483604", + "externalDataOrigin": "wikidata", "license": "MPL-2.0", "officialWebsiteUrl": "https://www.thunderbird.net/", "documentationUrl": undefined, @@ -605,7 +625,8 @@ const softwares = [ { "description": "team collaboration and videoconferencing application developed by Microsoft", - "wikidataId": "Q28406404", + "externalId": "Q28406404", + "externalDataOrigin": "wikidata", "label": "Microsoft Teams", "isLibreSoftware": false, "isInSill": false @@ -645,7 +666,8 @@ const softwares = [ "comptoirDuLibreId": 60, "annuaireCnllServiceProviders": [], "similarSoftwares": [], - "wikidataId": "Q1329181", + "externalId": "Q1329181", + "externalDataOrigin": "wikidata", "license": "GPL-2.0-or-later", "officialWebsiteUrl": "https://qgis.org/fr/site/", "documentationUrl": undefined, @@ -713,7 +735,8 @@ const softwares = [ "comptoirDuLibreServiceProviderCount": 3, "comptoirDuLibreId": 82, "annuaireCnllServiceProviders": [], - "wikidataId": "Q698", + "externalId": "Q698", + "externalDataOrigin": "wikidata", "license": "MPL-2.0", "officialWebsiteUrl": "https://www.mozilla.org/fr/firefox/new/", "documentationUrl": undefined, @@ -770,7 +793,8 @@ const softwares = [ "comptoirDuLibreId": 123, "annuaireCnllServiceProviders": [], "similarSoftwares": [], - "wikidataId": "Q192490", + "externalId": "Q192490", + "externalDataOrigin": "wikidata", "license": "PostgreSQL", "officialWebsiteUrl": "https://www.postgresql.org/", "documentationUrl": undefined, @@ -815,7 +839,8 @@ const softwares = [ "comptoirDuLibreId": 140, "annuaireCnllServiceProviders": [], "similarSoftwares": [], - "wikidataId": "Q50938515", + "externalId": "Q50938515", + "externalDataOrigin": "wikidata", "license": "AGPL-3.0-or-later", "officialWebsiteUrl": "https://joinpeertube.org/", "documentationUrl": undefined, @@ -857,7 +882,8 @@ const softwares = [ "comptoirDuLibreServiceProviderCount": 1, "comptoirDuLibreId": 368, "annuaireCnllServiceProviders": [], - "wikidataId": "Q77064547", + "externalId": "Q77064547", + "externalDataOrigin": "wikidata", "license": "MIT", "officialWebsiteUrl": "https://archifiltre.fabrique.social.gouv.fr/", "documentationUrl": undefined, @@ -902,7 +928,8 @@ const softwares = [ "comptoirDuLibreServiceProviderCount": 1, "comptoirDuLibreId": 368, "annuaireCnllServiceProviders": [], - "wikidataId": "Q77064547", + "externalId": "Q77064547", + "externalDataOrigin": "wikidata", "license": "MIT", "officialWebsiteUrl": "https://archifiltre.fabrique.social.gouv.fr/", "documentationUrl": undefined, @@ -947,7 +974,8 @@ const softwares = [ "comptoirDuLibreServiceProviderCount": 1, "comptoirDuLibreId": 368, "annuaireCnllServiceProviders": [], - "wikidataId": "Q77064547", + "externalId": "Q77064547", + "externalDataOrigin": "wikidata", "license": "MIT", "officialWebsiteUrl": "https://archifiltre.fabrique.social.gouv.fr/", "documentationUrl": undefined, @@ -992,7 +1020,8 @@ const softwares = [ "comptoirDuLibreServiceProviderCount": 1, "comptoirDuLibreId": 368, "annuaireCnllServiceProviders": [], - "wikidataId": "Q77064547", + "externalId": "Q77064547", + "externalDataOrigin": "wikidata", "license": "MIT", "officialWebsiteUrl": "https://archifiltre.fabrique.social.gouv.fr/", "documentationUrl": undefined, @@ -1037,7 +1066,8 @@ const softwares = [ "comptoirDuLibreServiceProviderCount": 1, "comptoirDuLibreId": 368, "annuaireCnllServiceProviders": [], - "wikidataId": "Q77064547", + "externalId": "Q77064547", + "externalDataOrigin": "wikidata", "license": "MIT", "officialWebsiteUrl": "https://archifiltre.fabrique.social.gouv.fr/", "documentationUrl": undefined, @@ -1082,7 +1112,8 @@ const softwares = [ "comptoirDuLibreServiceProviderCount": 1, "comptoirDuLibreId": 368, "annuaireCnllServiceProviders": [], - "wikidataId": "Q77064547", + "externalId": "Q77064547", + "externalDataOrigin": "wikidata", "license": "MIT", "officialWebsiteUrl": "https://archifiltre.fabrique.social.gouv.fr/", "documentationUrl": undefined, @@ -1127,7 +1158,8 @@ const softwares = [ "annuaireCnllServiceProviders": [], "comptoirDuLibreServiceProviderCount": 1, "comptoirDuLibreId": 368, - "wikidataId": "Q77064547", + "externalId": "Q77064547", + "externalDataOrigin": "wikidata", "license": "MIT", "officialWebsiteUrl": "https://archifiltre.fabrique.social.gouv.fr/", "documentationUrl": undefined, @@ -1172,7 +1204,8 @@ const softwares = [ "annuaireCnllServiceProviders": [], "comptoirDuLibreServiceProviderCount": 1, "comptoirDuLibreId": 368, - "wikidataId": "Q77064547", + "externalId": "Q77064547", + "externalDataOrigin": "wikidata", "license": "MIT", "officialWebsiteUrl": "https://archifiltre.fabrique.social.gouv.fr/", "documentationUrl": undefined, diff --git a/src/core/ports/SillApi.ts b/src/core/ports/SillApi.ts index 6d290728..bb171315 100644 --- a/src/core/ports/SillApi.ts +++ b/src/core/ports/SillApi.ts @@ -33,13 +33,13 @@ export type SillApi = { (): Promise; clear: () => void; }; - getWikidataOptions: ( - params: TrpcRouterInput["getWikidataOptions"] - ) => Promise; - getSoftwareFormAutoFillDataFromWikidataAndOtherSources: ( - params: TrpcRouterInput["getSoftwareFormAutoFillDataFromWikidataAndOtherSources"] + getExternalSoftwareOptions: ( + params: TrpcRouterInput["getExternalSoftwareOptions"] + ) => Promise; + getSoftwareFormAutoFillDataFromExternalSoftwareAndOtherSources: ( + params: TrpcRouterInput["getSoftwareFormAutoFillDataFromExternalSoftwareAndOtherSources"] ) => Promise< - TrpcRouterOutput["getSoftwareFormAutoFillDataFromWikidataAndOtherSources"] + TrpcRouterOutput["getSoftwareFormAutoFillDataFromExternalSoftwareAndOtherSources"] >; createSoftware: ( params: TrpcRouterInput["createSoftware"] diff --git a/src/core/usecases/instanceForm/state.ts b/src/core/usecases/instanceForm/state.ts index 08a90086..8fa8402f 100644 --- a/src/core/usecases/instanceForm/state.ts +++ b/src/core/usecases/instanceForm/state.ts @@ -7,7 +7,7 @@ import type { Language } from "@codegouvfr/sill"; export type WikidataEntry = { label: LocalizedString; description: LocalizedString; - wikidataId: string; + externalId: string; }; type State = State.NotInitialized | State.Ready; diff --git a/src/core/usecases/instanceForm/thunks.ts b/src/core/usecases/instanceForm/thunks.ts index 7d8291f6..440a3dc4 100644 --- a/src/core/usecases/instanceForm/thunks.ts +++ b/src/core/usecases/instanceForm/thunks.ts @@ -156,7 +156,7 @@ export const thunks = { "mainSoftwareSillId": step1Data.mainSoftwareSillId, organization, "otherSoftwareWikidataIds": step1Data.otherWikidataSoftwares.map( - ({ wikidataId }) => wikidataId + ({ externalId }) => externalId ), publicUrl, targetAudience diff --git a/src/core/usecases/softwareCatalog/selectors.ts b/src/core/usecases/softwareCatalog/selectors.ts index e102ef2c..27b38587 100644 --- a/src/core/usecases/softwareCatalog/selectors.ts +++ b/src/core/usecases/softwareCatalog/selectors.ts @@ -1,4 +1,5 @@ import "minimal-polyfills/Object.fromEntries"; +import type { ExternalDataOrigin } from "@codegouvfr/sill/core/ports/GetSoftwareExternalData"; import { createCompareFn } from "core/tools/compareFn"; import type { State as RootState } from "core/bootstrap"; import { createSelector } from "redux-clean-architecture"; @@ -684,15 +685,7 @@ function filterByPrerogative(params: { function apiSoftwareToInternalSoftware(params: { apiSoftwares: ApiTypes.Software[]; - softwareRef: - | { - type: "wikidataId"; - wikidataId: string; - } - | { - type: "name"; - softwareName: string; - }; + softwareRef: SoftwareRef; userDeclaration: | { isUser: boolean; @@ -707,8 +700,8 @@ function apiSoftwareToInternalSoftware(params: { switch (softwareRef.type) { case "name": return apiSoftware.softwareName === softwareRef.softwareName; - case "wikidataId": - return apiSoftware.wikidataId === softwareRef.wikidataId; + case "externalId": + return apiSoftware.externalId === softwareRef.externalId; } }); @@ -749,7 +742,7 @@ function apiSoftwareToInternalSoftware(params: { in_sill: { const software = apiSoftwares.find( - software => software.wikidataId === parentWikidataSoftware.wikidataId + software => software.externalId === parentWikidataSoftware.externalId ); if (software === undefined) { @@ -765,7 +758,7 @@ function apiSoftwareToInternalSoftware(params: { return { "isInSill": false, "softwareName": resolveLocalizedString(parentWikidataSoftware.label), - "url": `https://www.wikidata.org/wiki/${parentWikidataSoftware.wikidataId}` + "url": `https://www.wikidata.org/wiki/${parentWikidataSoftware.externalId}` }; })(); @@ -882,17 +875,20 @@ function internalSoftwareToExternalSoftware(params: { }; } +type SoftwareRef = + | { + type: "externalId"; + externalDataOrigin: ExternalDataOrigin; + externalId: string; + } + | { + type: "name"; + softwareName: string; + }; + export function apiSoftwareToExternalCatalogSoftware(params: { apiSoftwares: ApiTypes.Software[]; - softwareRef: - | { - type: "wikidataId"; - wikidataId: string; - } - | { - type: "name"; - softwareName: string; - }; + softwareRef: SoftwareRef; }): State.Software.External | undefined { const { apiSoftwares, softwareRef } = params; diff --git a/src/core/usecases/softwareCatalog/thunks.ts b/src/core/usecases/softwareCatalog/thunks.ts index 31dfdb0b..7cfeacae 100644 --- a/src/core/usecases/softwareCatalog/thunks.ts +++ b/src/core/usecases/softwareCatalog/thunks.ts @@ -204,7 +204,7 @@ function apiSoftwareToInternalSoftware(params: { case "name": return apiSoftware.softwareName === softwareRef.softwareName; case "wikidataId": - return apiSoftware.wikidataId === softwareRef.wikidataId; + return apiSoftware.externalId === softwareRef.wikidataId; } }); @@ -245,7 +245,7 @@ function apiSoftwareToInternalSoftware(params: { in_sill: { const software = apiSoftwares.find( - software => software.wikidataId === parentWikidataSoftware.wikidataId + software => software.externalId === parentWikidataSoftware.externalId ); if (software === undefined) { @@ -261,7 +261,7 @@ function apiSoftwareToInternalSoftware(params: { return { "isInSill": false, "softwareName": resolveLocalizedString(parentWikidataSoftware.label), - "url": `https://www.wikidata.org/wiki/${parentWikidataSoftware.wikidataId}` + "url": `https://www.wikidata.org/wiki/${parentWikidataSoftware.externalId}` }; })(); diff --git a/src/core/usecases/softwareDetails/thunks.ts b/src/core/usecases/softwareDetails/thunks.ts index 062de657..9666da2d 100644 --- a/src/core/usecases/softwareDetails/thunks.ts +++ b/src/core/usecases/softwareDetails/thunks.ts @@ -186,7 +186,7 @@ function apiSoftwareToSoftware(params: { comptoirDuLibreServiceProviderCount, comptoirDuLibreId, similarSoftwares: similarSoftwares_api, - wikidataId, + externalId, license, versionMin, softwareType, @@ -207,7 +207,7 @@ function apiSoftwareToSoftware(params: { in_sill: { const software = apiSoftwares.find( - software => software.wikidataId === parentWikidataSoftware_api.wikidataId + software => software.externalId === parentWikidataSoftware_api.externalId ); if (software === undefined) { @@ -223,7 +223,7 @@ function apiSoftwareToSoftware(params: { return { "isInSill": false, "softwareName": resolveLocalizedString(parentWikidataSoftware_api.label), - "url": `https://www.wikidata.org/wiki/${parentWikidataSoftware_api.wikidataId}` + "url": `https://www.wikidata.org/wiki/${parentWikidataSoftware_api.externalId}` }; })(); @@ -257,9 +257,9 @@ function apiSoftwareToSoftware(params: { ? undefined : `https://comptoir-du-libre.org/fr/softwares/${comptoirDuLibreId}`, "wikidataUrl": - wikidataId === undefined + externalId === undefined ? undefined - : `https://www.wikidata.org/wiki/${wikidataId}`, + : `https://www.wikidata.org/wiki/${externalId}`, "instances": softwareType.type !== "cloud" ? undefined @@ -285,8 +285,9 @@ function apiSoftwareToSoftware(params: { "softwareName": similarSoftware.softwareName } : { - "type": "wikidataId", - "wikidataId": similarSoftware.wikidataId + "type": "externalId", + "externalId": similarSoftware.externalId, + "externalDataOrigin": similarSoftware.externalDataOrigin } }); @@ -295,7 +296,7 @@ function apiSoftwareToSoftware(params: { return { "isInSill": false, - "wikidataId": similarSoftware.wikidataId, + "wikidataId": similarSoftware.externalId, "label": similarSoftware.label, "description": similarSoftware.description, "isLibreSoftware": similarSoftware.isLibreSoftware diff --git a/src/core/usecases/softwareForm/state.ts b/src/core/usecases/softwareForm/state.ts index 248aa22c..df1784d5 100644 --- a/src/core/usecases/softwareForm/state.ts +++ b/src/core/usecases/softwareForm/state.ts @@ -1,3 +1,4 @@ +import { ExternalDataOrigin } from "@codegouvfr/sill/core/ports/GetSoftwareExternalData"; import { createUsecaseActions } from "redux-clean-architecture"; import { id } from "tsafe/id"; import { assert } from "tsafe/assert"; @@ -27,7 +28,7 @@ export type FormData = { softwareType: ApiTypes.SoftwareType; }; step2: { - wikidataId: string | undefined; + externalId: string | undefined; comptoirDuLibreId: number | undefined; softwareName: string; softwareDescription: string; @@ -45,7 +46,8 @@ export type FormData = { similarSoftwares: { label: LocalizedString; description: LocalizedString; - wikidataId: string; + externalId: string; + externalDataOrigin: ExternalDataOrigin | undefined; }[]; }; }; @@ -73,7 +75,7 @@ export const { reducer, actions } = createUsecaseActions({ payload }: { payload: { - wikidataId: string; + externalId: string; comptoirDuLibreId: number | undefined; softwareName: string; softwareDescription: string; @@ -85,7 +87,7 @@ export const { reducer, actions } = createUsecaseActions({ } ) => { const { - wikidataId, + externalId, comptoirDuLibreId, softwareName, softwareDescription, @@ -99,7 +101,7 @@ export const { reducer, actions } = createUsecaseActions({ "stateDescription": "ready", "formData": { "step2": { - wikidataId, + externalId, comptoirDuLibreId, softwareName, softwareDescription, diff --git a/src/core/usecases/softwareForm/thunks.ts b/src/core/usecases/softwareForm/thunks.ts index 18ac0a4b..283466ad 100644 --- a/src/core/usecases/softwareForm/thunks.ts +++ b/src/core/usecases/softwareForm/thunks.ts @@ -11,7 +11,7 @@ export const thunks = { params: | { scenario: "create"; - wikidataId: string | undefined; + externalId: string | undefined; } | { scenario: "update"; @@ -34,7 +34,7 @@ export const thunks = { } } - if (params.scenario === "create" && params.wikidataId === undefined) { + if (params.scenario === "create" && params.externalId === undefined) { dispatch(actions.initializedForCreate()); return; } @@ -44,9 +44,9 @@ export const thunks = { switch (params.scenario) { case "create": { - const { wikidataId } = params; + const { externalId } = params; - assert(wikidataId !== undefined); + assert(externalId !== undefined); const { comptoirDuLibreId, @@ -56,11 +56,11 @@ export const thunks = { softwareLogoUrl, softwareMinimalVersion, softwareName - } = await dispatch(thunks.getAutofillData({ wikidataId })); + } = await dispatch(thunks.getAutofillData({ externalId })); dispatch( actions.initializedForCreateWithPreSelectedSoftware({ - wikidataId, + externalId, comptoirDuLibreId, "softwareName": softwareName ?? "", "softwareDescription": softwareDescription ?? "", @@ -90,7 +90,7 @@ export const thunks = { "softwareType": software.softwareType }, "step2": { - "wikidataId": software.wikidataId, + "externalId": software.externalId, "comptoirDuLibreId": software.comptoirDuLibreId, "softwareDescription": software.softwareDescription, @@ -124,7 +124,7 @@ export const thunks = { if ( software === undefined || - software.wikidataId === undefined + software.externalId === undefined ) { return undefined; } @@ -133,8 +133,10 @@ export const thunks = { "label": software.softwareName, "description": software.softwareDescription, - "wikidataId": software.wikidataId, - "isLibreSoftware": true + "isLibreSoftware": true, + "externalId": software.externalId, + "externalDataOrigin": + software.externalDataOrigin }; } }) @@ -208,7 +210,7 @@ export const thunks = { const formData: ApiTypes.SoftwareFormData = { "softwareType": step1.softwareType, - "wikidataId": step2.wikidataId, + "externalId": step2.externalId, "comptoirDuLibreId": step2.comptoirDuLibreId, "softwareName": step2.softwareName, "softwareDescription": step2.softwareDescription, @@ -217,8 +219,8 @@ export const thunks = { "isPresentInSupportContract": step3.isPresentInSupportContract ?? false, "isFromFrenchPublicService": step3.isFromFrenchPublicService, "doRespectRgaa": step3.doRespectRgaa, - "similarSoftwareWikidataIds": formDataStep4.similarSoftwares.map( - ({ wikidataId }) => wikidataId + "similarSoftwareExternalDataIds": formDataStep4.similarSoftwares.map( + ({ externalId }) => externalId ), "softwareLogoUrl": step2.softwareLogoUrl, "softwareKeywords": step2.softwareKeywords @@ -244,33 +246,24 @@ export const thunks = { dispatch(actions.navigatedToPreviousStep()); }, - "getLibreSoftwareWikidataOptions": + "getExternalSoftwareOptions": (props: { queryString: string; language: Language }) => async (...args) => { const { queryString, language } = props; const [, , { sillApi }] = args; - return await sillApi.getWikidataOptions({ queryString, language }); - }, - "getWikidataOptions": - (props: { queryString: string; language: Language }) => - async (...args) => { - const { queryString, language } = props; - - const [, , { sillApi }] = args; - - return await sillApi.getWikidataOptions({ queryString, language }); + return await sillApi.getExternalSoftwareOptions({ queryString, language }); }, "getAutofillData": - (props: { wikidataId: string }) => + (props: { externalId: string }) => (...args) => { - const { wikidataId } = props; + const { externalId } = props; const [, , extraArg] = args; - return extraArg.sillApi.getSoftwareFormAutoFillDataFromWikidataAndOtherSources( - { wikidataId } + return extraArg.sillApi.getSoftwareFormAutoFillDataFromExternalSoftwareAndOtherSources( + { externalId } ); } } satisfies Thunks; diff --git a/src/stories/pages/softwareForm/SoftwareForm.stories.tsx b/src/stories/pages/softwareForm/SoftwareForm.stories.tsx index 384067d1..c9dfb0f9 100644 --- a/src/stories/pages/softwareForm/SoftwareForm.stories.tsx +++ b/src/stories/pages/softwareForm/SoftwareForm.stories.tsx @@ -11,7 +11,7 @@ export default meta; export const VueCreation = getStory({ "route": createMockRoute("softwareCreationForm", { - "wikidataId": undefined + "externalId": undefined }) }); diff --git a/src/ui/pages/instanceForm/InstanceForm.tsx b/src/ui/pages/instanceForm/InstanceForm.tsx index a88b979f..8c8ff7f3 100644 --- a/src/ui/pages/instanceForm/InstanceForm.tsx +++ b/src/ui/pages/instanceForm/InstanceForm.tsx @@ -36,7 +36,7 @@ export default function InstanceForm(props: Props) { const { instanceForm, - softwareForm: { getLibreSoftwareWikidataOptions } + softwareForm: { getExternalSoftwareOptions } } = useCore().functions; const { @@ -151,7 +151,7 @@ export default function InstanceForm(props: Props) { "otherWikidataSoftwares": initializationData.otherSoftwares }} getLibreSoftwareWikidataOptions={queryString => - getLibreSoftwareWikidataOptions({ queryString, "language": lang }) + getExternalSoftwareOptions({ queryString, "language": lang }) } onSubmit={({ mainSoftwareSillId, otherWikidataSoftwares }) => instanceForm.completeStep1({ diff --git a/src/ui/pages/instanceForm/Step1.tsx b/src/ui/pages/instanceForm/Step1.tsx index bb2d87fc..11927026 100644 --- a/src/ui/pages/instanceForm/Step1.tsx +++ b/src/ui/pages/instanceForm/Step1.tsx @@ -32,7 +32,7 @@ export type Step1Props = { ) => ReturnType< ReturnType< typeof useCore - >["functions"]["softwareForm"]["getLibreSoftwareWikidataOptions"] + >["functions"]["softwareForm"]["getExternalSoftwareOptions"] >; }; diff --git a/src/ui/pages/softwareDetails/AlikeSoftwareTab.tsx b/src/ui/pages/softwareDetails/AlikeSoftwareTab.tsx index 656b8f3b..28bd73f3 100644 --- a/src/ui/pages/softwareDetails/AlikeSoftwareTab.tsx +++ b/src/ui/pages/softwareDetails/AlikeSoftwareTab.tsx @@ -21,7 +21,7 @@ export type Props = { "declarationForm" | "softwareDetails" | "softwareUsersAndReferents", Link >; - getAddWikipediaSoftwareToSillLink: (params: { wikidataId: string }) => Link; + getAddWikipediaSoftwareToSillLink: (params: { externalId: string }) => Link; }; export const SimilarSoftwareTab = (props: Props) => { @@ -153,7 +153,7 @@ export const SimilarSoftwareTab = (props: Props) => { iconId="ri-check-fill" linkProps={getAddWikipediaSoftwareToSillLink( { - wikidataId + externalId: wikidataId } )} > diff --git a/src/ui/pages/softwareDetails/SoftwareDetails.tsx b/src/ui/pages/softwareDetails/SoftwareDetails.tsx index 2a29d936..3fe07cd8 100644 --- a/src/ui/pages/softwareDetails/SoftwareDetails.tsx +++ b/src/ui/pages/softwareDetails/SoftwareDetails.tsx @@ -213,10 +213,10 @@ export default function SoftwareDetails(props: Props) { }).link })} getAddWikipediaSoftwareToSillLink={({ - wikidataId + externalId }) => routes.softwareCreationForm({ - wikidataId + externalId: externalId }).link } /> diff --git a/src/ui/pages/softwareForm/SoftwareForm.tsx b/src/ui/pages/softwareForm/SoftwareForm.tsx index 7f0d800b..5a4c09e8 100644 --- a/src/ui/pages/softwareForm/SoftwareForm.tsx +++ b/src/ui/pages/softwareForm/SoftwareForm.tsx @@ -51,7 +51,7 @@ export default function SoftwareForm(props: Props) { case "softwareCreationForm": return { "scenario": "create", - "wikidataId": route.params.wikidataId + "externalId": route.params.externalId }; case "softwareUpdateForm": return { @@ -172,7 +172,7 @@ export default function SoftwareForm(props: Props) { } getAutofillDataFromWikidata={softwareForm.getAutofillData} getLibreSoftwareWikidataOptions={queryString => - softwareForm.getLibreSoftwareWikidataOptions({ + softwareForm.getExternalSoftwareOptions({ "language": lang, queryString }) @@ -200,8 +200,11 @@ export default function SoftwareForm(props: Props) { "formDataStep4": formData }) } - getWikidataOptions={queryString => - softwareForm.getWikidataOptions({ "language": lang, queryString }) + getExternalSoftwareOptions={queryString => + softwareForm.getExternalSoftwareOptions({ + "language": lang, + queryString + }) } /> diff --git a/src/ui/pages/softwareForm/Step2.tsx b/src/ui/pages/softwareForm/Step2.tsx index 9d2c94fb..3a10b443 100644 --- a/src/ui/pages/softwareForm/Step2.tsx +++ b/src/ui/pages/softwareForm/Step2.tsx @@ -29,7 +29,7 @@ export type Step2Props = { ReturnType< ReturnType< typeof useCore - >["functions"]["softwareForm"]["getLibreSoftwareWikidataOptions"] + >["functions"]["softwareForm"]["getExternalSoftwareOptions"] > >; }; @@ -73,16 +73,16 @@ export function SoftwareFormStep2(props: Step2Props) { return undefined; } - const { comptoirDuLibreId, wikidataId, softwareKeywords, ...rest } = + const { comptoirDuLibreId, externalId, softwareKeywords, ...rest } = initialFormData ?? {}; return { ...rest, "wikidataEntry": - wikidataId === undefined + externalId === undefined ? undefined : { - wikidataId, + externalId, "description": "", "label": rest.softwareName }, @@ -134,7 +134,7 @@ export function SoftwareFormStep2(props: Step2Props) { softwareMinimalVersion, softwareLogoUrl } = await getAutofillDataFromWikidata({ - "wikidataId": wikiDataEntry.wikidataId + "externalId": wikiDataEntry.externalId }); if (!isActive) { @@ -214,7 +214,7 @@ export function SoftwareFormStep2(props: Step2Props) { : comptoirDuLibreInputValueToComptoirDuLibreId( comptoirDuLibreIdInputValue ), - "wikidataId": wikidataEntry?.wikidataId + "externalId": wikidataEntry?.externalId }) )} > @@ -233,7 +233,7 @@ export function SoftwareFormStep2(props: Step2Props) { resolveLocalizedString(wikidataEntry.label) } renderOption={(liProps, wikidataEntity) => ( -
  • +
  • {resolveLocalizedString(wikidataEntity.label)} diff --git a/src/ui/pages/softwareForm/Step4.tsx b/src/ui/pages/softwareForm/Step4.tsx index 8bcd7644..79d4b945 100644 --- a/src/ui/pages/softwareForm/Step4.tsx +++ b/src/ui/pages/softwareForm/Step4.tsx @@ -15,18 +15,25 @@ export type Step4Props = { initialFormData: FormData["step4"] | undefined; onSubmit: (formData: FormData["step4"]) => void; evtActionSubmit: NonPostableEvt; - getWikidataOptions: ( + getExternalSoftwareOptions: ( queryString: string ) => Promise< ReturnType< - ReturnType["functions"]["softwareForm"]["getWikidataOptions"] + ReturnType< + typeof useCore + >["functions"]["softwareForm"]["getExternalSoftwareOptions"] > >; }; export function SoftwareFormStep4(props: Step4Props) { - const { className, initialFormData, onSubmit, evtActionSubmit, getWikidataOptions } = - props; + const { + className, + initialFormData, + onSubmit, + evtActionSubmit, + getExternalSoftwareOptions + } = props; const { t } = useTranslation({ SoftwareFormStep4 }); const { handleSubmit, control } = useForm({ @@ -70,7 +77,7 @@ export function SoftwareFormStep4(props: Step4Props) { render={({ field }) => ( field.onChange(value)} getOptionLabel={wikidataEntry => diff --git a/src/ui/pages/softwareForm/route.ts b/src/ui/pages/softwareForm/route.ts index 7ecacc4c..7502c7a0 100644 --- a/src/ui/pages/softwareForm/route.ts +++ b/src/ui/pages/softwareForm/route.ts @@ -3,7 +3,7 @@ import { appPath } from "urls"; export const routeDefs = { "softwareCreationForm": defineRoute( - { "wikidataId": param.query.optional.string }, + { "externalId": param.query.optional.string }, () => appPath + "/add" ), "softwareUpdateForm": defineRoute(