mirror of
https://github.com/directus/directus.git
synced 2026-02-03 23:25:05 -05:00
Use lodash for field sorting
This commit is contained in:
@@ -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 } from 'lodash';
|
||||
import { clone, orderBy } from 'lodash';
|
||||
|
||||
export default function useFormFields(fields: Ref<Field[]>) {
|
||||
const interfaces = getInterfaces();
|
||||
@@ -14,15 +14,7 @@ export default function useFormFields(fields: Ref<Field[]>) {
|
||||
let formFields = clone(fields.value);
|
||||
|
||||
// Sort the fields on the sort column value
|
||||
formFields = formFields.sort((a, b) => {
|
||||
const aSort = a.meta?.sort || null;
|
||||
const bSort = b.meta?.sort || null;
|
||||
|
||||
if (aSort === bSort) return 0;
|
||||
if (aSort === null) return 1;
|
||||
if (bSort === null) return -1;
|
||||
return aSort < bSort ? -1 : 1;
|
||||
});
|
||||
formFields = orderBy(formFields, [(o) => o.meta?.sort || null, (o) => o.meta?.id]);
|
||||
|
||||
formFields = formFields.map((field, index) => {
|
||||
if (!field.meta) return field;
|
||||
|
||||
@@ -58,6 +58,7 @@ import { useFieldsStore } from '@/stores/';
|
||||
import FieldSelect from './field-select.vue';
|
||||
import hideDragImage from '@/utils/hide-drag-image';
|
||||
import { i18n } from '@/lang';
|
||||
import { orderBy } from 'lodash';
|
||||
|
||||
type DraggableEvent = {
|
||||
moved?: {
|
||||
@@ -85,15 +86,7 @@ export default defineComponent({
|
||||
const fieldsStore = useFieldsStore();
|
||||
|
||||
const sortedFields = computed(() => {
|
||||
return fields.value.sort((a, b) => {
|
||||
const aSort = a.meta?.sort || null;
|
||||
const bSort = b.meta?.sort || null;
|
||||
|
||||
if (aSort === bSort) return 0;
|
||||
if (aSort === null) return 1;
|
||||
if (bSort === null) return -1;
|
||||
return aSort < bSort ? -1 : 1;
|
||||
});
|
||||
return orderBy(fields.value, [(o) => o.meta?.sort || null, (o) => o.meta?.id]);
|
||||
});
|
||||
|
||||
const addOptions = computed(() => [
|
||||
|
||||
Reference in New Issue
Block a user