mirror of
https://github.com/directus/directus.git
synced 2026-01-23 18:18:03 -05:00
Fix issue that would cause sort order of fields to be corrupted on field changes (#6174)
Fixes #6091
This commit is contained in:
@@ -5,12 +5,14 @@ import { getInterfaces } from '@/interfaces';
|
||||
import { InterfaceConfig } from '@/interfaces/types';
|
||||
import { Field } from '@/types';
|
||||
import { getDefaultInterfaceForType } from '@/utils/get-default-interface-for-type';
|
||||
import { clone } from 'lodash';
|
||||
import { clone, orderBy } from 'lodash';
|
||||
import { computed, ComputedRef, Ref } from 'vue';
|
||||
|
||||
export default function useFormFields(fields: Ref<Field[]>): { formFields: ComputedRef<Field[]> } {
|
||||
const { interfaces } = getInterfaces();
|
||||
|
||||
const systemFieldsCount = computed(() => fields.value.filter((field) => field.meta?.system === true).length);
|
||||
|
||||
const formFields = computed(() => {
|
||||
let formFields = clone(fields.value);
|
||||
|
||||
@@ -42,6 +44,10 @@ export default function useFormFields(fields: Ref<Field[]>): { formFields: Compu
|
||||
}
|
||||
}
|
||||
|
||||
if (field.meta?.sort && field.meta?.system !== true) {
|
||||
field.meta.sort = field.meta.sort + systemFieldsCount.value;
|
||||
}
|
||||
|
||||
return field;
|
||||
});
|
||||
|
||||
@@ -52,6 +58,8 @@ export default function useFormFields(fields: Ref<Field[]>): { formFields: Compu
|
||||
return hidden !== true && systemFake === false;
|
||||
});
|
||||
|
||||
formFields = orderBy(formFields, 'meta.sort');
|
||||
|
||||
return formFields;
|
||||
});
|
||||
|
||||
|
||||
@@ -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];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user