Skip to content

Commit

Permalink
Merge pull request #6480 from getkirby/v5/refactor/nonmutating-models…
Browse files Browse the repository at this point in the history
…section-items-computed

Models sections: non-mutating `items` computed
  • Loading branch information
bastianallgeier authored Jun 12, 2024
2 parents fddd1d7 + 1c47d24 commit 932cf27
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 43 deletions.
31 changes: 16 additions & 15 deletions panel/src/components/Sections/FilesSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,24 @@ export default {
},
items() {
return this.data.map((file) => {
file.sortable = this.options.sortable;
file.column = this.column;
file.options = this.$dropdown(file.link, {
query: {
view: "list",
update: this.options.sortable,
delete: this.data.length > this.options.min
}
});
const sortable = this.options.sortable;
// add data-attributes info for item
file.data = {
"data-id": file.id,
"data-template": file.template
return {
...file,
column: this.column,
data: {
"data-id": file.id,
"data-template": file.template
},
options: this.$dropdown(file.link, {
query: {
view: "list",
update: sortable,
delete: this.data.length > this.options.min
}
}),
sortable
};
return file;
});
},
type() {
Expand Down
57 changes: 29 additions & 28 deletions panel/src/components/Sections/PagesSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,37 @@ export default {
},
items() {
return this.data.map((page) => {
const disabled = page.permissions.changeStatus === false;
const status = this.$helper.page.status(page.status, disabled);
status.click = () => this.$dialog(page.link + "/changeStatus");
const sortable = page.permissions.sort && this.options.sortable;
const deletable = this.data.length > this.options.min;
page.flag = {
status: page.status,
disabled: disabled,
click: () => this.$dialog(page.link + "/changeStatus")
return {
...page,
buttons: [
{
...this.$helper.page.status(
page.status,
page.permissions.changeStatus === false
),
click: () => this.$dialog(page.link + "/changeStatus")
},
...(page.buttons ?? [])
],
column: this.column,
data: {
"data-id": page.id,
"data-status": page.status,
"data-template": page.template
},
deletable,
options: this.$dropdown(page.link, {
query: {
view: "list",
delete: deletable,
sort: sortable
}
}),
sortable
};
page.sortable = page.permissions.sort && this.options.sortable;
page.deletable = this.data.length > this.options.min;
page.column = this.column;
page.buttons = [status, ...(page.buttons ?? [])];
page.options = this.$dropdown(page.link, {
query: {
view: "list",
delete: page.deletable,
sort: page.sortable
}
});
// add data-attributes info for item
page.data = {
"data-id": page.id,
"data-status": page.status,
"data-template": page.template
};
return page;
});
},
type() {
Expand Down

0 comments on commit 932cf27

Please sign in to comment.