Skip to content

Commit

Permalink
convert arrays isModified to computed, revert double check
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartromanek committed Jan 15, 2025
1 parent 8a7a561 commit 92507db
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
### Changes

* The `pickerOptions` sub property of a color field's configuration has been merged with it's parent `options` object.
* The array editor's `isModified` method is now a computed property for consistency.

## 4.11.2 (2024-12-29)

Expand Down
41 changes: 21 additions & 20 deletions modules/@apostrophecms/schema/ui/apos/logic/AposArrayEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,26 @@ export default {
},
currentDocMeta() {
return this.meta[this.currentId]?.aposMeta || {};
},
isModified() {
if (this.currentId) {
const currentIndex = this.next.findIndex(item => item._id === this.currentId);
if (detectDocChange(this.schema, this.next[currentIndex], this.currentDoc.data)) {
return true;
}
}
if (this.next.length !== this.original.length) {
return true;
}
for (let i = 0; (i < this.next.length); i++) {
if (this.next[i]._id !== this.original[i]._id) {
return true;
}
if (detectDocChange(this.schema, this.next[i], this.original[i])) {
return true;
}
}
return false;
}
},
async mounted() {
Expand Down Expand Up @@ -242,26 +262,7 @@ export default {
getFieldValue(name) {
return this.currentDoc.data[name];
},
isModified() {
if (this.currentId) {
const currentIndex = this.next.findIndex(item => item._id === this.currentId);
if (detectDocChange(this.schema, this.next[currentIndex], this.currentDoc.data)) {
return true;
}
}
if (this.next.length !== this.original.length) {
return true;
}
for (let i = 0; (i < this.next.length); i++) {
if (this.next[i]._id !== this.original[i]._id) {
return true;
}
if (detectDocChange(this.schema, this.next[i], this.original[i])) {
return true;
}
}
return false;
},

async validate(validateItem, validateLength) {
if (validateItem && this.next.length > 0 && this.currentId) {
this.triggerValidation = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ export default {
// Returns true if the cancellation does occur
async confirmAndCancel() {
let dismiss;
const modified = typeof this.isModified === 'function' ? this.isModified() : this.isModified;
if (modified) {
if (this.isModified) {
const discard = await apos.confirm({
heading: this.cancelHeading,
description: this.cancelDescription,
Expand Down

0 comments on commit 92507db

Please sign in to comment.