useObjectAttributesScreen.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { computed, type ComputedRef } from 'vue'
  3. import type {
  4. EnumObjectManagerObjects,
  5. ObjectManagerFrontendAttribute,
  6. } from '#shared/graphql/types.ts'
  7. import { useObjectAttributes } from './useObjectAttributes.ts'
  8. export const useObjectAttributesScreen = (
  9. object: EnumObjectManagerObjects,
  10. screen: string,
  11. ) => {
  12. const objectAttributes = useObjectAttributes(object)
  13. const getScreenAttributes = (
  14. screen: string,
  15. screens: ComputedRef<Record<string, string[]>>,
  16. attributesLookup: ComputedRef<Map<string, ObjectManagerFrontendAttribute>>,
  17. ) => {
  18. if (!screens.value[screen]) return []
  19. return screens.value[screen].reduce(
  20. (screenAttributes: ObjectManagerFrontendAttribute[], attributeName) => {
  21. screenAttributes.push(
  22. attributesLookup.value.get(
  23. attributeName,
  24. ) as ObjectManagerFrontendAttribute,
  25. )
  26. return screenAttributes
  27. },
  28. [],
  29. )
  30. }
  31. const screenAttributes = computed(() => {
  32. return getScreenAttributes(
  33. screen,
  34. objectAttributes.screens,
  35. objectAttributes.attributesLookup,
  36. )
  37. })
  38. return {
  39. screenAttributes,
  40. }
  41. }