useIssueTracker.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { computed, type Ref } from 'vue'
  3. import { EnumTicketExternalReferencesIssueTrackerType } from '#shared/graphql/types.ts'
  4. import type { ExternalReferencesFormValues } from '#desktop/pages/ticket/components/TicketSidebar/TicketSidebarExternalIssueTracker/types.ts'
  5. import {
  6. TicketSidebarButtonBadgeType,
  7. type TicketSidebarContext,
  8. TicketSidebarScreenType,
  9. } from '#desktop/pages/ticket/types/sidebar.ts'
  10. export const useIssueTracker = (
  11. trackerType: EnumTicketExternalReferencesIssueTrackerType,
  12. context: Ref<TicketSidebarContext>,
  13. ) => {
  14. const isTicketEditable = computed(
  15. () => context.value.isTicketEditable?.value ?? true, // True for ticket create screen.
  16. )
  17. const issueLinks = computed(() => {
  18. if (context.value.screenType === TicketSidebarScreenType.TicketCreate)
  19. return (
  20. (context.value.formValues as ExternalReferencesFormValues)
  21. .externalReferences?.[trackerType] || []
  22. )
  23. return context.value.ticket?.value?.externalReferences?.[trackerType] || []
  24. })
  25. const hideSidebar = computed(
  26. () => !issueLinks.value?.length && !isTicketEditable.value,
  27. )
  28. const openIssuesBadge = computed(() =>
  29. issueLinks.value?.length
  30. ? {
  31. label: __('Open Issues'),
  32. type: TicketSidebarButtonBadgeType.Info,
  33. value: issueLinks.value?.length,
  34. }
  35. : undefined,
  36. )
  37. return { hideSidebar, isTicketEditable, issueLinks, openIssuesBadge }
  38. }