-
Notifications
You must be signed in to change notification settings - Fork 87
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
feat: duplicate fields to next row #6285
Conversation
…fter If index error occurs, will insert the duplicate field at the end of the form fields
Not recommended, but issue will be solved with later mongoose versions >=6 which allows string comparison against ObjectId.
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.
Tested! But this PR is not backwards compatible! In the case where a new FE hits a old BE, the fields will be duplicated at the next index on FE but BE will save it at the end of the array of form fields. Conversely, if old FE hits new BE, FE will show that its added as the last field but BE will add it to the next one. This could be an issue with the volume of traffic we get, not sure if we have metrics as to how often admins duplicate fields?
Oh boy you are right... Thats the problem when FE and BE assumes each other knows, which is the problem of implementation 1 Not sure how we can circumvent this though? From speaking to Kenneth and Stacey, qualitatively, seems like duplicate is quite widely used. Then perhaps it might be best to only push this change at night or early mornign? 😭 |
Okay, checked and it could be up to ~50 in 5min. Could be substantial 🤔 |
Thanks @LinHuiqing, yeah I think we shouldn't release this during work hours... Will plan with the on-call person next week to release after hours! |
Yea actually I think there's no easy way to circumvent this that won't take too long :') If we really wanna do it safely, can break it up into multiple releases:
edit: points 1 + 2 can be done in the same release, then 3 in the next release |
frontend/src/features/admin-form/create/builder-and-design/mutations/useDuplicateFormField.ts
Show resolved
Hide resolved
return null | ||
} | ||
|
||
const index = formFields.findIndex((f) => fieldId === String(f._id)) |
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.
Why is the String()
wrapper necessary here when it wasn't used in useDuplicateFormField.ts?
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.
Thats because the f._id
here is a Mongoose ObjectId
whilst the one in useDuplicateFormField
is a string
hahaha
And the reason why I had to wrap it in string instead of using equals
comparator is because for some reason typescript or our current mongoose type does not recognise ObjectId.equals
which is very weird 😩
Problem
Currently when we duplicate fields, it is duplicated to the end of form fields. This makes it difficult for users of large forms to manoeuvre or modify their forms, and causes a lot of unneeded drag and drops.
This is related to our efforts to optimise performance for large forms in #6045
Solution
Form fields are now duplicated to the index immediately after the original field.
During implementation we had 2 potential methods of approaching this problem.
admin-form.service
will push the new duplicated field to end of form fields array. Whilst Frontend will do the same inuseDuplicateFormField
. Therefore, an explicit sync that we have to maintain between the two. So instead of pushing, both Backend and Frontend will look for the field to be duplicated and find its index + 1. This is the cleanest method of implementing this feat./duplicate
endpoint as areq.body
. This will allow an implicit sync between the Frontend and the Backend as the insertion index is passed between them. This can help in extensibility in the future too, if we have other features that requires duplicating to certain indexes.Decided on option 1, as it is the cleanest approach and the Backend does not rely on client input
Breaking Changes
Before & After Screenshots
BEFORE:
Screen.Recording.2023-05-08.at.6.26.15.PM.mov
AFTER:
Screen.Recording.2023-05-08.at.6.29.07.PM.mov
Tests
In a storage mode form
Email mode form