-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
gui: Disable Restore Versions filters when no versioned files exist (fixes #5408) #8539
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
gui: Disable Restore Versions filters when no versioned files exist (fixes #5408) #8539
Conversation
…ixes syncthing#5408) Currently, the name and date filters in the Restore Versions modal are always enabled, even if there are no versioned files present. With this change, they are enabled only when there are no errors and versioned files actually exist. In addition to disabling the filters, also completely skip date picker generation, as it serves no function while still displaying a non-sense date range, which starts today and ends in the past. Signed-off-by: Tomasz Wilczyński <twilczynski@naver.com>
|
Is there really no sane way of checking if an object is empty? Do we need to create a helper function? |
|
Yeah, I actually marked this WIP, because I'm going to change the approach completely. There's no need to generate the tree at all when there're no versions. |
|
I've changed the code a bit, so that tree generation is skipped almost immediately if there are no versions. I don't think it's that great though, as ideally all further parsing should be stopped in the function below. There's no point going forward if syncthing/gui/default/syncthing/core/syncthingController.js Lines 2592 to 2605 in 39d3424
I've also modified the HTML, so that the table and filter inputs are always shown. This way there's no GUI jumping, as the modal stays the same size and doesn't shrink, and also the Do you mean creating a helper function instead of |
|
Yeah that's pretty ugly I think. There's |
Signed-off-by: Tomasz Wilczyński <twilczynski@naver.com>
Signed-off-by: Tomasz Wilczyński <twilczynski@naver.com>
| if (isEmptyObject(data)) { | ||
| $scope.restoreVersions.noversions = true; | ||
| } else { |
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.
Could you initially set it to $scope.restoreVersions.versions = null and then if !closed && !isEmptyObject { iterate and assign to ...versions? Then in all the conditions you can check for !restoreVersions.versions. No new fields or weird stringify checks to identify an empty object.
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've done that now (and actually did try doing something similar a few times before), but there's one problem that I'm unable to solve. Basically, with the current code, the Restore Versions modal loads fine on the first try. However, if you close and re-open it, the following error pops up.
TypeError: Cannot read properties of undefined (reading 'expanderClosed')
at setIcon (jquery.fancytree-all-deps.js:11752:14)
at Fancytree.nodeRenderStatus (jquery.fancytree-all-deps.js:11848:5)
at Fancytree.nodeRenderStatus (jquery.fancytree-all-deps.js:1701:22)
at Fancytree.nodeRenderTitle (jquery.fancytree-all-deps.js:6521:10)
at Fancytree._super (jquery.fancytree-all-deps.js:1685:22)
at Fancytree.nodeRenderTitle (jquery.fancytree-all-deps.js:13185:15)
at Fancytree.nodeRenderTitle (jquery.fancytree-all-deps.js:1701:22)
at Fancytree.nodeRender (jquery.fancytree-all-deps.js:13123:11)
at Fancytree.nodeRender (jquery.fancytree-all-deps.js:1701:22)
at Fancytree.nodeRender (jquery.fancytree-all-deps.js:13144:11)
I've only managed to get around it by changing the code from
<table id="restoreTree">
<tbody>
<tr>
<td>
<span ng-if="restoreVersions.versions" translate>Loading data...</span>
<span ng-if="!restoreVersions.versions" translate>There are no file versions to restore.</span>
</td>
<td></td>
</tr>
</tbody>
</table>
to something more like
<table id="restoreTree" ng-if="restoreVersions.versions">
<tbody>
<tr>
<td translate>Loading data...</td>
<td></td>
</tr>
</tbody>
</table>
<table id="restoreTree" ng-if="!restoreVersions.versions">
<tbody>
<tr>
<td translate>There are no file versions to restore.</td>
<td></td>
</tr>
</tbody>
</table>
which does get rid of the error, but the table code ends up being duplicated. The two messages themselves need to be inside the table cells in order to match the same style (padding, etc.) as when there are actual versioned files rendered 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.
Can you try readding the condition in L3:
39249a0#diff-35607bd09efb510801fed738df57073a32758c8f16b7f40693fe007d92fd306dL3
Not that I'd understand why it helps, but it looks like an unrelated change and with this UI code any change in code may trigger any change in behaviour (maybe not quite as bad, but almost :P ).
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.
Yeah, it works with that too (as it's essentially the same as when moved down to the table element), but the problem is that I wanted to move the span element
from outside into the table, so that its position and padding matches the table cells, which prevents the text from jumping that takes place now while the table is being loaded 😕 (and also keeps the whole modal the same size due to the table being always rendered). That's why I was experimenting with two different conditions — one for when restoreVersions.versions exists, and one for when restoreVersions.versions is empty.
Signed-off-by: Tomasz Wilczyński <twilczynski@naver.com>
…-when-no-versions
Signed-off-by: Tomasz Wilczyński <twilczynski@naver.com>
|
I've found the helper function Just for the record, all strings present here are already used in the GUI, so there's nothing new to add to the translations here. |
imsodin
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.
Looks good, just one change I don't understand.
| <td> | ||
| <span ng-if="sizeOf(restoreVersions.versions) > 0" translate>Loading data...</span> | ||
| <span ng-if="sizeOf(restoreVersions.versions) == 0" translate>There are no file versions to restore.</span> | ||
| </td> |
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 assume this exists for the time until fancytree is initialised, isn't it? What's the point of the conditional, instead of just always showing "loading data" until fancytree is ready?
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 question, and the code was remnants from the previous iteration, however I've now added yet another similar sizeOf check in the controller, so that the tree code doesn't run at all when there are no versions. This way, the window loads faster, there is no 1970 year stuck in the disabled date filter, and the two conditionals are actually required again (because without the tree code running, the existing table isn't replaced with the tree table).
I hope the explanation is clear… What do you think?
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.
Yep makes sense. I don't think I'll remember/be able to figure it out if I ever stumble over this again though, but it wasn't any better before so 🤷
Signed-off-by: Tomasz Wilczyński <twilczynski@naver.com>
Signed-off-by: Tomasz Wilczyński <twilczynski@naver.com>
* main: gui: Disable Restore Versions filters when no versioned files exist (fixes syncthing#5408) (syncthing#8539) build(deps): bump github.com/chmduquesne/rollinghash from 0.0.0-20180912150627-a60f8e7142b5 to 4.0.0+incompatible (syncthing#8804) build: Update dependencies (syncthing#8821)
* main: gui: Add Persian (fa) translation template (syncthing#8822) lib: Correctly handle encrypted trailer size (fixes syncthing#8556) (syncthing#8563) gui: Disable Restore Versions filters when no versioned files exist (fixes syncthing#5408) (syncthing#8539) build(deps): bump github.com/chmduquesne/rollinghash from 0.0.0-20180912150627-a60f8e7142b5 to 4.0.0+incompatible (syncthing#8804) build: Update dependencies (syncthing#8821)
* main: gui: Add Persian (fa) translation template (syncthing#8822) lib: Correctly handle encrypted trailer size (fixes syncthing#8556) (syncthing#8563) gui: Disable Restore Versions filters when no versioned files exist (fixes syncthing#5408) (syncthing#8539) build(deps): bump github.com/chmduquesne/rollinghash from 0.0.0-20180912150627-a60f8e7142b5 to 4.0.0+incompatible (syncthing#8804) build: Update dependencies (syncthing#8821)
* main: lib/protocol: Cache expensive key operations (fixes syncthing#8599) (syncthing#8820) gui: Add Persian (fa) translation template (syncthing#8822) lib: Correctly handle encrypted trailer size (fixes syncthing#8556) (syncthing#8563) gui: Disable Restore Versions filters when no versioned files exist (fixes syncthing#5408) (syncthing#8539) build(deps): bump github.com/chmduquesne/rollinghash from 0.0.0-20180912150627-a60f8e7142b5 to 4.0.0+incompatible (syncthing#8804) build: Update dependencies (syncthing#8821)
* main: (424 commits) gui, man, authors: Update docs, translations, and contributors lib/protocol: Cache expensive key operations (fixes syncthing#8599) (syncthing#8820) gui: Add Persian (fa) translation template (syncthing#8822) lib: Correctly handle encrypted trailer size (fixes syncthing#8556) (syncthing#8563) gui: Disable Restore Versions filters when no versioned files exist (fixes syncthing#5408) (syncthing#8539) build(deps): bump github.com/chmduquesne/rollinghash from 0.0.0-20180912150627-a60f8e7142b5 to 4.0.0+incompatible (syncthing#8804) build: Update dependencies (syncthing#8821) lib/api: Expose `blocksHash` in file info (syncthing#8810) gui, man, authors: Update docs, translations, and contributors lib/discover: Don't leak relay-tokens to discovery (syncthing#8762) gui, man, authors: Update docs, translations, and contributors gui: Add Croatian (hr) translation template (syncthing#8801) build(deps): bump github.com/quic-go/quic-go from 0.32.0 to 0.33.0 (syncthing#8800) cmd/stupgrades: Cache should apply to HEAD as well as GET build: Add more GitHub Actions gui: Remove non-existent customicons.css file reference (fixes syncthing#8797) (syncthing#8798) Only fail after chmod error if permissions differ (e.g. on config file) (syncthing#8771) gui, man, authors: Update docs, translations, and contributors build: Use Go 1.19.6 for Windows build: Update dependencies ...
Currently, the name and date filters in the Restore Versions modal are always enabled, even if there are no versioned files present. With this change, they are enabled only when there are no errors and versioned files actually exist.
In addition to disabling the filters, also completely skip date picker generation, as it serves no function while still displaying a non-sense date range, which starts today and ends in the past.
Signed-off-by: Tomasz Wilczyński twilczynski@naver.com
Screenshots
Before
After