Skip to content

Commit 7e506ff

Browse files
authored
Merge pull request #1078 from MTES-MCT/feat-missing-artif
Prise en compte du cas où le territoire n'a pas d'OCS GE
2 parents 7e2c52f + 4d79799 commit 7e506ff

File tree

7 files changed

+26
-70
lines changed

7 files changed

+26
-70
lines changed

assets/scripts/components/features/status/OcsgeStatus.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface OcsgeStatusProps {
1111
status: "COMPLETE_UNIFORM" | "COMPLETE_NOT_UNIFORM" | "PARTIAL" | "NO_DATA" | "UNDEFINED";
1212
}
1313

14-
const defaultMessage = "Les données OCS GE ne sont pas encore disponibles sur ce territoire pour les dates sélectionnées.";
14+
const defaultMessage = "Les données OCS GE ne sont pas encore disponibles sur ce territoire.";
1515
const detailMessage = "Vous n'avez donc pas accès aux informations relatives à l'artificialisation, l'imperméabilisation, l'usage et la couverture.";
1616
const errorMessage = `${defaultMessage} ${detailMessage}`;
1717

assets/scripts/components/layout/Dashboard.tsx

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ const Dashboard: React.FC<DashboardProps> = ({ projectId }) => {
5555
skip: !projectData
5656
}
5757
);
58-
59-
const { landArtifStockIndex } = useArtificialisation({
60-
projectData: projectData as any,
61-
landData: landData as any
62-
});
6358

6459
const { urls } = projectData || {};
6560

@@ -91,23 +86,10 @@ const Dashboard: React.FC<DashboardProps> = ({ projectId }) => {
9186
title="Synthèse"
9287
consoCorrectionStatus={projectData.consommation_correction_status}
9388
>
94-
<Synthese
89+
<Synthese
9590
endpoint={urls.synthese}
9691
urls={projectData.urls}
97-
artificialisationData={landArtifStockIndex ? {
98-
surface: landArtifStockIndex.surface,
99-
percent: landArtifStockIndex.percent,
100-
flux_surface: landArtifStockIndex.flux_surface,
101-
years: landArtifStockIndex.years,
102-
is_interdepartemental: landData.is_interdepartemental,
103-
millesime_index: landArtifStockIndex.millesime_index,
104-
flux_previous_years: landArtifStockIndex.flux_previous_years,
105-
millesimes: landData.millesimes,
106-
territory_name: projectData.territory_name,
107-
land_type: projectData.land_type,
108-
land_id: projectData.land_id,
109-
millesimes_by_index: landData.millesimes_by_index
110-
} : undefined}
92+
landData={landData}
11193
/>
11294
</RouteWrapper>
11395
}
@@ -138,7 +120,9 @@ const Dashboard: React.FC<DashboardProps> = ({ projectId }) => {
138120
path={urls.artificialisation}
139121
element={
140122
<RouteWrapper
141-
title="Artificialisation des sols">
123+
title="Artificialisation des sols"
124+
ocsgeStatus={landData.has_ocsge ? 'COMPLETE_UNIFORM' : 'NO_DATA'}
125+
>
142126
<Artificialisation
143127
projectData={projectData}
144128
landData={landData}

assets/scripts/components/pages/Artificialisation.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ export const Artificialisation: React.FC<ArtificialisationProps> = ({
189189
isLoading,
190190
error
191191
} = useArtificialisation({
192-
projectData,
193192
landData
194193
});
195194

assets/scripts/components/pages/Synthese.tsx

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import Loader from '@components/ui/Loader';
55
import { formatNumber } from "@utils/formatUtils";
66
import { MillesimeDisplay } from "@components/features/ocsge/MillesimeDisplay";
77
import { LandMillesimeTable } from "@components/features/ocsge/LandMillesimeTable";
8-
import { Millesime, MillesimeByIndex } from "@services/types/land";
8+
import { LandDetailResultType, Millesime, MillesimeByIndex } from "@services/types/land";
99
import { useArtificialisation } from "@hooks/useArtificialisation";
10-
import { ProjectDetailResultType } from "@services/types/project";
1110

1211
/*
1312
Ce composant est un composant hybride qui permet de récupérer du contenu côté serveur via Django et de l'intégrer directement dans l'interface React.
@@ -39,17 +38,11 @@ interface UrlsType {
3938
}
4039

4140
const ArtificialisationSection: React.FC<{
42-
data: ArtificialisationData;
4341
urls: UrlsType;
44-
}> = ({ data, urls }) => {
45-
const { landArtifStockIndex, isLoading, error } = useArtificialisation({
46-
projectData: {
47-
land_type: data.land_type,
48-
land_id: data.land_id
49-
} as ProjectDetailResultType,
50-
landData: {
51-
millesimes_by_index: data.millesimes_by_index
52-
} as any
42+
landData: LandDetailResultType;
43+
}> = ({ landData, urls }) => {
44+
const { landArtifStockIndex : data, isLoading, error } = useArtificialisation({
45+
landData
5346
});
5447

5548
if (isLoading) return <Loader />;
@@ -66,8 +59,8 @@ const ArtificialisationSection: React.FC<{
6659
Surface artificialisée
6760
{" "}
6861
<MillesimeDisplay
69-
is_interdepartemental={data.is_interdepartemental}
70-
landArtifStockIndex={landArtifStockIndex}
62+
is_interdepartemental={landData.is_interdepartemental}
63+
landArtifStockIndex={data}
7164
/>
7265
</p>
7366
<span className={`fr-badge ${
@@ -86,8 +79,8 @@ const ArtificialisationSection: React.FC<{
8679
)}
8780
</span>
8881
<MillesimeDisplay
89-
is_interdepartemental={data.is_interdepartemental}
90-
landArtifStockIndex={landArtifStockIndex}
82+
is_interdepartemental={landData.is_interdepartemental}
83+
landArtifStockIndex={data}
9184
between={true}
9285
className="fr-text--sm fr-ml-1w"
9386
/>
@@ -103,9 +96,9 @@ const ArtificialisationSection: React.FC<{
10396

10497
<div className="fr-my-3w">
10598
<LandMillesimeTable
106-
millesimes={data.millesimes}
107-
territory_name={data.territory_name}
108-
is_interdepartemental={data.is_interdepartemental}
99+
millesimes={landData.millesimes}
100+
territory_name={landData.name}
101+
is_interdepartemental={landData.is_interdepartemental}
109102
/>
110103
</div>
111104

@@ -117,8 +110,8 @@ const ArtificialisationSection: React.FC<{
117110
const Synthese: React.FC<{
118111
endpoint: string;
119112
urls: UrlsType;
120-
artificialisationData?: ArtificialisationData
121-
}> = ({ endpoint, urls, artificialisationData }) => {
113+
landData?: LandDetailResultType;
114+
}> = ({ endpoint, urls, landData }) => {
122115
const { content, isLoading, error } = useHtmlLoader(endpoint);
123116

124117
if (isLoading) return <Loader />;
@@ -131,7 +124,7 @@ const Synthese: React.FC<{
131124
<div dangerouslySetInnerHTML={{ __html: content }} />
132125
</div>
133126
</div>
134-
{artificialisationData && <ArtificialisationSection data={artificialisationData} urls={urls} />}
127+
{landData?.has_ocsge && <ArtificialisationSection landData={landData} urls={urls} />}
135128
</div>
136129
);
137130
};

assets/scripts/hooks/useArtificialisation.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { useState } from 'react';
22
import { useGetLandArtifStockIndexQuery } from '@services/api';
3-
import { ProjectDetailResultType } from '@services/types/project';
43
import { LandDetailResultType } from '@services/types/land';
54
import { LandArtifStockIndex, defautLandArtifStockIndex } from '@services/types/landartifstockindex';
65
import { useMemo } from 'react';
76

87
interface UseArtificialisationProps {
9-
projectData: ProjectDetailResultType;
108
landData: LandDetailResultType;
119
}
1210

@@ -27,7 +25,6 @@ interface UseArtificialisationReturn {
2725
}
2826

2927
export const useArtificialisation = ({
30-
projectData,
3128
landData
3229
}: UseArtificialisationProps): UseArtificialisationReturn => {
3330
// Millésime par défaut
@@ -51,11 +48,11 @@ export const useArtificialisation = ({
5148

5249
// Récupération des données d'artificialisation
5350
const { data: landArtifStockIndexes, isLoading, error } = useGetLandArtifStockIndexQuery({
54-
land_type: projectData?.land_type,
55-
land_id: projectData?.land_id,
51+
land_type: landData?.land_type,
52+
land_id: landData?.land_id,
5653
millesime_index: defaultStockIndex,
5754
}, {
58-
skip: !projectData
55+
skip: !landData
5956
});
6057

6158
// Récupère les données d'artificialisation du millésime sélectionné

assets/scripts/services/types/land.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export type Millesime = {
3535
parent_keys: string[];
3636
departements: string[];
3737
is_interdepartemental: boolean;
38+
has_zonage: boolean;
39+
has_ocsge: boolean;
3840
};
3941

4042
type LandDetailQueryArg = string | FetchArgs | {

public_data/models/administration/LandModel.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
from rest_framework import serializers, viewsets
77
from rest_framework.response import Response
88

9-
from .Departement import Departement
10-
119

1210
class LandModel(models.Model):
1311
land_id = models.CharField()
@@ -38,23 +36,6 @@ def __str__(self):
3836

3937

4038
class LandModelSerializer(serializers.ModelSerializer):
41-
def get_departement_name(self, departement_id):
42-
try:
43-
departement = Departement.objects.get(source_id=departement_id)
44-
return departement.name
45-
except Departement.DoesNotExist:
46-
return departement_id
47-
48-
def to_representation(self, instance):
49-
data = super().to_representation(instance)
50-
51-
# Ajouter le nom du département pour chaque millésime
52-
for millesime in data["millesimes"]:
53-
if "departement" in millesime:
54-
millesime["departement_name"] = self.get_departement_name(millesime["departement"])
55-
56-
return data
57-
5839
class Meta:
5940
model = LandModel
6041
exclude = ("geom",)

0 commit comments

Comments
 (0)