Skip to content

Commit

Permalink
feat: début formulaire génération de pyramide #470
Browse files Browse the repository at this point in the history
  • Loading branch information
ocruze committed Oct 2, 2024
1 parent 81fb5e2 commit 121c311
Show file tree
Hide file tree
Showing 14 changed files with 250 additions and 9 deletions.
10 changes: 8 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ HTTPS_PROXY=
# id du processus d'intégration en base
API_ENTREPOT_PROC_INT_VECT_FILES_DB=

# id du processus de génération de pyramide
# id du processus de génération de pyramide vecteur
API_ENTREPOT_PROC_CREATE_VECT_PYR=

# id du processus de génération de pyramide raster
API_ENTREPOT_PROC_CREATE_RAST_PYR=

# Id de la community liee au datastore bac a sable
SANDBOX_COMMUNITY_ID=

Expand All @@ -46,8 +49,11 @@ SANDBOX_SERVICE_ACCOUNT_CLIENT_SECRET=
# id du processus d'intégration en base pour le Bac a sable
SANDBOX_PROC_INT_VECT_FILES_DB=

# id du processus de génération de pyramide pour le Bac a sable
# id du processus de génération de pyramide vecteur pour le Bac a sable
SANDBOX_PROC_CREATE_VECT_PYR=

# id du processus de génération de pyramide raster pour le Bac à sable
SANDBOX_PROC_CREATE_RAST_PYR=

# URL de l'API espace collaboratif
API_ESPACE_COLLABORATIF_URL=
8 changes: 5 additions & 3 deletions assets/components/Utils/MenuList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type MenuListItem = MenuListItemCommon &

type MenuListProps = {
menuOpenButtonProps?: Omit<ButtonProps, "linkProps" | "onClick" | "type" | "disabled">;
items: MenuListItem[];
items: (MenuListItem | undefined | false)[];
disabled?: boolean;
};

Expand All @@ -48,6 +48,8 @@ const MenuList: FC<MenuListProps> = ({ menuOpenButtonProps, items = [], disabled
setAnchorEl(null);
};

const _items: MenuListItem[] = useMemo(() => items.filter((item) => item !== undefined && item !== false), [items]);

// props du bouton ouvrir menu
const _menuOpenBtnProps = useMemo<ButtonProps>(() => {
const _props: ButtonProps = menuOpenButtonProps ? { ...(menuOpenButtonProps as ButtonProps) } : ({} as ButtonProps);
Expand All @@ -66,7 +68,7 @@ const MenuList: FC<MenuListProps> = ({ menuOpenButtonProps, items = [], disabled
return _props;
}, [menuOpenButtonProps, disabled, isMenuOpen, otherActionsBtnId, otherActionsMenuId]);

const atLeastOneIcon = useMemo<boolean>(() => items.filter((item) => item.iconId !== undefined).length > 0, [items]);
const atLeastOneIcon = useMemo<boolean>(() => _items.filter((item) => item.iconId !== undefined).length > 0, [_items]);

return (
<>
Expand All @@ -91,7 +93,7 @@ const MenuList: FC<MenuListProps> = ({ menuOpenButtonProps, items = [], disabled
}}
>
{disabled === false &&
items.map((item, i) => {
_items.map((item, i) => {
const itemContent = (
<MenuItem
key={i}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,11 @@ const ServicesListItem: FC<ServicesListItemProps> = ({ service, datasheetName, d
}
},
},
{
[OfferingTypeEnum.WFS, OfferingTypeEnum.WMTSTMS].includes(service.type) && {
text: "Gérer les styles",
iconId: "ri-flashlight-line",
linkProps: routes.datastore_service_view({ datastoreId, datasheetName, offeringId: service._id, activeTab: "styles" })
.link,
disabled: ![OfferingTypeEnum.WFS, OfferingTypeEnum.WMTSTMS].includes(service.type),
},
// {
// text: "Mettre à jour la légende",
Expand All @@ -123,7 +122,7 @@ const ServicesListItem: FC<ServicesListItemProps> = ({ service, datasheetName, d
linkProps: routes.datastore_manage_permissions({ datastoreId }).link,
disabled: service.open === true,
},
{
[OfferingTypeEnum.WMSVECTOR, OfferingTypeEnum.WFS, OfferingTypeEnum.WMTSTMS].includes(service.type) && {
text: "Modifier les informations de publication",
iconId: "ri-edit-box-line",
linkProps: (() => {
Expand Down Expand Up @@ -158,7 +157,11 @@ const ServicesListItem: FC<ServicesListItemProps> = ({ service, datasheetName, d
};
}
})(),
disabled: ![OfferingTypeEnum.WMSVECTOR, OfferingTypeEnum.WFS, OfferingTypeEnum.WMTSTMS].includes(service.type),
},
service.type === OfferingTypeEnum.WMSVECTOR && {
text: "Créer un service raster WMS/WMTS",
iconId: "ri-add-box-line",
linkProps: routes.datastore_pyramid_raster_generate({ datastoreId, offeringId: service._id, datasheetName }).link,
},
// NOTE : reporté cf. issue #249
// {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
import { fr } from "@codegouvfr/react-dsfr";
import Alert from "@codegouvfr/react-dsfr/Alert";
import Button from "@codegouvfr/react-dsfr/Button";
import ButtonsGroup from "@codegouvfr/react-dsfr/ButtonsGroup";
import Input from "@codegouvfr/react-dsfr/Input";
import Stepper from "@codegouvfr/react-dsfr/Stepper";
import { useQuery } from "@tanstack/react-query";
import { declareComponentKeys } from "i18nifty";
import { FC, useCallback, useState } from "react";

import { Service } from "../../../../@types/app";
import DatastoreLayout from "../../../../components/Layout/DatastoreLayout";
import LoadingText from "../../../../components/Utils/LoadingText";
import useScrollToTopEffect from "../../../../hooks/useScrollToTopEffect";
import { Translations, useTranslation } from "../../../../i18n/i18n";
import RQKeys from "../../../../modules/entrepot/RQKeys";
import { CartesApiException } from "../../../../modules/jsonFetch";
import { routes } from "../../../../router/router";
import api from "../../../api";
import { DatasheetViewActiveTabEnum } from "../../datasheet/DatasheetView/DatasheetView";

const STEPS = {
TECHNICAL_NAME: 1,
TOP_ZOOM_LEVEL: 2,
};

type PyramidRasterGenerateFormProps = {
datastoreId: string;
offeringId: string;
datasheetName: string;
};
const PyramidRasterGenerateForm: FC<PyramidRasterGenerateFormProps> = ({ datastoreId, offeringId, datasheetName }) => {
const { t } = useTranslation("PyramidRasterGenerateForm");
const { t: tCommon } = useTranslation("Common");

const [currentStep, setCurrentStep] = useState(STEPS.TECHNICAL_NAME);

const serviceQuery = useQuery<Service, CartesApiException>({
queryKey: RQKeys.datastore_offering(datastoreId, offeringId),
queryFn: () => api.service.getService(datastoreId, offeringId),
staleTime: 60000,
});

useScrollToTopEffect(currentStep);

const previousStep = useCallback(() => setCurrentStep((currentStep) => currentStep - 1), []);

const nextStep = useCallback(async () => {
// const isStepValid = await trigger(undefined, { shouldFocus: true }); // demande de valider le formulaire
// if (!isStepValid) return; // ne fait rien si formulaire invalide
// formulaire est valide
if (currentStep < Object.values(STEPS).length) {
// on passe à la prochaine étape du formulaire
setCurrentStep((currentStep) => currentStep + 1);
} else {
// on est à la dernière étape du formulaire donc on envoie la sauce
// if (editMode) {
// editServiceMutation.mutate();
// } else {
// createServiceMutation.mutate();
// }
}
}, [
currentStep,
/*createServiceMutation, editServiceMutation, trigger, editMode*/
]);

return (
<DatastoreLayout datastoreId={datastoreId} documentTitle={t("title")}>
<h1>{t("title")}</h1>

{serviceQuery.isLoading ? (
<LoadingText as="h2" message={t("wmsv-service.loading")} />
) : serviceQuery.error !== null ? (
<Alert
severity="error"
closable={false}
title={t("wmsv-service.fetch_failed")}
description={
<>
<p>{serviceQuery.error?.message}</p>
<Button
linkProps={routes.datastore_datasheet_view({ datastoreId, datasheetName, activeTab: DatasheetViewActiveTabEnum.Services }).link}
>
{t("back_to_datasheet")}
</Button>
</>
}
/>
) : (
<>
<Stepper
currentStep={currentStep}
stepCount={Object.values(STEPS).length}
nextTitle={currentStep < STEPS.TOP_ZOOM_LEVEL && t("step.title", { stepNumber: currentStep + 1 })}
title={t("step.title", { stepNumber: currentStep })}
/>

<p>{tCommon("mandatory_fields")}</p>

<div className={fr.cx(currentStep !== STEPS.TECHNICAL_NAME && "fr-hidden")}>
<h3>Choisissez le nom technique de la pyramide de tuiles raster</h3>
<Input
label={"Nom technique de la pyramide de tuiles raster"}
hintText={
"II s'agit du nom technique du service qui apparaitra dans votre espace de travail, il ne sera pas publié en ligne. Si vous le renommez, choisissez un nom explicite."
}
/>
</div>

<div className={fr.cx(currentStep !== STEPS.TOP_ZOOM_LEVEL && "fr-hidden")}>
<h3>{"Choisissez le niveau de zoom top de vos tables"}</h3>
<p>
{`Les niveaux de zoom de la pyramide de tuiles raster sont prédéfinis. Choisissez la borne minimum de votre pyramide de tuiles en vous aidant
de la carte de gauche. Le zoom maximum sur l’image de droite est fixe et ne peut être modifié. Tous les niveaux intermédiaires seront
générés.`}
</p>
</div>

<ButtonsGroup
className={fr.cx("fr-mt-2w")}
alignment="between"
buttons={[
{
children: tCommon("previous_step"),
iconId: "fr-icon-arrow-left-fill",
priority: "tertiary",
onClick: previousStep,
disabled: currentStep === STEPS.TECHNICAL_NAME,
},
{
children: currentStep < Object.values(STEPS).length ? tCommon("continue") : tCommon("publish"),
onClick: nextStep,
},
]}
inlineLayoutWhen="always"
/>
</>
)}
</DatastoreLayout>
);
};

export default PyramidRasterGenerateForm;

export const { i18n } = declareComponentKeys<
"title" | { K: "step.title"; P: { stepNumber: number }; R: string } | "wmsv-service.loading" | "wmsv-service.fetch_failed" | "back_to_datasheet"
>()({
PyramidRasterGenerateForm,
});

export const PyramidRasterGenerateFormFrTranslations: Translations<"fr">["PyramidRasterGenerateForm"] = {
// title: "Créer un service raster WMS/WMTS",
title: "Générer une pyramide de tuiles raster",
"step.title": ({ stepNumber }) => {
switch (stepNumber) {
case 1:
return "Nom de la pyramide de tuiles raster";
case 2:
return "Niveau de zoom top";
default:
return "";
}
},
"wmsv-service.loading": "Chargement du service WMS-Vecteur...",
"wmsv-service.fetch_failed": "Récupération des informations sur le service WMS-Vecteur a échoué",
back_to_datasheet: "Retour à la fiche de données",
};

export const PyramidRasterGenerateFormEnTranslations: Translations<"en">["PyramidRasterGenerateForm"] = {
title: undefined,
"step.title": undefined,
"wmsv-service.loading": undefined,
"wmsv-service.fetch_failed": undefined,
back_to_datasheet: undefined,
};
3 changes: 3 additions & 0 deletions assets/i18n/Breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const { i18n } = declareComponentKeys<
| "datastore_pyramid_vector_generate"
| "datastore_pyramid_vector_tms_service_new"
| "datastore_pyramid_vector_tms_service_edit"
| "datastore_pyramid_raster_generate"
| "datastore_service_view"
>()("Breadcrumb");

Expand Down Expand Up @@ -81,6 +82,7 @@ export const BreadcrumbFrTranslations: Translations<"fr">["Breadcrumb"] = {
datastore_pyramid_vector_generate: "Génération d'une pyramide vecteur",
datastore_pyramid_vector_tms_service_new: "Création d'un service TMS",
datastore_pyramid_vector_tms_service_edit: "Modification d'un service TMS",
datastore_pyramid_raster_generate: "Génération d'une pyramide raster",
datastore_service_view: "Prévisualisation d'un service",
};

Expand Down Expand Up @@ -123,5 +125,6 @@ export const BreadcrumbEnTranslations: Translations<"en">["Breadcrumb"] = {
datastore_pyramid_vector_generate: "Generate a vector pyramid",
datastore_pyramid_vector_tms_service_new: "Create a TMS service",
datastore_pyramid_vector_tms_service_edit: "Modify a TMS service",
datastore_pyramid_raster_generate: "Generate raster pyramid",
datastore_service_view: "Preview a service",
};
1 change: 1 addition & 0 deletions assets/i18n/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export type ComponentKey =
| typeof import("../entrepot/pages/service/wms-vector/WmsVectorServiceForm").i18n
| typeof import("../entrepot/pages/service/wfs/WfsServiceForm").i18n
| typeof import("../entrepot/pages/service/tms/PyramidVectorTmsServiceForm").i18n
| typeof import("../entrepot/pages/service/wms-raster-wmts/PyramidRasterGenerateForm").i18n
| typeof import("../entrepot/pages/service/TableSelection").i18n
| typeof import("../entrepot/pages/service/AccessRestrictions").i18n
| typeof import("../entrepot/pages/service/wms-vector/UploadStyleFile").i18n
Expand Down
2 changes: 2 additions & 0 deletions assets/i18n/languages/en.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { RightsEnTranslations } from "../Rights";
import { StyleEnTranslations } from "../Style";
import type { Translations } from "../i18n";
import { DatasheetUploadFormEnTranslations } from "../../entrepot/pages/datasheet/DatasheetNew/DatasheetUploadForm";
import { PyramidRasterGenerateFormEnTranslations } from "../../entrepot/pages/service/wms-raster-wmts/PyramidRasterGenerateForm";

export const translations: Translations<"en"> = {
Common: commonEnTranslations,
Expand Down Expand Up @@ -67,6 +68,7 @@ export const translations: Translations<"en"> = {
TableSelection: TableSelectionEnTranslations,
UploadStyleFile: UploadStyleFileEnTranslations,
PyramidVectorTmsServiceForm: PyramidVectorTmsServiceFormEnTranslations,
PyramidRasterGenerateForm: PyramidRasterGenerateFormEnTranslations,
EspaceCoCommunities: EspaceCoCommunitiesEnTranslations,
DatasheetUploadForm: DatasheetUploadFormEnTranslations,
DatasheetList: DatasheetListEnTranslations,
Expand Down
2 changes: 2 additions & 0 deletions assets/i18n/languages/fr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { BreadcrumbFrTranslations } from "../Breadcrumb";
import { RightsFrTranslations } from "../Rights";
import { StyleFrTranslations } from "../Style";
import type { Translations } from "../i18n";
import { PyramidRasterGenerateFormFrTranslations } from "../../entrepot/pages/service/wms-raster-wmts/PyramidRasterGenerateForm";

export const translations: Translations<"fr"> = {
Common: commonFrTranslations,
Expand Down Expand Up @@ -67,6 +68,7 @@ export const translations: Translations<"fr"> = {
TableSelection: TableSelectionFrTranslations,
UploadStyleFile: UploadStyleFileFrTranslations,
PyramidVectorTmsServiceForm: PyramidVectorTmsServiceFormFrTranslations,
PyramidRasterGenerateForm: PyramidRasterGenerateFormFrTranslations,
EspaceCoCommunities: EspaceCoCommunitiesFrTranslations,
DatasheetUploadForm: DatasheetUploadFormFrTranslations,
DatasheetList: DatasheetListFrTranslations,
Expand Down
1 change: 1 addition & 0 deletions assets/modules/entrepot/breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ const getBreadcrumb = (route: Route<typeof routes>, datastore?: Datastore): Brea
case "datastore_pyramid_vector_generate":
case "datastore_pyramid_vector_tms_service_new":
case "datastore_pyramid_vector_tms_service_edit":
case "datastore_pyramid_raster_generate":
case "datastore_service_view":
defaultProps.segments = [
...defaultProps.segments,
Expand Down
9 changes: 9 additions & 0 deletions assets/router/RouterRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const WfsServiceForm = lazy(() => import("../entrepot/pages/service/wfs/WfsServi
const WmsVectorServiceForm = lazy(() => import("../entrepot/pages/service/wms-vector/WmsVectorServiceForm"));
const PyramidVectorGenerateForm = lazy(() => import("../entrepot/pages/service/tms/PyramidVectorGenerateForm"));
const PyramidVectorTmsServiceForm = lazy(() => import("../entrepot/pages/service/tms/PyramidVectorTmsServiceForm"));
const PyramidRasterGenerateForm = lazy(() => import("../entrepot/pages/service/wms-raster-wmts/PyramidRasterGenerateForm"));

const ServiceView = lazy(() => import("../entrepot/pages/service/view/ServiceView"));

Expand Down Expand Up @@ -176,6 +177,14 @@ const RouterRenderer: FC = () => {
offeringId={route.params.offeringId}
/>
);
case "datastore_pyramid_raster_generate":
return (
<PyramidRasterGenerateForm
datastoreId={route.params.datastoreId}
offeringId={route.params.offeringId}
datasheetName={route.params.datasheetName}
/>
);
case "datastore_service_view":
return <ServiceView datastoreId={route.params.datastoreId} offeringId={route.params.offeringId} datasheetName={route.params.datasheetName} />;
case "espaceco_community_list":
Expand Down
10 changes: 10 additions & 0 deletions assets/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,16 @@ const routeDefs = {
(p) => `${appRoot}/entrepot/${p.datastoreId}/service/tms/${p.offeringId}/modification`
),

// Création/génération d'une pyramide raster
datastore_pyramid_raster_generate: defineRoute(
{
datastoreId: param.path.string,
offeringId: param.query.string,
datasheetName: param.query.string,
},
(p) => `${appRoot}/entrepot/${p.datastoreId}/pyramide-raster/ajout`
),

datastore_service_view: defineRoute(
{
datastoreId: param.path.string,
Expand Down
Loading

0 comments on commit 121c311

Please sign in to comment.