Skip to content

Conversation

@tomasz1986
Copy link
Member

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

image

After

image

…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>
@tomasz1986 tomasz1986 marked this pull request as draft September 14, 2022 00:21
@calmh
Copy link
Member

calmh commented Sep 14, 2022

Is there really no sane way of checking if an object is empty? Do we need to create a helper function?

@tomasz1986
Copy link
Member Author

tomasz1986 commented Sep 14, 2022

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.

Signed-off-by: Tomasz Wilczyński <twilczynski@naver.com>
@tomasz1986
Copy link
Member Author

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 data is just {}, but I'm not really sure how to change the code to do do it cleanly.

var dataReceived = $http.get(urlbase + '/folder/versions?folder=' + encodeURIComponent($scope.restoreVersions.folder))
.success(function (data) {
$.each(data, function (key, values) {
$.each(values, function (idx, value) {
value.modTime = new Date(value.modTime);
value.versionTime = new Date(value.versionTime);
});
values.sort(function (a, b) {
return b.versionTime - a.versionTime;
});
});
if (closed) return;
$scope.restoreVersions.versions = data;
});

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 Loading data... line is shown inside the table and not before it. I've also changed loading: $translate.instant("Loading...") to loading: $translate.instant("Loading data...") in JS to make both the same for consistency.

Do you mean creating a helper function instead of (restoreVersions.versions | json) === '{}'?

@tomasz1986 tomasz1986 marked this pull request as ready for review September 17, 2022 19:56
@calmh
Copy link
Member

calmh commented Sep 20, 2022

Yeah that's pretty ugly I think. There's angular.equals(foo, {}) or jQuery.isEmptyObject we could maybe use instead.

Signed-off-by: Tomasz Wilczyński <twilczynski@naver.com>
Signed-off-by: Tomasz Wilczyński <twilczynski@naver.com>
Comment on lines 2594 to 2596
if (isEmptyObject(data)) {
$scope.restoreVersions.noversions = true;
} else {
Copy link
Member

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.

Copy link
Member Author

@tomasz1986 tomasz1986 Sep 26, 2022

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.

Copy link
Member

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 ).

Copy link
Member Author

@tomasz1986 tomasz1986 Sep 26, 2022

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

https://github.com/syncthing/syncthing/pull/8539/files#diff-35607bd09efb510801fed738df57073a32758c8f16b7f40693fe007d92fd306dL3

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>
Signed-off-by: Tomasz Wilczyński <twilczynski@naver.com>
Signed-off-by: Tomasz Wilczyński <twilczynski@naver.com>
@tomasz1986
Copy link
Member Author

tomasz1986 commented Jan 5, 2023

I've found the helper function sizeOf which is already used in other HTML files of the GUI, so I've decided to use it here too, which has simplified the whole diff greatly. Please check the current iteration and let me know whether the code is fine like this or whether there's still something to fix.

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.

Copy link
Member

@imsodin imsodin left a 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.

Comment on lines +8 to +11
<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>
Copy link
Member

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?

Copy link
Member Author

@tomasz1986 tomasz1986 Jan 15, 2023

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?

Copy link
Member

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>
@calmh calmh merged commit b53c1b9 into syncthing:main Mar 10, 2023
calmh added a commit to imsodin/syncthing that referenced this pull request Mar 10, 2023
* 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)
calmh added a commit to calmh/syncthing that referenced this pull request Mar 10, 2023
* 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)
calmh added a commit to calmh/syncthing that referenced this pull request Mar 10, 2023
* 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)
calmh added a commit to calmh/syncthing that referenced this pull request Mar 12, 2023
* 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)
@calmh calmh added this to the v1.23.3 milestone Mar 14, 2023
calmh added a commit to tomasz1986/syncthing that referenced this pull request Mar 18, 2023
* 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
  ...
@tomasz1986 tomasz1986 deleted the tomasz86/gui/restoreversions-disable-filters-when-no-versions branch September 12, 2023 18:34
@st-review st-review added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label Mar 10, 2024
@syncthing syncthing locked and limited conversation to collaborators Mar 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants