Fix issue that would cause sort order of fields to be corrupted on field changes (#6174)

Fixes #6091
This commit is contained in:
Rijk van Zanten
2021-06-09 20:13:21 -04:00
committed by GitHub
parent 1f2bce9fd2
commit 11ea192368
2 changed files with 10 additions and 20 deletions

View File

@@ -61,7 +61,7 @@ export const useFieldsStore = defineStore({
const fields: FieldRaw[] = fieldsResponse.data.data;
this.fields = this.adjustSortForSystem([...fields.map(this.parseField), fakeFilesField]);
this.fields = [...fields.map(this.parseField), fakeFilesField];
this.translateFields();
},
@@ -106,24 +106,6 @@ export const useFieldsStore = defineStore({
};
});
},
/**
* System collections have system fields. We'll have to adjust all custom fields to have their
* sort values incremented by the amount of system fields, to ensure the fields are sorted
* correctly after the system fields. (#5520)
*/
adjustSortForSystem(fields: FieldRaw[]) {
const systemFields = fields.filter((field) => field.meta?.system === true);
if (systemFields.length === 0) {
return systemFields;
}
return fields.map((field) => {
if (field.meta?.system === true) return field;
if (field.meta?.sort) field.meta.sort += systemFields.length;
return field;
});
},
async createField(collectionKey: string, newField: Field) {
const stateClone = [...this.fields];