diff --git a/packages/libs/eda/src/lib/map/analysis/EZTimeFilter.tsx b/packages/libs/eda/src/lib/map/analysis/EZTimeFilter.tsx index c8704d5bc6..9dc8657479 100755 --- a/packages/libs/eda/src/lib/map/analysis/EZTimeFilter.tsx +++ b/packages/libs/eda/src/lib/map/analysis/EZTimeFilter.tsx @@ -29,12 +29,8 @@ interface Props { starredVariables: VariableDescriptor[]; toggleStarredVariable: (targetVariableId: VariableDescriptor) => void; - variable: AppState['timeSliderVariable']; - setVariable: (newVariable: AppState['timeSliderVariable']) => void; - selectedRange: AppState['timeSliderSelectedRange']; - setSelectedRange: (newRange: AppState['timeSliderSelectedRange']) => void; - active: AppState['timeSliderActive']; - setActive: (newState: AppState['timeSliderActive']) => void; + config: NonNullable; + updateConfig: (newConfig: NonNullable) => void; } export default function EZTimeFilter({ @@ -44,14 +40,12 @@ export default function EZTimeFilter({ filters, starredVariables, toggleStarredVariable, - variable, - setVariable, - selectedRange, - setSelectedRange, - active, // to do - add a toggle to enable/disable - setActive, // the small filter and grey everything out + config, + updateConfig, }: Props) { const findEntityAndVariable = useFindEntityAndVariable(); + + const { variable, active, selectedRange } = config; const variableMetadata = findEntityAndVariable(variable); // data request to distribution for time slider @@ -127,9 +121,11 @@ export default function EZTimeFilter({ return; } - setVariable(selection.overlayVariable); - setSelectedRange(undefined); - setActive(true); + updateConfig({ + variable: selection.overlayVariable, + selectedRange: undefined, + active: true, + }); } // if no variable in a study is suitable to time slider, do not show time slider @@ -193,7 +189,7 @@ export default function EZTimeFilter({ label={active ? 'On' : 'Off'} labelPosition="left" value={!!active} - onChange={setActive} + onChange={(active) => updateConfig({ ...config, active })} /> @@ -211,7 +207,9 @@ export default function EZTimeFilter({ + updateConfig({ ...config, selectedRange }) + } width={timeFilterWidth - 30} height={100} // line color of the selectedRange diff --git a/packages/libs/eda/src/lib/map/analysis/MapAnalysis.tsx b/packages/libs/eda/src/lib/map/analysis/MapAnalysis.tsx index 25cf4e0d86..984f01cd8b 100755 --- a/packages/libs/eda/src/lib/map/analysis/MapAnalysis.tsx +++ b/packages/libs/eda/src/lib/map/analysis/MapAnalysis.tsx @@ -254,9 +254,7 @@ function MapAnalysisImpl(props: ImplProps) { setActiveMarkerConfigurationType, setMarkerConfigurations, geoConfigs, - setTimeSliderVariable, - setTimeSliderSelectedRange, - setTimeSliderActive, + setTimeSliderConfig, } = props; const { activeMarkerConfigurationType, markerConfigurations } = appState; const filters = analysisState.analysis?.descriptor.subset.descriptor; @@ -281,9 +279,6 @@ function MapAnalysisImpl(props: ImplProps) { const { variable: overlayVariable, entity: overlayEntity } = findEntityAndVariable(activeMarkerConfiguration?.selectedVariable) ?? {}; - const { variable: timeVariableMetadata } = - findEntityAndVariable(appState.timeSliderVariable) ?? {}; - const outputEntity = useMemo(() => { if (geoConfig == null || geoConfig.entity.id == null) return; @@ -307,35 +302,33 @@ function MapAnalysisImpl(props: ImplProps) { [markerConfigurations, setMarkerConfigurations] ); - const timeFilter: NumberRangeFilter | DateRangeFilter | undefined = useMemo( - () => - timeVariableMetadata && - appState.timeSliderActive && - appState.timeSliderVariable && - appState.timeSliderSelectedRange + const timeFilter: NumberRangeFilter | DateRangeFilter | undefined = + useMemo(() => { + if (appState.timeSliderConfig == null) return undefined; + + const { active, variable, selectedRange } = appState.timeSliderConfig; + + const { variable: timeVariableMetadata } = + findEntityAndVariable(variable) ?? {}; + + return active && variable && selectedRange ? DateVariable.is(timeVariableMetadata) ? { type: 'dateRange', - ...appState.timeSliderVariable, - min: appState.timeSliderSelectedRange.start + 'T00:00:00Z', - max: appState.timeSliderSelectedRange.end + 'T00:00:00Z', + ...variable, + min: selectedRange.start + 'T00:00:00Z', + max: selectedRange.end + 'T00:00:00Z', } : NumberVariable.is(timeVariableMetadata) ? { type: 'numberRange', // this is temporary - I think we should NOT handle non-date variables when we roll this out - ...appState.timeSliderVariable, // TO DO: remove number variable handling - min: Number(appState.timeSliderSelectedRange.start.split(/-/)[0]), // just take the year number - max: Number(appState.timeSliderSelectedRange.end.split(/-/)[0]), // from the YYYY-MM-DD returned from the widget + ...variable, // TO DO: remove number variable handling + min: Number(selectedRange.start.split(/-/)[0]), // just take the year number + max: Number(selectedRange.end.split(/-/)[0]), // from the YYYY-MM-DD returned from the widget } : undefined - : undefined, - [ - timeVariableMetadata, - appState.timeSliderActive, - appState.timeSliderVariable, - appState.timeSliderSelectedRange, - ] - ); + : undefined; + }, [appState.timeSliderConfig, findEntityAndVariable]); const viewportFilters = useMemo( () => @@ -1251,23 +1244,23 @@ function MapAnalysisImpl(props: ImplProps) { overlayActive={overlayVariable != null} > {/* child elements will be distributed across, 'hanging' below the header */} - {/* Time slider component */} - + {/* Time slider component - only if prerequisite variable is available */} + {appState.timeSliderConfig && + appState.timeSliderConfig.variable && ( + + )}
0 || timeVariableIsMissing) { + if (missingMarkerConfigs.length > 0 || timeSliderConfigIsMissing) { setVariableUISettings((prev) => ({ ...prev, [uiStateKey]: { ...appState, - ...(timeVariableIsMissing - ? { timeSliderVariable: defaultTimeVariable } + ...(timeSliderConfigIsMissing + ? { timeSliderConfig: defaultAppState.timeSliderConfig } : {}), markerConfigurations: [ ...appState.markerConfigurations, @@ -213,14 +221,7 @@ export function useAppState(uiStateKey: string, analysisState: AnalysisState) { } appStateCheckedRef.current = true; } - }, [ - analysis, - appState, - setVariableUISettings, - uiStateKey, - defaultAppState, - defaultTimeVariable, - ]); + }, [analysis, appState, setVariableUISettings, uiStateKey, defaultAppState]); function useSetter(key: T) { return useCallback( @@ -254,8 +255,6 @@ export function useAppState(uiStateKey: string, analysisState: AnalysisState) { setIsSubsetPanelOpen: useSetter('isSubsetPanelOpen'), setSubsetVariableAndEntity: useSetter('subsetVariableAndEntity'), setViewport: useSetter('viewport'), - setTimeSliderVariable: useSetter('timeSliderVariable'), - setTimeSliderSelectedRange: useSetter('timeSliderSelectedRange'), - setTimeSliderActive: useSetter('timeSliderActive'), + setTimeSliderConfig: useSetter('timeSliderConfig'), }; }