webcompat / web-bugs

A place to report bugs on websites.
https://webcompat.com
Mozilla Public License 2.0
746 stars 67 forks source link

piraeus.gov.gr - File are not ordered correctly by date #107285

Open webcompat-bot opened 2 years ago

webcompat-bot commented 2 years ago

URL: https://piraeus.gov.gr/proskliseis-ekdilosis-endiaferontos/

Browser / Version: Firefox 102.0 Operating System: Windows 10 Tested Another Browser: Yes Opera

Problem type: Something else Description: From Firefox browser I see older version while from Opera and Edge a newer with newer files uploaded. Steps to Reproduce: When I enter the page, I can not see the uploaded files I see when I open the same page from other browsers, even in the same PC (tried Edge just to confirm) or other PC where Opera is Installed.

View the screenshot Screenshot
Browser Configuration
  • None

From webcompat.com with ❤️

softvision-oana-arbuzov commented 2 years ago

Thanks for the report, I was able to reproduce the issue. It seems that files are not displayed in the correct order in Firefox (year 2022 files are on page 15). image image

Note:

  1. The issue is not reproducible on Chrome and Microsoft Edge.
  2. Strangely there are 38 pages of files both in Firefox and Chrome, so it might be something related to sorting. image

Tested with: Browser / Version: Firefox Nightly 104.0a1 (2022-07-11), Firefox Release 102.0.1, Firefox Beta 103.0b7 Operating System: Windows 10 Pro

Moving to Needsdiagnosis for further investigation.

[qa_28/2022]

wisniewskit commented 2 years ago

The code responsible for the sorting is:

            getNinjaTableConfig: function(t) {
                var e = this
                  , r = (RegExp.prototype.test.bind(/(<([^>]+)>)/i),
                t.init_config);
                if (r.data_request_url && (r.rows = b.get(r.data_request_url)),
                jQuery.each(t.columns, (function(n, u) {
                    u.original_type = u.type,
                    "date" == u.type ? (u.sortValue = function(t) {
                        return (FooTable.is.element(t) || FooTable.is.jq(t)) && (t = jQuery(t).text()),
                        t ? (u.formatString && (t = moment(t, u.formatString).valueOf()),
                        t) : 0
                    }

Where formatString is "D/M/YYYY" and the dates are like "22/8/2022". Adding a logpoint to see the values being generated there by moment, it looks like Firefox and Chrome are behaving the same way, so it's not the date string themselves or the moment parsing.

Their predraw function is where the sorting is initiated:

      predraw: function () {
        if (this.column) {
          var t = this.column;
          this.ft.rows.array.sort(function (e, i) {
            return 'DESC' == t.direction ? t.sorter(i.cells[t.index].sortValue, e.cells[t.index].sortValue) : t.sorter(e.cells[t.index].sortValue, i.cells[t.index].sortValue)
          })
        }

Hmm. This is t.sorter:

      t.Column.prototype.sorter = function (t, e) {
        return window.ninjaTablesCustomSorter ? window.ninjaTablesCustomSorter(t, e) : 'string' == typeof t && 'string' == typeof e ? t.localeCompare(e) : t === e ? 0 : t < e ? - 1 : 1
      },

If I change that logic to return t > e instead of t === e ? 0 : t < e ? - 1 : 1 then it works, so there is something weird about the logic they're using which throws Firefox off here.

Ah, if I change the logic to this, it works:

        if (t===e) return 0;
        if (t<e) return -1;
        if (t>e) return 1; // theirs always returns 1 in this case, no test

So let's see what ends up getting a 1 value in their code which doesn't in the above change:

t=1621828800000 e=NaN
t=NaN                     e=1618977600000
t=1621483200000 e=NaN
t=1618545600000 e=NaN
t=NaN                     e=1621915200000
t=1621224000000 e=NaN
t=1617595200000 e=NaN

Ah. Indeed, two of the table rows end up with a NaN for their sortValue, because the "date" is actually the string "ΑΜΕΣΑ" (which my translator tells me means "immediately").

But the weird thing is that Chrome also has to sort those values, and it also ends up with them getting the value of 1, so I'm at a loss here. I've tried to make a reduced test-case, but it's sorting properly, so there must be something else going on here that's throwing off the sorting.

@denschub @ksy36 have either of you ever run into anything like this?