-
-
Notifications
You must be signed in to change notification settings - Fork 40
674: Implement edit form with resource info populated #678
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
base: develop
Are you sure you want to change the base?
Conversation
RNR1
left a comment
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.
First pass
| }); | ||
|
|
||
| useEffect(() => { | ||
| reset({ |
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 shouldn’t be necessary if you have already defined the defaultValues
|
|
||
| {resourceForm === FORAGE_RESOURCE_TYPE && ( | ||
| <AddForaging | ||
| key={editingResource?.id || 'new'} |
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.
What is the reason for adding the key here and in other components?
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.
so basically my intention was to reset all of its internal state of the component by changing the key. so when I didnt have that and switched over between different resources. The old resource form data stayed. Kinda like using the bug we had a while ago with the search function but this time intentionally to to force a fresh remount
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 was one of the workarounds I thought of to get around components mounting only once to show the correct data
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.
We should prevent switching resources while editing. I'm unsure how this is possible, but it sounds undesireable
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.
like if we are in edit mode and click on a different marker it wont fly to that pin?
src/db.js
Outdated
| // 1. Store suggestion in database | ||
| // 2. Create admin review/approval interface | ||
| // 3. Define how approved suggestions are applied to resources | ||
| throw new Error('Suggestion submission not yet implemented. Awaiting admin review workflow design.'); |
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.
Can we remove this throw statement? We should only throw errors if we need to block a specific flow. In this case, It's ok if this function will have no operation, but we should have a TODO comment for backfilling the implmentation
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.
ok gotcha
| dispatch({ type: 'SET_TOOLBAR_MODAL', modal }); | ||
| }; | ||
|
|
||
| useEffect(() => { |
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.
Can we only use the state initialization callback to define these instead of having a useEffect hook?
We can use the editingResource?.resource_type ?? null as the initial value for the resource form, and the existing initialization for the values.
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 would have to add unmountonexit to the component. so the issue was that when the modal was closed the component stayed mounted. should I just add that to the collapse mui component? so that the component actually remounts and we can grab the correct values? not really sure what the best approach is 🤔. @RNR1
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 might make sense. I think this is one of the approaches I took in my refactor PR
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.
When I tried out unmountOnExit it only unmounted its children, and not the AddResourceModalV2 component itself. So I think the component only mounts when the app loads the first time, so im not sure how we can get around that
| hasFountain: false | ||
| }; | ||
|
|
||
| const mapResourceToFormState = resource => { |
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 we able to break this function down into multiple functions?
getStandardResourceValuesthat receives the resource and defaultValues (theinitialState) and returns a new object that merges the defaultValues with the shared resource values (name, address, etc)- for each resource:
get<ResourceType>ResourceValuesfor resource-specific values.- It receives the existing state and the resource and returns a new object merging the existing state with the specific values.
- We should iterate through the resource lists (
tags,dispenser_type, etc) and modify the object if it satisfies the condition instead of usingincludesanywhere we set a value
const result = resource.water.tags.reduce((prev, next) => {
switch (tag) {
case 'FILTERED':
return { ...prev, filtration: true }
...
default:
return prev;
}
}, {})| // 3. Define how approved suggestions are applied to resources | ||
| throw new Error('Suggestion submission not yet implemented. Awaiting admin review workflow design.'); | ||
| } | ||
| // eslint-disable-next-line no-unused-vars |
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.
nit: You can prefix with _ to ignore the unused variables
Add edit modal functionality with pre-populated resource data and disabled address field for crowdsourcing edits. - Add Redux action and state for tracking editing resource - Wire edit button to dispatch editing action and open form - Create function to map resource data to form state - Detect edit mode in AddResourceModalV2 and initialize form - Pass editMode prop through all form components - Disable address field in edit mode (greyed out, no changes allowed) - Hide "Use my location" button in edit mode
- Use reset() method to update form fields when props change - Add useEffect hooks to all resource form components to sync form state - Address field is disabled in edit mode to prevent location changes - Modal titles updated to show Edit vs Add based on mode - Tests created for edit functionality validation
…ggestion workflow - Enable address field editing across all resource types (water, food, bathroom, foraging) - Allow 'Use my location' button functionality during edit mode with full geocoding validation - Remove edit mode blocking logic from address fields and styling - Update ResourceEntry typedef to document id field for resource tracking - Defer submitSuggestion implementation pending admin review/approval workflow design - Add TODO comments for future suggestion submission feature planning
- remove console.warn from edit mode handler - replace throw with no-op return in submitSuggestion - add comment explaining key prop for form remount - remove redundant useEffect reset in AddWaterTap - refactor mapResourceToFormState into smaller functions with mapping constants
- block map pin clicks while in edit mode - remove key prop from form components - prefix unused variable with underscore
698c4a5 to
f66762e
Compare
Change Summary
Implements the crowdsourcing edit form that pre-populates with existing resource information when users click "Suggest Edit" from the resource detail modal.
Change Reason
Issue #674 requires the edit button (from #648) to open a crowdsourcing form with the resource's existing data pre-filled, allowing users to suggest edits to resources.
Changes
src/actions/actions.js: AddedsetEditingResourceaction to track the resource being editedsrc/reducers/filterMarkers.js: AddededitingResourcestate propertysrc/components/SelectedTapDetails/SelectedTapDetails.jsx: Replaced placeholder with meatball menu containing "Suggest Edit" and "Report" optionssrc/components/AddResourceModal/AddResourceModalV2.jsx:mapResourceToFormState()to convert database resource format to form stateeditingResourceeditModeprop to child formssrc/components/AddResourceModal/Add*.jsx(Water, Food, Bathroom, Foraging):reset()from react-hook-form to populate fields when editingeditModepropVerification
The form correctly populates with resource data when clicking "Suggest Edit":
Note: Actual edit submission is deferred pending implementation of the suggestion/approval workflow.
Related Issues: #674