-
Notifications
You must be signed in to change notification settings - Fork 2
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
fix: Map and Label breaking on back action #3825
Conversation
Removed vultr server and associated DNS entries |
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.
Looks like you're on the right track for this bug! Know this is still draft, but want to flag what's seeming like a possible new side-effect bug of your changes:
Here's steps to recreate:
- Navigate forwards to Map&Label & draw two features
- Click "reset all" button the map -> features and tabs should both clear
- Draw two features again
- "Continue" forwards this time
- Navigate "back" to Map&Label
- Confirm I can add another feature to map and tab is added (works now!)
- Click "reset all" button on the map -> map is cleared but the tabs are not (new bug?!)
Can you recreate too?
First guess would be to double check that any changes you're making to the map context methods stay in sync with their form method counterpart !
move test files to test folder tidy test expects fix: remove unused imports
a237a8d
to
407e57e
Compare
); | ||
|
||
const [minError, setMinError] = useState<boolean>(false); | ||
const [maxError, setMaxError] = useState<boolean>(false); | ||
const [loadPreviousValues, setLoadPreviousValues] = useState<boolean>( |
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.
Went round the blocks with this trying to find an elegant solution, this felt like the best option to ensure previous values only loaded once
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 don't really understand the addition of these local state variables - why can't we simply ensure addInitialFeaturesToMap
is only called if when previouslySubmittedData
is present? What's a scenario where we're trying to load initial values more than once?
If we do indeed need this, can we rename it to something like loadPreviousValuesOnMap
because it's not actually handling the form tab data (formik.initialValues
is, right?)
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.
From what I could understand, previouslySubmittedData
is always present once you navigate backwards, so when you add a new point the code will run again and it will add the new point to features
then hit the if()
statement then reassign features
to be previouslySubmittedData.data...
I initially tried to place it in a useEffect()
to only run the if
statement on initial mount then whenever previouslySubmittedData
changed, but I couldn't get it to work so easily, and it felt like a larger change than the state variable.
Have I missed a simpler solution?
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.
Thanks for explanation - happy to keep this approach then, it seems to be achieving what we want !
formik.setFieldValue(`schemaData[${destinationIndex}]`, sourceFeature); | ||
formik.setFieldValue(`schemaData[${destinationIndex}]`, { | ||
...sourceFeature, | ||
label: `${destinationIndex + 1}`, |
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 label was being assigned based on the object you were copying from rather than the object we were copying to
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.
Good catch but I don't think this is quite working in all scenarios correctly yet!
For example:
- I add two trees on the map
- I fill out tree two tab
- On tab 1, I "copy from" tree 2
- I "continue" & my labels are correct
- I come "back" and "remove tree" from tab 1 - this shifts the map & tab labels for previous "tree 2" to 1 now
- I "continue" again and my passport data has a single feature with
label: 2
when it should belabel: 1
to reflect map/tab changes after a point was removed !
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.
Thanks so much for catching this, I'll add some adjustments
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.
Testing added for this and hope I have solved it. I couldn't find another bug through manual testing...
editor.planx.uk/src/@planx/components/MapAndLabel/test/mocks/Trees.ts
Outdated
Show resolved
Hide resolved
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 file was becoming quite long, so it felt right to move the back navigation tests to separate file, and relocate these files to the test
folder on the Map and Label component
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.
On the right track - pizza is working more smoothly, but a few questions/comments while reading through the code!
); | ||
|
||
const [minError, setMinError] = useState<boolean>(false); | ||
const [maxError, setMaxError] = useState<boolean>(false); | ||
const [loadPreviousValues, setLoadPreviousValues] = useState<boolean>( |
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 don't really understand the addition of these local state variables - why can't we simply ensure addInitialFeaturesToMap
is only called if when previouslySubmittedData
is present? What's a scenario where we're trying to load initial values more than once?
If we do indeed need this, can we rename it to something like loadPreviousValuesOnMap
because it's not actually handling the form tab data (formik.initialValues
is, right?)
if (loadPreviousValues) { | ||
setFeatures(initialFeatures); | ||
setLoadPreviousValues(false); | ||
} |
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.
Again, see above comment - not following this change in particular !
editor.planx.uk/src/@planx/components/MapAndLabel/test/mocks/Trees.ts
Outdated
Show resolved
Hide resolved
export const previouslySubmittedDoubleData: PreviousData = { | ||
auto: false, | ||
...previousMockDoubleFeatureData, | ||
}; |
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.
Per your question in the PR description, mocking previouslySubmittedData
is how I'd expect to see "back" navigation tested at the component level 👍 This is consistent with other @planx/components
tests
formik.setFieldValue(`schemaData[${destinationIndex}]`, sourceFeature); | ||
formik.setFieldValue(`schemaData[${destinationIndex}]`, { | ||
...sourceFeature, | ||
label: `${destinationIndex + 1}`, |
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.
Good catch but I don't think this is quite working in all scenarios correctly yet!
For example:
- I add two trees on the map
- I fill out tree two tab
- On tab 1, I "copy from" tree 2
- I "continue" & my labels are correct
- I come "back" and "remove tree" from tab 1 - this shifts the map & tab labels for previous "tree 2" to 1 now
- I "continue" again and my passport data has a single feature with
label: 2
when it should belabel: 1
to reflect map/tab changes after a point was removed !
const secondTabPanel = getByTestId("vertical-tabpanel-1"); | ||
expect(secondTabPanel).toBeVisible(); | ||
|
||
addMultipleFeatures([point1, point2, point3]); |
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: aren't point1
and point2
already on the map? Am we actually mocking adding "multiple" features here or just one? I understand the mock data needs to reflect the full feature collection, but I wonder if there's a way we can make this more clear in helper function naming, a code comment etc?
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 correct, it should just be adding one feature at a time. I'll adjust and switch the functions
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.
Found that this was correct and just adding a single point deletes the others from the map, so I need them added like this. I've added a comment above each line explaining this need
editor.planx.uk/src/@planx/components/MapAndLabel/test/public.backNavigation.test.tsx
Show resolved
Hide resolved
refine naming of test mocks remove test.only
9af3f9f
to
960c1eb
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.
Working as expected for me now - thanks for iterating on this one !
The initial bug centred on navigating back after completing the Map and Label component, and finding the active tab not selected, then when adding a new point, the tabs would break. My solution was to change how the ActiveIndex was assigned and handled, and when the previous data from the passport was added to
features
. From this, I found a couple other bugs on how we handle labels when copying data.Should all be fixed now with testing around navigating back. There is no test coverage right now for navigating back, adding new data, continuing forward, then navigating back again.
I would be interested to know if I should be rendering a different component within the tests so I can test clicking "Continue" then clicking "Back" - at the moment, I just recreate rendering a component with the
previouslySubmittedData
. Would be great to have feedback on whether this would be overkill.