Skip to content

Commit

Permalink
🔧 Some further migrations.
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasGilg committed Dec 12, 2024
1 parent 1829994 commit b8eff10
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions frontend/src/DataContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const DataProvider = ({children}: {children: React.ReactNode}) => {
const {data: referenceDateValues} = useGetScenarioInfectionDataQuery(
{
path: {
scenarioId: caseDataScenario!.id,
scenarioId: caseDataScenario?.id,
},
query: {
startDate: referenceDate!,
Expand Down Expand Up @@ -155,11 +155,11 @@ export const DataProvider = ({children}: {children: React.ReactNode}) => {

const {data: selectedScenarioData} = useGetScenarioQuery(selectedScenario!, {skip: !selectedScenario});
const {data: simulationModels} = useGetModelsQuery();
const {data: selectedSimulationModel} = useGetModelQuery(selectedScenarioData!.modelId, {
const {data: selectedSimulationModel} = useGetModelQuery(selectedScenarioData?.modelId ?? '', {
skip: !selectedScenarioData,
});
const {data: parameterDefinitions} = useGetMultiParameterDefinitionsQuery(
selectedSimulationModel!.parameterDefinitions,
selectedSimulationModel?.parameterDefinitions ?? [],
{skip: !selectedSimulationModel}
);
const {data: groups} = useGetGroupsQuery();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// SPDX-FileCopyrightText: 2024 German Aerospace Center (DLR)
// SPDX-License-Identifier: Apache-2.0

import React, {useState, useEffect, useMemo, useRef} from 'react';
import React, {useState, useEffect, useMemo, useRef, useContext} from 'react';
import Joyride, {CallBackProps, Step, STATUS, ACTIONS, EVENTS} from 'react-joyride';
import {useAppDispatch, useAppSelector} from '../../../store/hooks';
import {useTranslation} from 'react-i18next';
import {useTheme} from '@mui/material/styles';
import {setShowPopover, setTourCompleted, setActiveTour} from '../../../store/UserOnboardingSlice';
import {selectTab} from '../../../store/UserPreferenceSlice';
import {DataSelection, selectDate, selectScenario} from '../../../store/DataSelectionSlice';
import {DataContext} from '../../../DataContext';

/**
* Interface for the state of the tour steps
Expand Down Expand Up @@ -38,6 +39,7 @@ export default function TourSteps(): JSX.Element {
const dispatch = useAppDispatch();
const theme = useTheme();
const {t: tOnboarding} = useTranslation('onboarding');
const context = useContext(DataContext);

const activeTour = useAppSelector((state) => state.userOnboarding.activeTour);
const showPopover = useAppSelector((state) => state.userOnboarding.showPopover);
Expand All @@ -46,7 +48,7 @@ export default function TourSteps(): JSX.Element {
const selectedTab = useAppSelector((state) => state.userPreference.selectedTab);
const simulationStart = useAppSelector((state) => state.dataSelection.simulationStart);
const dataSelection = useAppSelector((state) => state.dataSelection);
const scenarioList = useAppSelector((state) => state.scenarioList.scenarios);
const scenarioList = context.scenarios;

const previousSimulationStart = useRef(simulationStart); // To keep track of the previous simulation start date for the scenario controlled tour.
const savedUserDataSelection = useRef<null | DataSelection>(null); // To keep track of the original data selection before starting any tour.
Expand All @@ -69,14 +71,14 @@ export default function TourSteps(): JSX.Element {
* sets the simulation start date, and starts the tour once preferences are saved.
*/
useEffect(() => {
if (activeTour && !showPopover && !showWelcomeDialog && !run) {
if (activeTour && !showPopover && !showWelcomeDialog && !run && scenarioList) {
if (!savedUserDataSelection.current) {
savedUserDataSelection.current = dataSelection; // Save the current data selection of the user so we can override it with different values during the tour

const maxDate = dataSelection.maxDate || '2024-07-08'; // Get the maximum date from the data selection
const maxDate = dataSelection.maxDate ?? '2024-07-08'; // Get the maximum date from the data selection
dispatch(selectDate(maxDate)); // Set the simulation start date (purple line) to the maximum date

const firstScenarioId = Number(Object.keys(scenarioList)[0]); // We get the first scenario id (base scenario) from scenarioList
const firstScenarioId = scenarioList[0].id; // We get the first scenario id (base scenario) from scenarioList
dispatch(selectScenario(firstScenarioId)); // Dispatch the selectScenario action with the base scenario

setArePreferencesSaved(true); // Flag to indicate that the preferences are saved
Expand Down Expand Up @@ -163,8 +165,8 @@ export default function TourSteps(): JSX.Element {

// If the tour is finished, skipped or closed
if (([STATUS.FINISHED, STATUS.SKIPPED] as string[]).includes(status) || action === ACTIONS.CLOSE) {
dispatch(selectDate(savedUserDataSelection.current?.date || '2024-07-08')); // Restore the original date in the data selection
dispatch(selectScenario(savedUserDataSelection.current?.scenario || 0)); // Restore the original selected scenario in the data selection
dispatch(selectDate(savedUserDataSelection.current?.date ?? '2024-07-08')); // Restore the original date in the data selection
dispatch(selectScenario(savedUserDataSelection.current?.scenario ?? '')); // Restore the original selected scenario in the data selection
savedUserDataSelection.current = null; // Reset the saved preferences after the tour is completed

// If the tour was finished and not skipped or closed, mark as completed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

import {ListItemButton, ListItemText, ListItemIcon, ClickAwayListener, Tooltip, useTheme} from '@mui/material';
import InfoOutlined from '@mui/icons-material/InfoOutlined';
import {Dispatch, SetStateAction, useState} from 'react';
import React, {Dispatch, useState} from 'react';
import {useTranslation} from 'react-i18next';
import React from 'react';
import {Localization} from 'types/localization';

interface CompartmentsRowProps {
Expand All @@ -25,7 +24,7 @@ interface CompartmentsRowProps {
compartmentsExpanded: boolean;

/** Function to set the selected compartment */
setSelectedCompartment: Dispatch<SetStateAction<string>>;
setSelectedCompartment: Dispatch<string>;

/** Minimum number of compartment rows */
minCompartmentsRows: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

import {List} from '@mui/material';
import {ScrollSyncPane} from 'react-scroll-sync';
import {Dispatch, SetStateAction} from 'react';
import React, {Dispatch} from 'react';
import CompartmentsRow from './CompartmentsRow';
import React from 'react';

import {Localization} from 'types/localization';
import {Dictionary} from 'util/util';
import {useTranslation} from 'react-i18next';

interface CompartmentsRowsProps {
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/components/Sidebar/SidebarContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ export default function MapContainer() {
[t]
);

const data = useMemo(() => {
return mapData?.map((entry) => ({id: entry.node ?? '', value: entry.values['50'] ?? 0}));
}, [mapData]);

return (
<Stack
id='sidebar-root'
Expand Down Expand Up @@ -166,7 +170,7 @@ export default function MapContainer() {
tooltipText={calculateToolTip}
tooltipTextWhileFetching={calculateToolTipFetching}
defaultSelectedValue={defaultValue}
values={mapData}
values={data}
isDataFetching={mapData === undefined}
longLoad={longLoad}
setLongLoad={setLongLoad}
Expand Down Expand Up @@ -199,11 +203,7 @@ export default function MapContainer() {
setFixedLegendMaxValue={setFixedLegendMaxValue}
aggregatedMax={aggregatedMax}
/>
<HeatLegendEdit
legend={legend}
setLegend={setLegend}
legendPresetsUrl={legendPresets}
/>
<HeatLegendEdit legend={legend} setLegend={setLegend} legendPresetsUrl={legendPresets} />
</Grid>
</Grid>
</LoadingContainer>
Expand Down

0 comments on commit b8eff10

Please sign in to comment.