useObjectAttributesScreen.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. return screens.value[screen].reduce(
  19. (screenAttributes: ObjectManagerFrontendAttribute[], attributeName) => {
  20. screenAttributes.push(
  21. attributesLookup.value.get(
  22. attributeName,
  23. ) as ObjectManagerFrontendAttribute,
  24. )
  25. return screenAttributes
  26. },
  27. [],
  28. )
  29. }
  30. const screenAttributes = computed(() => {
  31. return getScreenAttributes(
  32. screen,
  33. objectAttributes.screens,
  34. objectAttributes.attributesLookup,
  35. )
  36. })
  37. return {
  38. screenAttributes,
  39. }
  40. }