-
Notifications
You must be signed in to change notification settings - Fork 34
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
Analysis Module #92
Analysis Module #92
Conversation
Current changes - hide analysis button on click - add buttons for show result and download
2038d36
to
e3c2fea
Compare
96baef8
to
5460dea
Compare
BROKEN: - files to check: package.json src/components/MapView/index.tsx src/context/layers/impact.ts src/context/layers/layer-data.ts src/context/layers/nso.ts src/context/mapStateSlice.ts yarn.lock
Update: The below cycles have been fixed
There's a really big loop:
breaking also: |
@SimplyBallistic nice work! Here are a few answers to your questions:
-> it should show the same data as clicking on the map I added the color code to the legend since its easily accessible. Should it be kept? If not, should we try to make a more accurate color code or remove it entirely in favor of just the names of the hazard and baseline layers? -> This is actually the baseline layer, so it should reflect that be the same as putting a baseline layer only We don't flip any switches off when the analysis layer is shown. Should we? -> maybe switch the impact layer if there is one? |
We could add this in #98 as an enhancement to keep this PR manageable
If I understand correctly, I believe the legend already does this, so we're all good here! 👍
I'll make a quick commit to add this, or if @laveesh is interested in doing this you could do it here or on #98 #98 is purely for enhancements for now; we hope to get a fully functional Analysis UI out within this PR. However, if you believe point 1, 3 or anything else is needed for proper use of the UI let us know and we'll continue working here :) |
Conflicts: src/context/store.ts
@ericboucher |
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.
This is getting close! I had a few clean-up suggestions, but I think the important ones are:
-
Refactor the
runAnalysis
function a bit to move as much of the logic into Redux as possible - the async thunk should handle clearing out existing data. For input validation, we should either enforce them with a combination of Typescript & the UI (e.g. use Typescript and buttons being disabled to make sure that values exist beforerunAnalysis
is ever called), or have the validation live inside the async thunk itself to ensure that invalid values generate UI errors using our redux error handling infrastructure. -
Move
LayerDropdown
into thesrc/components
tree.
if (!selectedDate) { | ||
throw new Error('Date must be given to run analysis'); | ||
} | ||
|
||
if (!hazardLayerId || !baselineLayerId) { | ||
throw new Error('Layer should be selected to run analysis'); | ||
} |
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.
Do these errors display UI errors when they get thrown? This function is happening outside of a Redux thunk, so it seems like our error handling that we have set up there wouldn't apply here?
I think we basically want to move all the logic in this function into the redux thunk itself so that it can properly take advantage of Redux and the error handling we've set up there.
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.
these errors are more so to make TS happy, as TS already ensures non-null values are passed into the thunk. If these are thrown, then it highlights a clear developer-side issue as the fields weren't validated properly before runAnalysis
was called. (The button is disabled if the fields are invalid/empty).
Do you think it should be done a different way? What we could do instead is dispatch a notification to redux directly and print the error instead of throwing an error only a dev would notice.
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.
Gotcha, I see the issue. I think in a perfect world we'd handle these with form validations, and make sure that TS knows that this function will never be called without the form validations being run. But as long as we have form validations/user-friendly warnings there, it's probably fine for these to live behind the scenes. If we're relying on these to actually enforce the conditions (rather than just to make TS happy), we should make the errors visible though...
.map(key => TableDefinitions[key]) | ||
.filter(val => Boolean(val)), | ||
})); | ||
return map(layersList, (layerKeys, layersListKey) => { |
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.
Any reason not to just use the builtin map
here?
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.
are you referring to the Array#map
here? layersList
is an object, hence the use of map
as a shorthand to Object.entries().map()
which is the only vanilla methodology I can think of for this case. If you know a better vanilla approach let me know :)
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.
Ya, it'd require Object.entries
(or Object.keys/Object.values
) and then map
. But generally I don't think that's a big deal to add that one call, and the (theoretical at this point) idea is to only use Lodash where it's strictly necessary/a big savings over what is provided in the standard library. In theory this means that we could use tree-shaking to selectively include only parts of Lodash in the build, rather than the whole library.
a07458d
to
a8fc0c1
Compare
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 this should be good to merge at this point!
Test Deployment on: http://prism-analysis-ui-test.surge.sh/
Closes #86
Continuation: #98
Possible Discussion points
AnalysisUI test still needsfixed by removing defaultsLayerDefinitions
to be mocked otherwise it might fail iflayers.json
is changed due to mismatching snapshots.QOL Changes
LayerKey
type definition. Most places have been changed to rely on this type instead of genericstring
admin_level_local_names
withadmin_level_names
inlayers.json
admin_level
in NSO to be a numberfetchNsoLayerData->fetch*NSO*LayerData
AggregationOperations
an enum for easier typingLayerDropdown
, made into an individual component for easier testing and readability. Could be used elsewherepackage.json
, doesn't really do anything but its used in some IDEs when displaying personal project lists