Skip to content

Commit 95626fe

Browse files
authored
Pro 8230 improve schema (#5044)
* no updateNextAndEmit when inputs update, watch changes instead * upgrades vue version * simplifies AposSchema, improves perfs
1 parent 311b6f9 commit 95626fe

6 files changed

Lines changed: 22 additions & 47 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## UNRELEASED
4+
5+
### Changes
6+
7+
* Refactors complex logic from `AposSchema` that handle data updates to simplifies it.
8+
39
## 4.22.0 (2025-10-01)
410

511
### Adds

modules/@apostrophecms/modal/ui/apos/mixins/AposEditorMixin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export default {
181181
async handleSaveError(e, { fallback }) {
182182
// eslint-disable-next-line no-console
183183
console.error(e);
184-
if (e.body && e.body.data && e.body.data.errors) {
184+
if (e.body?.data?.errors) {
185185
const serverErrors = {};
186186
let first;
187187
e.body.data.errors.forEach(e => {

modules/@apostrophecms/schema/ui/apos/components/AposSchema.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
:server-error="fields[field.name].serverError"
5353
:doc-id="docId"
5454
:generation="generation"
55-
@update:model-value="updateNextAndEmit"
5655
@update-doc-data="onUpdateDocData"
5756
@validate="emitValidate()"
5857
/>

modules/@apostrophecms/schema/ui/apos/logic/AposSchema.js

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { detectFieldChange } from 'Modules/@apostrophecms/schema/lib/detectChange';
21
import { getConditionTypesObject } from '../lib/conditionalFields';
32

43
export default {
@@ -130,9 +129,6 @@ export default {
130129
...item,
131130
required
132131
},
133-
value: {
134-
data: this.modelValue.data[item.name]
135-
},
136132
serverError: this.serverErrors && this.serverErrors[item.name],
137133
modifiers: this.computeModifiers(item)
138134
}
@@ -167,6 +163,13 @@ export default {
167163
}
168164
},
169165
watch: {
166+
fieldState: {
167+
deep: 2,
168+
handler() {
169+
this.updateNextAndEmit();
170+
},
171+
flush: 'post'
172+
},
170173
schema() {
171174
this.populateDocData();
172175
},
@@ -211,6 +214,7 @@ export default {
211214
created() {
212215
this.populateDocData();
213216
},
217+
214218
methods: {
215219
emitValidate() {
216220
this.$emit('validate');
@@ -269,53 +273,18 @@ export default {
269273
if (!this.schemaReady) {
270274
return;
271275
}
272-
const oldHasErrors = this.next.hasErrors;
273-
// destructure these for non-linked comparison
274-
const oldFieldState = { ...this.next.fieldState };
275-
const newFieldState = { ...this.fieldState };
276-
277-
let changeFound = false;
278-
279276
this.next.hasErrors = false;
280-
this.next.fieldState = { ...this.fieldState };
281-
282277
this.schema
283278
.filter(field => this.displayComponent(field))
284279
.forEach(field => {
285280
if (this.fieldState[field.name].error) {
286281
this.next.hasErrors = true;
287282
}
288-
// This simply check if a field has changed since it has been
289-
// instantiated
290-
if (
291-
this.fieldState[field.name].data !== undefined &&
292-
detectFieldChange(
293-
field,
294-
this.next.data[field.name],
295-
this.fieldState[field.name].data
296-
)
297-
) {
298-
changeFound = true;
299-
300-
// fieldState never gets the relationships postprocessed data
301-
// that's why it gets seen as different than next all the time
302-
this.next.data[field.name] = this.fieldState[field.name].data;
303-
} else {
304-
this.next.data[field.name] = this.modelValue.data[field.name];
305-
}
283+
this.next.data[field.name] = this.fieldState[field.name].data;
306284
});
307-
if (
308-
oldHasErrors !== this.next.hasErrors ||
309-
oldFieldState !== newFieldState
310-
) {
311-
// Otherwise the save button may never unlock
312-
changeFound = true;
313-
}
314285

315-
if (changeFound) {
316-
// ... removes need for deep watch at parent level
317-
this.$emit('update:model-value', { ...this.next });
318-
}
286+
this.next.fieldState = { ...this.fieldState };
287+
this.$emit('update:model-value', { ...this.next });
319288
},
320289
displayComponent({ name, hidden = false }) {
321290
if (hidden === true) {

modules/@apostrophecms/schema/ui/apos/logic/AposSubform.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,14 @@ export default {
109109
this.docFields = value;
110110
this.evaluateConditions();
111111
},
112-
async submit() {
112+
submit() {
113113
this.triggerValidation = true;
114-
this.$nextTick(async () => {
114+
this.$nextTick(() => {
115115
if (this.docFields.hasErrors) {
116116
this.triggerValidation = false;
117117
return;
118118
}
119+
119120
this.$emit('submit', {
120121
name: this.subform.name,
121122
values: this.docFields.data

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
"underscore.string": "^3.3.4",
125125
"uploadfs": "^1.25.1",
126126
"void-elements": "^3.1.0",
127-
"vue": "^3.3.8",
127+
"vue": "^3.5.20",
128128
"vue-advanced-cropper": "^2.8.8",
129129
"vue-loader": "^17.1.0",
130130
"vue-style-loader": "^4.1.3",

0 commit comments

Comments
 (0)