diff --git a/components/bal/toponymes-list.tsx b/components/bal/toponymes-list.tsx
index febb30be3..850c6d514 100644
--- a/components/bal/toponymes-list.tsx
+++ b/components/bal/toponymes-list.tsx
@@ -179,7 +179,11 @@ function ToponymesList({
}
comment={
toponyme.commentedNumeros.length > 0 ? (
-
+ comment)}
+ />
) : null
}
/>
diff --git a/components/bal/voie-editor.tsx b/components/bal/voie-editor.tsx
index f03379a7a..a274d8547 100644
--- a/components/bal/voie-editor.tsx
+++ b/components/bal/voie-editor.tsx
@@ -24,6 +24,7 @@ import {
VoiesService,
} from "@/lib/openapi-api-bal";
import LayoutContext from "@/contexts/layout";
+import Comment from "../comment";
interface VoieEditorProps {
initialValue?: Voie;
@@ -43,6 +44,9 @@ function VoieEditor({
initialValue ? initialValue.typeNumerotation === "metrique" : false
);
const [nom, onNomChange] = useInput(initialValue ? initialValue.nom : "");
+ const [comment, onCommentChange] = useInput(
+ initialValue ? initialValue.comment : ""
+ );
const { getValidationMessage, setValidationMessages } =
useValidationMessage();
const [nomAlt, setNomAlt] = useState(initialValue?.nomAlt);
@@ -66,6 +70,7 @@ function VoieEditor({
nomAlt: Object.keys(nomAlt).length > 0 ? nomAlt : null,
typeNumerotation: isMetric ? "metrique" : "numerique",
trace: data ? data.geometry : null,
+ comment: comment ? comment : null,
};
// Add or edit a voie
@@ -126,6 +131,7 @@ function VoieEditor({
baseLocale.id,
initialValue,
nom,
+ comment,
isMetric,
data,
nomAlt,
@@ -203,6 +209,8 @@ function VoieEditor({
/>
+
+
{isMetric && }
diff --git a/components/bal/voies-list.tsx b/components/bal/voies-list.tsx
index 7089a3063..e51a0748a 100644
--- a/components/bal/voies-list.tsx
+++ b/components/bal/voies-list.tsx
@@ -194,8 +194,11 @@ function VoiesList({
: null
}
comment={
- voie.comments.length > 0 ? (
-
+ voie.comment?.length || voie.commentedNumeros?.length > 0 ? (
+
) : null
}
warning={
diff --git a/components/comments-content.tsx b/components/comments-content.tsx
index dddcfb744..abcad3fe8 100644
--- a/components/comments-content.tsx
+++ b/components/comments-content.tsx
@@ -4,20 +4,35 @@ import { uniqueId } from "lodash";
const COMMENTS_LIMIT = 10;
interface CommentsContentProps {
- comments: string[];
+ mainComment?: string;
+ commentedNumeros?: string[];
}
-function CommentsContent({ comments }: CommentsContentProps) {
- const filteredComments = comments.slice(0, COMMENTS_LIMIT);
- const nbComments = comments.length;
+function CommentsContent({
+ mainComment,
+ commentedNumeros,
+}: CommentsContentProps) {
+ const filteredComments = commentedNumeros.slice(0, COMMENTS_LIMIT);
+ const nbComments = commentedNumeros.length;
const remainComments = nbComments - COMMENTS_LIMIT;
return (
<>
-
- Commentaire{`${comments.length > 0 ? "s" : ""}`} :
-
+ {mainComment ? (
+
+ {mainComment}
+
+ ) : (
+
+ Commentaire{`${commentedNumeros.length > 0 ? "s" : ""}`}
+
+ )}
{filteredComments.map((comment) => (
{comment && token && (
diff --git a/components/voie/voie-heading.tsx b/components/voie/voie-heading.tsx
index 00d14010d..9cda6a9fd 100644
--- a/components/voie/voie-heading.tsx
+++ b/components/voie/voie-heading.tsx
@@ -65,6 +65,11 @@ function VoieHeading({ voie }: VoieHeadingProps) {
{numeros.length} numéro{numeros.length > 1 ? "s" : ""}
)}
+ {voie.comment && (
+
+ {voie.comment}
+
+ )}
{voie.nomAlt && }
diff --git a/contexts/bal-data.tsx b/contexts/bal-data.tsx
index b3b3492a4..572e54371 100644
--- a/contexts/bal-data.tsx
+++ b/contexts/bal-data.tsx
@@ -39,8 +39,9 @@ interface BALDataContextType {
isHabilitationValid: boolean;
parcelles: Array;
reloadParcelles: () => Promise;
+ setVoies: React.Dispatch>;
voie: Voie;
- setVoie: (voie: Voie) => void;
+ setVoie: React.Dispatch>;
toponyme: Toponyme;
setToponyme: (Toponyme: Toponyme) => void;
numeros: Array;
@@ -298,6 +299,7 @@ export function BalDataContextProvider({
reloadToponymes,
reloadBaseLocale,
setVoie,
+ setVoies,
setToponyme,
certifyAllNumeros,
uncertifyAllNumeros,
@@ -326,6 +328,7 @@ export function BalDataContextProvider({
initialToponymes,
voies,
toponymes,
+ setVoies,
reloadNumeros,
reloadVoies,
reloadToponymes,
diff --git a/lib/openapi-api-bal/index.ts b/lib/openapi-api-bal/index.ts
index fec439f08..8c3a0bf0d 100644
--- a/lib/openapi-api-bal/index.ts
+++ b/lib/openapi-api-bal/index.ts
@@ -44,6 +44,7 @@ export type { UpdateToponymeDTO } from './models/UpdateToponymeDTO';
export { UpdateVoieDTO } from './models/UpdateVoieDTO';
export type { ValidatePinCodeDTO } from './models/ValidatePinCodeDTO';
export { Voie } from './models/Voie';
+export type { VoieMetas } from './models/VoieMetas';
export { BasesLocalesService } from './services/BasesLocalesService';
export { CommuneService } from './services/CommuneService';
diff --git a/lib/openapi-api-bal/models/CreateVoieDTO.ts b/lib/openapi-api-bal/models/CreateVoieDTO.ts
index 4eaeb2fe1..154f765de 100644
--- a/lib/openapi-api-bal/models/CreateVoieDTO.ts
+++ b/lib/openapi-api-bal/models/CreateVoieDTO.ts
@@ -10,6 +10,7 @@ export type CreateVoieDTO = {
nomAlt?: Record | null;
typeNumerotation?: CreateVoieDTO.typeNumerotation;
trace?: LineString;
+ comment?: string | null;
};
export namespace CreateVoieDTO {
diff --git a/lib/openapi-api-bal/models/ExtendedVoieDTO.ts b/lib/openapi-api-bal/models/ExtendedVoieDTO.ts
index 19bee6abf..166477a34 100644
--- a/lib/openapi-api-bal/models/ExtendedVoieDTO.ts
+++ b/lib/openapi-api-bal/models/ExtendedVoieDTO.ts
@@ -19,12 +19,13 @@ export type ExtendedVoieDTO = {
centroid: Record;
trace: Record;
bbox: Array;
+ comment: string;
baseLocale: BaseLocale;
numeros: Array;
nbNumeros: number;
nbNumerosCertifies: number;
isAllCertified: boolean;
- comments: Array;
+ commentedNumeros: Array;
};
export namespace ExtendedVoieDTO {
diff --git a/lib/openapi-api-bal/models/UpdateVoieDTO.ts b/lib/openapi-api-bal/models/UpdateVoieDTO.ts
index 0e632a180..1e2eed32c 100644
--- a/lib/openapi-api-bal/models/UpdateVoieDTO.ts
+++ b/lib/openapi-api-bal/models/UpdateVoieDTO.ts
@@ -10,6 +10,7 @@ export type UpdateVoieDTO = {
nomAlt?: Record | null;
typeNumerotation?: UpdateVoieDTO.typeNumerotation;
trace?: LineString;
+ comment?: string | null;
};
export namespace UpdateVoieDTO {
diff --git a/lib/openapi-api-bal/models/Voie.ts b/lib/openapi-api-bal/models/Voie.ts
index 24307ff5a..d57adb6a1 100644
--- a/lib/openapi-api-bal/models/Voie.ts
+++ b/lib/openapi-api-bal/models/Voie.ts
@@ -19,6 +19,7 @@ export type Voie = {
centroid: Record;
trace: Record;
bbox: Array;
+ comment: string;
baseLocale: BaseLocale;
numeros: Array;
};
diff --git a/lib/openapi-api-bal/models/VoieMetas.ts b/lib/openapi-api-bal/models/VoieMetas.ts
new file mode 100644
index 000000000..a0acce789
--- /dev/null
+++ b/lib/openapi-api-bal/models/VoieMetas.ts
@@ -0,0 +1,13 @@
+/* generated using openapi-typescript-codegen -- do no edit */
+/* istanbul ignore file */
+/* tslint:disable */
+/* eslint-disable */
+
+export type VoieMetas = {
+ id: string;
+ nbNumeros: number;
+ nbNumerosCertifies: number;
+ isAllCertified: boolean;
+ commentedNumeros: Array;
+};
+
diff --git a/lib/openapi-api-bal/services/BasesLocalesService.ts b/lib/openapi-api-bal/services/BasesLocalesService.ts
index 81537f9ca..e7d28cfde 100644
--- a/lib/openapi-api-bal/services/BasesLocalesService.ts
+++ b/lib/openapi-api-bal/services/BasesLocalesService.ts
@@ -23,6 +23,7 @@ import type { UpdateBaseLocaleDemoDTO } from '../models/UpdateBaseLocaleDemoDTO'
import type { UpdateBaseLocaleDTO } from '../models/UpdateBaseLocaleDTO';
import type { UpdateBatchNumeroDTO } from '../models/UpdateBatchNumeroDTO';
import type { Voie } from '../models/Voie';
+import type { VoieMetas } from '../models/VoieMetas';
import type { CancelablePromise } from '../core/CancelablePromise';
import { OpenAPI } from '../core/OpenAPI';
@@ -534,6 +535,24 @@ export class BasesLocalesService {
});
}
+ /**
+ * Find all Metas Voie in Bal
+ * @param baseLocaleId
+ * @returns VoieMetas
+ * @throws ApiError
+ */
+ public static findVoieMetasByBal(
+ baseLocaleId: string,
+ ): CancelablePromise> {
+ return __request(OpenAPI, {
+ method: 'GET',
+ url: '/v2/bases-locales/{baseLocaleId}/voies/metas',
+ path: {
+ 'baseLocaleId': baseLocaleId,
+ },
+ });
+ }
+
/**
* Find all Toponymes in Bal
* @param baseLocaleId
diff --git a/lib/openapi-api-bal/services/VoiesService.ts b/lib/openapi-api-bal/services/VoiesService.ts
index 2d5201e75..5b3f552ca 100644
--- a/lib/openapi-api-bal/services/VoiesService.ts
+++ b/lib/openapi-api-bal/services/VoiesService.ts
@@ -9,6 +9,7 @@ import type { RestoreVoieDTO } from '../models/RestoreVoieDTO';
import type { Toponyme } from '../models/Toponyme';
import type { UpdateVoieDTO } from '../models/UpdateVoieDTO';
import type { Voie } from '../models/Voie';
+import type { VoieMetas } from '../models/VoieMetas';
import type { CancelablePromise } from '../core/CancelablePromise';
import { OpenAPI } from '../core/OpenAPI';
@@ -74,6 +75,24 @@ export class VoiesService {
});
}
+ /**
+ * Find Voie Metas by id
+ * @param voieId
+ * @returns VoieMetas
+ * @throws ApiError
+ */
+ public static findVoieMetas(
+ voieId: string,
+ ): CancelablePromise {
+ return __request(OpenAPI, {
+ method: 'GET',
+ url: '/v2/voies/{voieId}/metas',
+ path: {
+ 'voieId': voieId,
+ },
+ });
+ }
+
/**
* Soft delete Voie by id
* @param voieId
diff --git a/pages/bal/[balId]/index.tsx b/pages/bal/[balId]/index.tsx
index f8290e9b1..e00b44bb8 100644
--- a/pages/bal/[balId]/index.tsx
+++ b/pages/bal/[balId]/index.tsx
@@ -1,4 +1,5 @@
-import React, { useCallback, useContext, useEffect, useState } from "react";
+import React, { useState, useCallback, useContext, useEffect } from "react";
+import { keyBy } from "lodash";
import { Pane, Paragraph } from "evergreen-ui";
import TokenContext from "@/contexts/token";
@@ -17,6 +18,9 @@ import {
Toponyme,
Voie,
VoiesService,
+ VoieMetas,
+ ExtendedVoieDTO,
+ BasesLocalesService,
} from "@/lib/openapi-api-bal";
import usePublishProcess from "@/hooks/publish-process";
import HeaderSideBar from "@/components/sidebar/header";
@@ -42,9 +46,15 @@ function BaseLocalePage({ commune }: BaseLocalePageProps) {
const [onConvertLoading, setOnConvertLoading] = useState(false);
const { token } = useContext(TokenContext);
- const { voies, toponymes, baseLocale, habilitation, isHabilitationValid } =
- useContext(BalDataContext);
const { toaster } = useContext(LayoutContext);
+ const {
+ voies,
+ toponymes,
+ baseLocale,
+ habilitation,
+ isHabilitationValid,
+ setVoies,
+ } = useContext(BalDataContext);
const { reloadTiles } = useContext(MapContext);
const { setIsRecoveryDisplayed } = useContext(BALRecoveryContext);
const { handleShowHabilitationProcess } = usePublishProcess(commune);
@@ -62,6 +72,25 @@ function BaseLocalePage({ commune }: BaseLocalePageProps) {
}
useHelp(help);
+ useEffect(() => {
+ async function addCommentsToVoies() {
+ try {
+ const voieMetas: VoieMetas[] =
+ await BasesLocalesService.findVoieMetasByBal(baseLocale.id);
+ const voiesMetasByVoieId = keyBy(voieMetas, "id");
+ setVoies((voies: ExtendedVoieDTO[]) =>
+ voies.map((v) => ({ ...v, ...voiesMetasByVoieId[v.id] }))
+ );
+ } catch (e) {
+ console.error("Impossible de charger les commentaires de voies", e);
+ }
+ }
+
+ if (token) {
+ addCommentsToVoies();
+ }
+ }, [baseLocale.id, setVoies, token]);
+
useEffect(() => {
if (
token &&
diff --git a/pages/bal/[balId]/voies/[idVoie].tsx b/pages/bal/[balId]/voies/[idVoie].tsx
index 706e2ae49..1cb796901 100644
--- a/pages/bal/[balId]/voies/[idVoie].tsx
+++ b/pages/bal/[balId]/voies/[idVoie].tsx
@@ -12,7 +12,13 @@ import VoieHeading from "@/components/voie/voie-heading";
import NumerosList from "@/components/voie/numeros-list";
import { CommuneType } from "@/types/commune";
import { BaseEditorProps, getBaseEditorProps } from "@/layouts/editor";
-import { ExtendedVoieDTO, Numero, VoiesService } from "@/lib/openapi-api-bal";
+import {
+ ExtendedVoieDTO,
+ Numero,
+ OpenAPI,
+ VoieMetas,
+ VoiesService,
+} from "@/lib/openapi-api-bal";
// Import BALRecoveryContext from '@/contexts/bal-recovery'
interface VoiePageProps {
@@ -21,19 +27,27 @@ interface VoiePageProps {
function VoiePage({ commune }: VoiePageProps) {
const { isFormOpen, handleEditing, editedNumero, reset } = useFormState();
- // Const {setIsRecoveryDisplayed} = useContext(BALRecoveryContext)
useHelp(3);
const { token } = useContext(TokenContext);
- const { voie, numeros, reloadNumeros } = useContext(BalDataContext);
+ const { voie, setVoie, numeros, reloadNumeros } = useContext(BalDataContext);
- // Load protected fields (ex: 'comment')
useEffect(() => {
+ async function addCommentsToVoies() {
+ try {
+ const voieMetas: VoieMetas = await VoiesService.findVoieMetas(voie.id);
+ setVoie({ ...voie, ...voieMetas });
+ } catch (e) {
+ console.error("Impossible de charger les commentaires de voie", e);
+ }
+ }
+
if (token) {
+ addCommentsToVoies();
reloadNumeros();
}
- }, [token, reloadNumeros]);
+ }, [token]);
return (
<>
@@ -68,8 +82,9 @@ function VoiePage({ commune }: VoiePageProps) {
);
}
-export async function getServerSideProps({ params }) {
+export async function getServerSideProps({ params, req }) {
const { idVoie, balId }: { idVoie: string; balId: string } = params;
+
try {
const { baseLocale, commune, voies, toponymes }: BaseEditorProps =
await getBaseEditorProps(balId);