[WEB-31] Bug renaming reordering issue (and also WEB-68) #377
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why are the changes needed?
Currently, when you rename a file in the folder and refresh, the renamed file is repositioned to the end of the file list, jumbling the original order.
WEB-68
In this ticket I also happened to fixed the issue covered in the ticket WEB-68 (https://csesoc.atlassian.net/browse/WEB-68) where input boxes were rendered with old initial values.
Changes
The reason that files are reordered upon renaming is due to how
UPDATE
s in PostgreSQL works. PostgreSQL tables store their records in an undefined order, hence we cannot assume that a table retains its original order after anUPDATE
.A possible fix to this would to be adding an explicit ordering to the query that fetches the files from the database. However this seems infeasible as there does not seem to be an existing
datetime_created
orserial
field in the existing database schema to explicitly sort the files on the desired order.This PR contains an alternate solution which displays files in alphabetical order. Additionally, the comparator used also ensures that all folders are displayed before files.
WEB-68
The reason why initial input values were not updating was because these elements are actually rendered multiple times upon refresh.
First, the file containers render with the data stored on the frontend in redux, which is in the initial order before the renaming of the file. Then, after the call to the backend, these values are updated with the new order. However, since the files will be in a new order and initial
useState()
values are only considered during the first render, the initial values will not be updated. This causes a mismatch between file names and initial values.To fix this, I explicitly called
setInputName(name)
in the event handler for when the file name label is double clicked to ensure that the proper initial value is displayed.