sort fields when getting them from the store (#4154)

This commit is contained in:
Nitwel
2021-02-18 18:54:49 +01:00
committed by GitHub
parent 7a2a4c311a
commit 52922866ef
2 changed files with 13 additions and 9 deletions

View File

@@ -193,14 +193,12 @@ export default defineComponent({
const fields = computed(() => {
if (!state.relations[0].many_collection) return [];
return fieldsStore.state.fields
.filter((field) => field.collection === state.relations[0].many_collection)
.map((field) => ({
text: field.field,
value: field.field,
disabled:
!field.schema || field.schema?.is_primary_key || field.type !== currentCollectionPrimaryKey.value.type,
}));
return fieldsStore.getFieldsForCollection(state.relations[0].many_collection).map((field: Field) => ({
text: field.field,
value: field.field,
disabled:
!field.schema || field.schema?.is_primary_key || field.type !== currentCollectionPrimaryKey.value.type,
}));
});
const collectionMany = computed({

View File

@@ -222,7 +222,13 @@ export const useFieldsStore = createStore({
return primaryKeyField;
},
getFieldsForCollection(collection: string) {
return this.state.fields.filter((field) => field.collection === collection);
return this.state.fields
.filter((field) => field.collection === collection)
.sort((a, b) => {
if (a.field < b.field) return -1;
else if (a.field > b.field) return 1;
else return 1;
});
},
getField(collection: string, fieldKey: string) {
if (fieldKey.includes('.')) {