getkirby / kirby

Kirby's core application folder
https://getkirby.com
Other
1.31k stars 168 forks source link

Files section sort value NaN #6067

Closed AnnikaGruca-JUNO closed 10 months ago

AnnikaGruca-JUNO commented 11 months ago

Description

When uploading a file in a section without a defined file template and sortable: false, Sort: NaN is inserted in the file’s content file. The file is then displayed at the end the section.

Expected behaviour

In Kirby 3, the files were sorted by name.

To reproduce

Can be reproduced in the Starterkit in site/blueprints/pages/album.yml from line 40:

  - width: 2/3
    sections:
      images:
        type: files
        layout: cards
        sortable: false # add this
        # template: image # remove this

Your setup

Kirby Version
4.0.1

distantnative commented 10 months ago

@bastianallgeier found the source of this issue: https://github.com/getkirby/kirby/blob/main/panel/src/panel/upload.js#L293

When there is no template and not sortable, attributes is actually empty (see https://github.com/getkirby/kirby/blob/main/config/sections/files.php#L194-L200). In turn, attributes is not an empty object but actually ends up as an empty array in JS world. And .sort on an array is a method, which is why the if statement gets entered and then NaN is the result.

Some ideas: