• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DLR-SC / ESID / 18566232027

16 Oct 2025 03:20PM UTC coverage: 50.306% (-2.4%) from 52.681%
18566232027

Pull #430

github

kunkoala
:green_heart: fix build
Pull Request #430: data display settings

460 of 587 branches covered (78.36%)

Branch coverage included in aggregate %.

15 of 280 new or added lines in 4 files covered. (5.36%)

108 existing lines in 3 files now uncovered.

4467 of 9207 relevant lines covered (48.52%)

10.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/context/BaseDataContext.tsx
1
// SPDX-FileCopyrightText: 2024 German Aerospace Center (DLR)
2
// SPDX-License-Identifier: Apache-2.0
3

4
import React, {ReactNode, useEffect, useMemo, useState} from 'react';
×
5
import {
×
6
  useGetCompartmentsQuery,
7
  useGetGroupCategoriesQuery,
8
  useGetGroupsQuery,
9
  useGetInterventionTemplatesQuery,
10
  useGetModelsQuery,
11
  useGetNodeListsQuery,
12
  useGetNodesQuery,
13
  useGetScenariosQuery,
14
} from 'store/services/scenarioApi';
15
import {
16
  Compartments,
17
  GroupCategories,
18
  Groups,
19
  InterventionTemplates,
20
  Models,
21
  NodeLists,
22
  Nodes,
23
  Scenarios,
24
} from 'store/services/APITypes';
25
import CircularProgress from '@mui/material/CircularProgress';
×
26
import ValidateState from 'context/ValidateState';
×
27
import {GeoJSON, GeoJsonProperties} from 'geojson';
28
import {useTranslation} from 'react-i18next';
×
29

30
export interface BaseData {
31
  scenarios: Scenarios;
32
  compartments: Compartments;
33
  npis: InterventionTemplates;
34
  nodeLists: NodeLists;
35
  nodes: Nodes;
36
  groups: Groups;
37
  groupCategories: GroupCategories;
38
  simulationModels: Models;
39
  geoData: GeoJSON;
40
  searchBarData: GeoJsonProperties[];
41
  populationByNuts: Record<string, number>;
42
}
43

44
/**
45
 * BaseDataContext is a component that manages the loading and preparation of base data that has no direct dependencies.
46
 * It fetches data from several sources and passes it to a validator, once all data is loaded.
47
 */
48
export default function BaseDataContext(props: {children: ReactNode}): JSX.Element {
×
49
  const {data: scenarios, ...scenariosResult} = useGetScenariosQuery();
×
50
  const {data: compartments, ...compartmentsResult} = useGetCompartmentsQuery();
×
51
  const {data: npis, ...npisResult} = useGetInterventionTemplatesQuery();
×
52
  const {data: nodeLists, ...nodeListsResult} = useGetNodeListsQuery();
×
53
  const {data: nodes, ...nodesResult} = useGetNodesQuery();
×
54
  const {data: groups, ...groupsResult} = useGetGroupsQuery();
×
55
  const {data: groupCategories, ...groupCategoriesResult} = useGetGroupCategoriesQuery();
×
56
  const {data: simulationModels, ...simulationModelsResult} = useGetModelsQuery();
×
57

58
  const geoData = useGeoData();
×
59
  const searchBarData = useSearchBarData();
×
NEW
60
  const populationByNuts = usePopulationData();
×
61

62
  const dataLoadingCompleted = useMemo(() => {
×
63
    return (
×
64
      !scenariosResult.isLoading &&
×
65
      !compartmentsResult.isLoading &&
×
66
      !npisResult.isLoading &&
×
67
      !nodeListsResult.isLoading &&
×
68
      !nodesResult.isLoading &&
×
69
      !groupsResult.isLoading &&
×
70
      !groupCategoriesResult.isLoading &&
×
71
      !simulationModelsResult.isLoading &&
×
72
      geoData &&
×
NEW
73
      searchBarData &&
×
NEW
74
      populationByNuts
×
75
    );
76
  }, [
×
77
    compartmentsResult.isLoading,
×
78
    geoData,
×
79
    groupCategoriesResult.isLoading,
×
80
    groupsResult.isLoading,
×
81
    nodeListsResult.isLoading,
×
82
    nodesResult.isLoading,
×
83
    npisResult.isLoading,
×
84
    scenariosResult.isLoading,
×
85
    searchBarData,
×
86
    simulationModelsResult.isLoading,
×
NEW
87
    populationByNuts,
×
UNCOV
88
  ]);
×
89

90
  const baseData: BaseData = useMemo(
×
91
    () => ({
×
92
      scenarios: scenarios ?? [],
×
93
      compartments: compartments ?? [],
×
94
      npis: npis ?? [],
×
95
      nodeLists: nodeLists ?? [],
×
96
      nodes: nodes ?? [],
×
97
      groups: groups ?? [],
×
98
      groupCategories: groupCategories ?? [],
×
99
      simulationModels: simulationModels ?? [],
×
100
      geoData: geoData ?? {type: 'FeatureCollection', features: []},
×
101
      searchBarData: searchBarData ?? [],
×
NEW
102
      populationByNuts: populationByNuts ?? {},
×
103
    }),
×
NEW
104
    [
×
NEW
105
      scenarios,
×
NEW
106
      compartments,
×
NEW
107
      npis,
×
NEW
108
      nodeLists,
×
NEW
109
      nodes,
×
NEW
110
      groups,
×
NEW
111
      groupCategories,
×
NEW
112
      simulationModels,
×
NEW
113
      geoData,
×
NEW
114
      searchBarData,
×
NEW
115
      populationByNuts,
×
NEW
116
    ]
×
UNCOV
117
  );
×
118

119
  if (dataLoadingCompleted) {
×
120
    return <ValidateState baseData={baseData}>{props.children}</ValidateState>;
×
121
  }
×
122

123
  return <CircularProgress variant='indeterminate' />;
×
124
}
×
125

126
import geoMapData from '../../assets/lk_germany_reduced.geojson?url';
×
127

128
function useGeoData() {
×
129
  const [geoData, setGeoData] = useState<GeoJSON>();
×
130

131
  useEffect(() => {
×
132
    void fetch(geoMapData, {
×
133
      headers: {
×
134
        'Content-Type': 'application/json',
×
135
        Accept: 'application/json',
×
136
      },
×
137
    })
×
138
      .then((result) => result.json())
×
139
      .then((geodata: GeoJSON) => setGeoData(geodata));
×
140
  }, []);
×
141

142
  return geoData;
×
143
}
×
144

145
import searchbarMapData from '../../assets/lk_germany_reduced_list.json?url';
×
146

147
function useSearchBarData() {
×
148
  const {t} = useTranslation();
×
149
  const [searchBarData, setSearchBarData] = useState<GeoJsonProperties[]>();
×
150

151
  useEffect(() => {
×
152
    void fetch(searchbarMapData, {
×
153
      headers: {
×
154
        'Content-Type': 'application/json',
×
155
        Accept: 'application/json',
×
156
      },
×
157
    })
×
158
      .then((response) => response.json())
×
159
      .then((jsonlist: GeoJsonProperties[]) => {
×
160
        jsonlist.push({RS: '00000', GEN: t('germany'), BEZ: ''} as unknown as GeoJsonProperties);
×
161
        jsonlist.sort((a: GeoJsonProperties, b: GeoJsonProperties) => {
×
162
          return String(a!.GEN).localeCompare(String(b!.GEN));
×
163
        });
×
164
        setSearchBarData(jsonlist);
×
165
      });
×
166
  }, [t]);
×
167

168
  return searchBarData;
×
169
}
×
170

NEW
171
import populationDataUrl from '../../assets/population_data_v3.json?url';
×
172

173
interface PopulationData {
174
  id: string;
175
  name: string;
176
  total_population: number | string;
177
}
178

NEW
179
function usePopulationData() {
×
NEW
180
  const [populationByNuts, setPopulationByNuts] = useState<Record<string, number>>();
×
181

NEW
182
  useEffect(() => {
×
NEW
183
    void fetch(populationDataUrl, {
×
NEW
184
      headers: {
×
NEW
185
        'Content-Type': 'application/json',
×
NEW
186
        Accept: 'application/json',
×
NEW
187
      },
×
NEW
188
    })
×
NEW
189
      .then((response) => response.json())
×
NEW
190
      .then((jsonlist: PopulationData[]) => {
×
NEW
191
        const map: Record<string, number> = {};
×
NEW
192
        jsonlist.forEach((entry) => {
×
NEW
193
          const id = String(entry?.id || '').trim();
×
NEW
194
          const pop = typeof entry?.total_population === 'number' ? entry.total_population : undefined;
×
NEW
195
          if (id && typeof pop === 'number' && isFinite(pop) && pop > 0) {
×
NEW
196
            map[id] = pop;
×
NEW
197
          }
×
NEW
198
        });
×
NEW
199
        setPopulationByNuts(map);
×
NEW
200
      });
×
NEW
201
  }, []);
×
202

NEW
203
  return populationByNuts;
×
NEW
204
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc