useObjectAttributesScreen.ts 1.2 KB

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