Sort fields as numeric

Fixes #4454
This commit is contained in:
rijkvanzanten
2021-03-11 18:41:38 -05:00
parent 06726f3462
commit 316bf32bd9
2 changed files with 6 additions and 6 deletions

View File

@@ -5,7 +5,7 @@ import getDefaultInterfaceForType from '@/utils/get-default-interface-for-type';
import { getInterfaces } from '@/interfaces';
import { FormField } from '@/components/v-form/types';
import { Field } from '@/types';
import { clone, orderBy } from 'lodash';
import { clone } from 'lodash';
export default function useFormFields(fields: Ref<Field[]>) {
const interfaces = getInterfaces();
@@ -13,9 +13,6 @@ export default function useFormFields(fields: Ref<Field[]>) {
const formFields = computed(() => {
let formFields = clone(fields.value);
// Sort the fields on the sort column value
formFields = orderBy(formFields, [(o) => o.meta?.sort || null, (o) => o.meta?.id]);
formFields = formFields.map((field, index) => {
if (!field.meta) return field;

View File

@@ -6,7 +6,7 @@ import { i18n } from '@/lang';
import formatTitle from '@directus/format-title';
import { useRelationsStore } from '@/stores/';
import { Relation, FieldRaw, Field } from '@/types';
import { merge } from 'lodash';
import { merge, orderBy } from 'lodash';
import { nanoid } from 'nanoid';
import { unexpectedError } from '@/utils/unexpected-error';
@@ -221,7 +221,10 @@ export const useFieldsStore = createStore({
return primaryKeyField;
},
getFieldsForCollection(collection: string): Field[] {
return this.state.fields.filter((field) => field.collection === collection);
return orderBy(
this.state.fields.filter((field) => field.collection === collection),
(collection) => (collection.meta?.sort ? Number(collection.meta?.sort) : null)
);
},
getFieldsForCollectionAlphabetical(collection: string): Field[] {
return this.getFieldsForCollection(collection).sort((a: Field, b: Field) => {