Skip to content

Commit

Permalink
add possiblity to edite an instance. Fixes #64.
Browse files Browse the repository at this point in the history
  • Loading branch information
JeromeBu committed Jan 17, 2024
1 parent 57e3fcc commit 5cdf6a8
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/core/usecases/softwareDetails/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export namespace State {
testUrl: string | undefined;
instances:
| {
id: number;
organization: string;
instanceUrl: string;
targetAudience: string;
Expand Down
1 change: 1 addition & 0 deletions src/core/usecases/softwareDetails/thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ function apiSoftwareToSoftware(params: {
instance.publicUrl === undefined
? undefined
: {
"id": instance.id,
"instanceUrl": instance.publicUrl,
"organization": instance.organization,
"targetAudience": instance.targetAudience
Expand Down
1 change: 1 addition & 0 deletions src/ui/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export const { i18n } = declareComponentKeys<
| "update software"
| "add software or service"
| "add instance"
| "update instance"
| "required"
| "invalid url"
| "invalid version"
Expand Down
8 changes: 6 additions & 2 deletions src/ui/i18n/i18n.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const {
"update software": "Update Software",
"add software or service": "Add Software or Service",
"add instance": "Add Instance",
"update instance": "Update Instance",
"required": "This field is required",
"invalid url": 'Invalid URL. It must start with "http"',
"invalid version": "The value must be numeric (e.g., 2.0.1)",
Expand Down Expand Up @@ -580,7 +581,8 @@ const {
`${instanceCount} maintained instance by ${publicOrganizationCount} public organisation`,
"concerned public": "Concerned public : ",
"go to instance": "Open the instance",
"add instance": "Reference new instance"
"add instance": "Reference new instance",
"edit instance": "Edit instance"
},
"SimilarSoftwareTab": {
"similar software in sill": "Alike software in the SILL",
Expand Down Expand Up @@ -749,6 +751,7 @@ const {
"update software": "Mettre à jour un logiciel",
"add software or service": "Ajouter un logiciel ou un service",
"add instance": "Ajouter une instance",
"update instance": "Modifier une instance",
"required": "Ce champ est requis",
"invalid url": 'URL invalide. Elle doit commencer par "http"',
"invalid version": "La valeur doit être numérique (Exemple : 2.0.1)",
Expand Down Expand Up @@ -1281,7 +1284,8 @@ const {
`${instanceCount} instances maintenues par ${publicOrganizationCount} organisations publiques`,
"concerned public": "Public concerné : ",
"go to instance": "Accéder à l'instance",
"add instance": "Référencer une nouvelle instance"
"add instance": "Référencer une nouvelle instance",
"edit instance": "Éditer l'instance"
},
"SimilarSoftwareTab": {
"similar software in sill": "Logiciels similaires dans le SILL",
Expand Down
40 changes: 21 additions & 19 deletions src/ui/pages/instanceForm/InstanceForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,24 @@ export default function InstanceForm(props: Props) {
const { t } = useTranslation({ InstanceForm });
const { t: tCommon } = useTranslation({ "App": null });

const translationByRoute: Record<
PageRoute["name"],
{ title: string; submitLabel: string; breadcrumbs: string }
> = {
instanceCreationForm: {
title: t("title add instance form"),
breadcrumbs: t("breadcrumb add instance"),
submitLabel: tCommon("add instance")
},
instanceUpdateForm: {
title: t("title update instance form"),
breadcrumbs: t("breadcrumb update instance"),
submitLabel: tCommon("update instance")
}
};

const translations = translationByRoute[route.name];

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

const { lang } = useLang();
Expand All @@ -106,14 +124,7 @@ export default function InstanceForm(props: Props) {
"label": tCommon("add software or service")
}
]}
currentPageLabel={(() => {
switch (route.name) {
case "instanceCreationForm":
return t("breadcrumb add instance");
case "instanceUpdateForm":
return t("breadcrumb update instance");
}
})()}
currentPageLabel={translations.breadcrumbs}
className={classes.breadcrumb}
/>
<div className={classes.headerDeclareUserOrReferent}>
Expand All @@ -125,16 +136,7 @@ export default function InstanceForm(props: Props) {
>
<i className={fr.cx("fr-icon-arrow-left-s-line")} />
</a>
<h4 className={classes.title}>
{(() => {
switch (route.name) {
case "instanceCreationForm":
return t("title add instance form");
case "instanceUpdateForm":
return t("title update instance form");
}
})()}
</h4>
<h4 className={classes.title}>{translations.title}</h4>
</div>
<Stepper
currentStep={step}
Expand Down Expand Up @@ -193,7 +195,7 @@ export default function InstanceForm(props: Props) {
>
{isLastStep ? (
<>
{tCommon("add instance")}
{translations.submitLabel}
{isSubmitting && (
<CircularProgress
size={20}
Expand Down
27 changes: 26 additions & 1 deletion src/ui/pages/softwareDetails/ReferencedInstancesTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,24 @@ import { Accordion } from "@codegouvfr/react-dsfr/Accordion";
import { groupBy } from "lodash";
import { Button } from "@codegouvfr/react-dsfr/Button";
import type { Link } from "type-route";
import { useCore } from "../../../core";
import { routes } from "../../routes";

export type Props = {
className?: string;
instanceList: { organization: string; instanceUrl: string; targetAudience: string }[];
instanceList: {
id: number;
organization: string;
instanceUrl: string;
targetAudience: string;
}[];
createInstanceLink: Link;
};

export const ReferencedInstancesTab = (props: Props) => {
const { className, instanceList, createInstanceLink, ...rest } = props;
const { userAuthentication } = useCore().functions;
const isUserLoggedIn = userAuthentication.getIsUserLoggedIn();

/** Assert to make sure all props are deconstructed */
assert<Equals<typeof rest, {}>>();
Expand Down Expand Up @@ -73,6 +82,21 @@ export const ReferencedInstancesTab = (props: Props) => {
{targetAudience}
</p>
<div className={classes.footer}>
{isUserLoggedIn && (
<Button
className={fr.cx("fr-mr-3w")}
onClick={() =>
routes
.instanceUpdateForm({
id: instance.id
})
.push()
}
>
{t("edit instance")}
</Button>
)}

<a
className={cx(
fr.cx("fr-btn", "fr-btn--secondary")
Expand Down Expand Up @@ -139,4 +163,5 @@ export const { i18n } = declareComponentKeys<
| "concerned public"
| "go to instance"
| "add instance"
| "edit instance"
>()({ ReferencedInstancesTab });

0 comments on commit 5cdf6a8

Please sign in to comment.