mirror of
https://github.com/directus/directus.git
synced 2026-01-30 23:08:15 -05:00
fix running useFieldTree to often (#7543)
This commit is contained in:
@@ -3,7 +3,7 @@ import { Relation } from '@/types';
|
||||
import { Field } from '@directus/shared/types';
|
||||
import { getRelationType } from '@/utils/get-relation-type';
|
||||
import { cloneDeep, orderBy } from 'lodash';
|
||||
import { computed, Ref, ComputedRef } from 'vue';
|
||||
import { Ref, ref, watch } from 'vue';
|
||||
|
||||
type FieldOption = { name: string; field: string; key: string; children?: FieldOption[]; group?: string };
|
||||
|
||||
@@ -14,15 +14,24 @@ export default function useFieldTree(
|
||||
inject?: Ref<{ fields: Field[]; relations: Relation[] } | null>,
|
||||
filter: (field: Field) => boolean = () => true,
|
||||
depth = 3
|
||||
): { tree: ComputedRef<FieldOption[]> } {
|
||||
): { tree: Ref<FieldOption[]> } {
|
||||
const fieldsStore = useFieldsStore();
|
||||
const collectionsStore = useCollectionsStore();
|
||||
const relationsStore = useRelationsStore();
|
||||
|
||||
const tree = computed(() => {
|
||||
if (!collection.value) return [];
|
||||
return parseLevel(collection.value, null);
|
||||
});
|
||||
const tree = ref<FieldOption[]>([]);
|
||||
|
||||
watch(
|
||||
collection,
|
||||
(newCollection) => {
|
||||
if (!newCollection) {
|
||||
tree.value = [];
|
||||
return;
|
||||
}
|
||||
tree.value = parseLevel(newCollection, null);
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
return { tree };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user