Skip to content
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

Files section sort value NaN #6067

Closed
AnnikaVennemann-JUNO opened this issue Dec 14, 2023 · 1 comment · Fixed by #6150
Closed

Files section sort value NaN #6067

AnnikaVennemann-JUNO opened this issue Dec 14, 2023 · 1 comment · Fixed by #6150
Assignees
Labels
type: regression 🚨 Is a regression between versions
Milestone

Comments

@AnnikaVennemann-JUNO
Copy link

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
Copy link
Member

@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:

  • Check for Array.isArray(this.attributes) === false in upload.js
  • Remove the array_filter call from fields.php to ensure that attributes is always an object

@distantnative distantnative added type: regression 🚨 Is a regression between versions needs: decision 🗳 Requires a decision to proceed labels Jan 1, 2024
@distantnative distantnative added this to the 4.1.0 milestone Jan 1, 2024
@distantnative distantnative removed the needs: decision 🗳 Requires a decision to proceed label Jan 15, 2024
@distantnative distantnative linked a pull request Jan 15, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression 🚨 Is a regression between versions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants