Skip to content

Commit

Permalink
fix types to fit with instance without other wikidata softwares
Browse files Browse the repository at this point in the history
  • Loading branch information
JeromeBu committed Jul 26, 2024
1 parent 5676443 commit 1e66422
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 79 deletions.
9 changes: 1 addition & 8 deletions api/src/core/usecases/readWriteSillData/thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,14 +494,7 @@ export const thunks = {

assert(index !== -1, "Can't update instance, it doesn't exist");

const {
mainSoftwareSillId,
organization,
otherSoftwareWikidataIds,
publicUrl,
targetAudience,
...rest
} = formData;
const { mainSoftwareSillId, organization, publicUrl, targetAudience, ...rest } = formData;

assert<Equals<typeof rest, {}>>();

Expand Down
1 change: 0 additions & 1 deletion api/src/core/usecases/readWriteSillData/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,4 @@ export type InstanceFormData = {
organization: string;
targetAudience: string;
publicUrl: string | undefined;
otherSoftwareWikidataIds: string[];
};
3 changes: 1 addition & 2 deletions api/src/rpc/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,7 @@ const zInstanceFormData = (() => {
"mainSoftwareSillId": z.number(),
"organization": z.string(),
"targetAudience": z.string(),
"publicUrl": z.string().optional(),
"otherSoftwareWikidataIds": z.array(z.string())
"publicUrl": z.string().optional()
});

{
Expand Down
1 change: 0 additions & 1 deletion api/src/tools/test.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,5 @@ export const createInstanceFormData = makeObjectFactory<InstanceFormData>({
organization: "Default organization",
targetAudience: "Default audience",
mainSoftwareSillId: 1,
otherSoftwareWikidataIds: [],
publicUrl: "https://example.com"
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"test": "turbo test",
"format": "turbo format",
"format:check": "turbo format:check",
"fullcheck": "turbo typecheck format:check test"
"fullcheck": "turbo typecheck format:check lint test"
},
"devDependencies": {
"turbo": "^1.12.5"
Expand Down
3 changes: 2 additions & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"dev": {},
"format:check": {},
"format": {}
"format": {},
"lint": {}
}
}
1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"build": "react-app-rewired build && rimraf build/keycloak-resources",
"build-keycloak-theme": "yarn build && keycloakify",
"storybook": "start-storybook -p 6006",
"lint": "eslint --ext .ts,.tsx,.js,.jsx src",
"_format": "prettier '**/*.{ts,tsx,json,md}'",
"format": "yarn _format --write",
"format:check": "yarn _format --list-different",
Expand Down
2 changes: 1 addition & 1 deletion web/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<link rel="shortcut icon" href="%PUBLIC_URL%/dsfr/favicon/favicon.ico?v=1.12.1" type="image/x-icon" />
<link rel="manifest" href="%PUBLIC_URL%/dsfr/favicon/manifest.webmanifest?v=1.12.1" crossorigin="use-credentials" />

<link rel="stylesheet" href="%PUBLIC_URL%/dsfr/utility/icons/icons.min.css?hash=cfdb5c1c" />
<link rel="stylesheet" href="%PUBLIC_URL%/dsfr/utility/icons/icons.min.css?hash=3375e412" />
<link rel="stylesheet" href="%PUBLIC_URL%/dsfr/dsfr.min.css?v=1.12.1" />

<%
Expand Down
1 change: 0 additions & 1 deletion web/src/core/adapter/sillApiMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export const sillApi: SillApi = {
"id": 0,
"mainSoftwareSillId": 9,
"organization": "CNRS",
"otherWikidataSoftwares": [],
"publicUrl": "https://videos.ahp-numerique.fr/",
"targetAudience": `Plateforme vidéos des Archives Henri-Poincaré (laboratoire du CNRS, de l'Université de Lorraine et de
l'Université de Strasbourg). Vous y trouverez des vidéos de philosophie et d'histoire des sciences et des techniques.`
Expand Down
6 changes: 1 addition & 5 deletions web/src/core/usecases/instanceForm/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { State as RootState } from "core/bootstrap";
import { createSelector } from "redux-clean-architecture";
import { name, type WikidataEntry } from "./state";
import { name } from "./state";
import { assert } from "tsafe/assert";

const readyState = (rootState: RootState) => {
Expand All @@ -23,7 +23,6 @@ const initializationData = createSelector(
| undefined
| {
mainSoftwareSillId: number | undefined;
otherSoftwares: WikidataEntry[];
organization: string | undefined;
publicUrl: string | undefined;
targetAudience: string | undefined;
Expand All @@ -37,7 +36,6 @@ const initializationData = createSelector(
if (preFillData === undefined) {
return {
"mainSoftwareSillId": undefined,
"otherSoftwares": [],
"organization": undefined,
"publicUrl": undefined,
"targetAudience": undefined
Expand All @@ -48,15 +46,13 @@ const initializationData = createSelector(
case "update":
return {
"mainSoftwareSillId": preFillData.mainSoftwareSillId,
"otherSoftwares": preFillData.otherWikidataSoftwares,
"organization": preFillData.organization,
"publicUrl": preFillData.publicUrl,
"targetAudience": preFillData.targetAudience
};
case "navigated from software form":
return {
"mainSoftwareSillId": preFillData.justRegisteredSoftwareSillId,
"otherSoftwares": [],
"organization": undefined,
"publicUrl": undefined,
"targetAudience": undefined
Expand Down
2 changes: 0 additions & 2 deletions web/src/core/usecases/instanceForm/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ namespace State {
type: "update";
instanceId: number;
mainSoftwareSillId: number;
otherWikidataSoftwares: WikidataEntry[];
organization: string;
publicUrl: string | undefined;
targetAudience: string;
Expand All @@ -41,7 +40,6 @@ namespace State {
step1Data:
| {
mainSoftwareSillId: number;
otherWikidataSoftwares: WikidataEntry[];
}
| undefined;
isSubmitting: boolean;
Expand Down
18 changes: 4 additions & 14 deletions web/src/core/usecases/instanceForm/thunks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Thunks } from "core/bootstrap";
import { assert } from "tsafe/assert";
import type { ApiTypes } from "api";
import { name, actions, type WikidataEntry } from "./state";
import { name, actions } from "./state";

export const thunks = {
"initialize":
Expand Down Expand Up @@ -59,7 +59,6 @@ export const thunks = {
"type": "update",
"instanceId": instance.id,
"mainSoftwareSillId": instance.mainSoftwareSillId,
"otherWikidataSoftwares": instance.otherWikidataSoftwares,
"organization": instance.organization,
"publicUrl": instance.publicUrl,
"targetAudience": instance.targetAudience
Expand Down Expand Up @@ -115,21 +114,15 @@ export const thunks = {
dispatch(actions.cleared());
},
"completeStep1":
(props: {
mainSoftwareSillId: number;
otherWikidataSoftwares: WikidataEntry[];
}) =>
(props: { mainSoftwareSillId: number }) =>
(...args) => {
const { mainSoftwareSillId, otherWikidataSoftwares } = props;
const { mainSoftwareSillId } = props;

const [dispatch] = args;

dispatch(
actions.step1Completed({
"step1Data": {
mainSoftwareSillId,
otherWikidataSoftwares
}
"step1Data": { mainSoftwareSillId }
})
);
},
Expand All @@ -155,9 +148,6 @@ export const thunks = {
const formData: ApiTypes.InstanceFormData = {
"mainSoftwareSillId": step1Data.mainSoftwareSillId,
organization,
"otherSoftwareWikidataIds": step1Data.otherWikidataSoftwares.map(
({ externalId }) => externalId
),
publicUrl,
targetAudience
};
Expand Down
19 changes: 4 additions & 15 deletions web/src/ui/pages/instanceForm/InstanceForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { declareComponentKeys } from "i18nifty";
import { Stepper } from "@codegouvfr/react-dsfr/Stepper";
import { ActionsFooter } from "ui/shared/ActionsFooter";
import type { PageRoute } from "./route";
import { useLang } from "ui/i18n";
import { LoadingFallback } from "ui/shared/LoadingFallback";

export type Props = {
Expand All @@ -34,10 +33,7 @@ export default function InstanceForm(props: Props) {

const { evtInstanceForm } = useCore().evts;

const {
instanceForm,
softwareForm: { getExternalSoftwareOptions }
} = useCore().functions;
const { instanceForm } = useCore().functions;

const {
isReady,
Expand Down Expand Up @@ -106,8 +102,6 @@ export default function InstanceForm(props: Props) {

const evtActionSubmitStep = useConst(() => Evt.create());

const { lang } = useLang();

if (!isReady) {
return <LoadingFallback className={className} showAfterMs={150} />;
}
Expand Down Expand Up @@ -147,16 +141,11 @@ export default function InstanceForm(props: Props) {
<InstanceFormStep1
className={cx(classes.step, classes.step1)}
initialFormData={{
"mainSoftwareSillId": initializationData.mainSoftwareSillId,
"otherWikidataSoftwares": initializationData.otherSoftwares
"mainSoftwareSillId": initializationData.mainSoftwareSillId
}}
getLibreSoftwareWikidataOptions={queryString =>
getExternalSoftwareOptions({ queryString, "language": lang })
}
onSubmit={({ mainSoftwareSillId, otherWikidataSoftwares }) =>
onSubmit={({ mainSoftwareSillId }) =>
instanceForm.completeStep1({
mainSoftwareSillId,
otherWikidataSoftwares
mainSoftwareSillId
})
}
allSillSoftwares={allSillSoftwares}
Expand Down
33 changes: 6 additions & 27 deletions web/src/ui/pages/instanceForm/Step1.tsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,34 @@
import { fr } from "@codegouvfr/react-dsfr";
import type { useCore } from "core";
import type { WikidataEntry } from "core/usecases/instanceForm";
import type { NonPostableEvt } from "evt";
import { useEvt } from "evt/hooks";
import { declareComponentKeys } from "i18nifty";
import { useState } from "react";
import { Controller, useForm } from "react-hook-form";
import { assert } from "tsafe/assert";
import { useResolveLocalizedString, useTranslation } from "ui/i18n";
import { useTranslation } from "ui/i18n";
import { AutocompleteInput } from "ui/shared/AutocompleteInput";

export type Step1Props = {
className?: string;
initialFormData: {
mainSoftwareSillId: number | undefined;
otherWikidataSoftwares: WikidataEntry[];
};
onSubmit: (formData: {
mainSoftwareSillId: number;
otherWikidataSoftwares: WikidataEntry[];
}) => void;
onSubmit: (formData: { mainSoftwareSillId: number }) => void;
allSillSoftwares: {
softwareName: string;
softwareSillId: number;
softwareDescription: string;
}[];
evtActionSubmit: NonPostableEvt<void>;
getLibreSoftwareWikidataOptions: (
queryString: string
) => ReturnType<
ReturnType<
typeof useCore
>["functions"]["softwareForm"]["getExternalSoftwareOptions"]
>;
};

export function InstanceFormStep1(props: Step1Props) {
const {
className,
initialFormData,
onSubmit,
evtActionSubmit,
getLibreSoftwareWikidataOptions,
allSillSoftwares
} = props;
const { className, initialFormData, onSubmit, evtActionSubmit, allSillSoftwares } =
props;

const { t } = useTranslation({ InstanceFormStep1 });
const { t: tCommon } = useTranslation({ "App": null });
const { resolveLocalizedString } = useResolveLocalizedString();

const {
handleSubmit,
Expand Down Expand Up @@ -77,8 +58,7 @@ export function InstanceFormStep1(props: Step1Props) {
assert(mainSoftware !== undefined);

return mainSoftware;
})(),
"otherWikidataSoftwares": initialFormData.otherWikidataSoftwares
})()
}
});

Expand All @@ -101,8 +81,7 @@ export function InstanceFormStep1(props: Step1Props) {
className={className}
onSubmit={handleSubmit(data =>
onSubmit({
"mainSoftwareSillId": data.mainSoftware.softwareSillId,
"otherWikidataSoftwares": data.otherWikidataSoftwares
"mainSoftwareSillId": data.mainSoftware.softwareSillId
})
)}
>
Expand Down

0 comments on commit 1e66422

Please sign in to comment.