-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new analysis button to all analyses component in map #459
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The button does not appear if I am in a new analysis for a study, and I don't have other saved analyses:
I suppose that's okay, but it threw me off when testing.
I do wonder if it would be better to put that button in the top-right, and to make it use the coreui primary theme color? That would address my comment above. For reference, this is what it looks like now:
This is what I was thinking. It would also avoid the changes to |
That looks like a great suggestion to me. |
I've made the requested change. That is, I'm pretty sure--I haven't been able to test the final styling due to server issues |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
history.push(redirectURL); | ||
// push() alone doesn't seem to work in this context; the URL changes, | ||
// but the page doesn't load, so we force a refresh | ||
history.go(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the issue here is related to a bug in appState
. Here is a git diff that should address the issue. Once applied, you should be able to remove this line (history.go(0)
).
diff --git a/packages/libs/eda/src/lib/map/analysis/MapAnalysis.tsx b/packages/libs/eda/src/lib/map/analysis/MapAnalysis.tsx
index ad70931ae4..ed27b7404e 100755
--- a/packages/libs/eda/src/lib/map/analysis/MapAnalysis.tsx
+++ b/packages/libs/eda/src/lib/map/analysis/MapAnalysis.tsx
@@ -212,8 +212,7 @@ interface Props {
}
export function MapAnalysis(props: Props) {
- const analysisState = useAnalysis(props.analysisId, 'pass');
- const appStateAndSetters = useAppState('@@mapApp@@', analysisState);
+ const appStateAndSetters = useAppState('@@mapApp@@', props.analysisId);
const geoConfigs = useGeoConfig(useStudyEntities());
if (geoConfigs == null || geoConfigs.length === 0)
@@ -230,7 +229,6 @@ export function MapAnalysis(props: Props) {
<MapAnalysisImpl
{...props}
{...(appStateAndSetters as CompleteAppState)}
- analysisState={analysisState}
geoConfigs={geoConfigs}
/>
);
diff --git a/packages/libs/eda/src/lib/map/analysis/appState.ts b/packages/libs/eda/src/lib/map/analysis/appState.ts
index af57d76ede..12ecb3baf4 100644
--- a/packages/libs/eda/src/lib/map/analysis/appState.ts
+++ b/packages/libs/eda/src/lib/map/analysis/appState.ts
@@ -5,10 +5,11 @@ import { isEqual } from 'lodash';
import { useCallback, useEffect, useMemo, useRef } from 'react';
import {
AnalysisState,
+ useAnalysis,
useGetDefaultVariableDescriptor,
- useStudyMetadata,
} from '../../core';
import { VariableDescriptor } from '../../core/types/variable';
+import { isSavedAnalysis } from '../../core/utils/analysis';
import { useGetDefaultTimeVariableDescriptor } from './hooks/eztimeslider';
const LatLngLiteral = t.type({ lat: t.number, lng: t.number });
@@ -122,7 +123,17 @@ export const defaultViewport: AppState['viewport'] = {
zoom: 1,
};
-export function useAppState(uiStateKey: string, analysisState: AnalysisState) {
+export function useAppState(uiStateKey: string, analysisId?: string) {
+ const analysisState = useAnalysis(analysisId);
+
+ // make some backwards compatability updates to the appstate retrieved from the back end
+ const appStateCheckedRef = useRef(false);
+
+ useEffect(() => {
+ // flip bit when analysis id changes
+ appStateCheckedRef.current = false;
+ }, [analysisId]);
+
const { analysis, setVariableUISettings } = analysisState;
const appState = pipe(
AppState.decode(
@@ -177,9 +188,6 @@ export function useAppState(uiStateKey: string, analysisState: AnalysisState) {
[defaultVariable, defaultTimeVariable]
);
- // make some backwards compatability updates to the appstate retrieved from the back end
- const appStateCheckedRef = useRef(false);
-
useEffect(() => {
if (appStateCheckedRef.current) return;
if (analysis) {
@@ -243,6 +251,7 @@ export function useAppState(uiStateKey: string, analysisState: AnalysisState) {
return {
appState,
+ analysisState,
setActiveMarkerConfigurationType: useSetter(
'activeMarkerConfigurationType'
),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dmfalke Is the above still valid given the investigations you made and posted about on Slack?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes! 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made these changes, but the issue is still happening for me :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured out why the issue is still happening. When we transition from a saved analysis to a new analysis, the ref appStateCheckedRef
is set to false after the new unsaved analysis is returned by useAnalysis
. I changed this to a useState variable, and that addresses the issue, since updating its value will trigger a rerender:
diff --git a/packages/libs/eda/src/lib/map/analysis/appState.ts b/packages/libs/eda/src/lib/map/analysis/appState.ts
index 2437ef7659..72fbc9b87f 100644
--- a/packages/libs/eda/src/lib/map/analysis/appState.ts
+++ b/packages/libs/eda/src/lib/map/analysis/appState.ts
@@ -2,7 +2,7 @@ import { getOrElseW } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/function';
import * as t from 'io-ts';
import { isEqual } from 'lodash';
-import { useCallback, useEffect, useMemo, useRef } from 'react';
+import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useAnalysis, useGetDefaultVariableDescriptor } from '../../core';
import { VariableDescriptor } from '../../core/types/variable';
import { useGetDefaultTimeVariableDescriptor } from './hooks/eztimeslider';
@@ -122,11 +122,11 @@ export function useAppState(uiStateKey: string, analysisId?: string) {
const analysisState = useAnalysis(analysisId);
// make some backwards compatability updates to the appstate retrieved from the back end
- const appStateCheckedRef = useRef(false);
+ const [appStateChecked, setAppStateChecked] = useState(false);
useEffect(() => {
// flip bit when analysis id changes
- appStateCheckedRef.current = false;
+ setAppStateChecked(false);
}, [analysisId]);
const { analysis, setVariableUISettings } = analysisState;
@@ -184,7 +184,7 @@ export function useAppState(uiStateKey: string, analysisId?: string) {
);
useEffect(() => {
- if (appStateCheckedRef.current) return;
+ if (appStateChecked) return;
if (analysis) {
if (!appState) {
setVariableUISettings((prev) => ({
@@ -219,9 +219,9 @@ export function useAppState(uiStateKey: string, analysisId?: string) {
}));
}
}
- appStateCheckedRef.current = true;
+ setAppStateChecked(true);
}
- }, [analysis, appState, setVariableUISettings, uiStateKey, defaultAppState]);
+ }, [analysis, appState, setVariableUISettings, uiStateKey, defaultAppState, appStateChecked]);
function useSetter<T extends keyof AppState>(key: T) {
return useCallback(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That worked! Thanks Dave!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ready for review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd agree if they were equivalent in size/weight to the pencil icon, and located just to the right of it. Keep the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look great, thanks!
Closes #425