useObjectAttributeLoadFormFields.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { computed } from 'vue'
  3. import type { EnumObjectManagerObjects } from '#shared/graphql/types.ts'
  4. import { useObjectAttributes } from './useObjectAttributes.ts'
  5. export const useObjectAttributeLoadFormFields = (
  6. objectAttributeObjects: EnumObjectManagerObjects[],
  7. ) => {
  8. const objectAttributesByObject: Partial<
  9. Record<EnumObjectManagerObjects, ReturnType<typeof useObjectAttributes>>
  10. > = {}
  11. objectAttributeObjects.forEach((object) => {
  12. objectAttributesByObject[object] = useObjectAttributes(object)
  13. })
  14. const objectAttributesLoading = computed(() => {
  15. let loading = false
  16. const usedObjects = Object.keys(
  17. objectAttributesByObject,
  18. ) as EnumObjectManagerObjects[]
  19. usedObjects.forEach((object: EnumObjectManagerObjects) => {
  20. if (
  21. (
  22. objectAttributesByObject[object] as ReturnType<
  23. typeof useObjectAttributes
  24. >
  25. ).formFieldAttributesLookup.value.size === 0
  26. ) {
  27. loading = true
  28. }
  29. })
  30. return loading
  31. })
  32. return {
  33. objectAttributesLoading,
  34. }
  35. }