TicketSidebarAttachment.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { computed, watch } from 'vue'
  4. import { useArticleContext } from '#desktop/pages/ticket/composables/useArticleContext.ts'
  5. import {
  6. type TicketSidebarProps,
  7. type TicketSidebarEmits,
  8. TicketSidebarButtonBadgeType,
  9. type TicketSidebarButtonBadgeDetails,
  10. } from '#desktop/pages/ticket/types/sidebar.ts'
  11. import TicketSidebarWrapper from '../TicketSidebarWrapper.vue'
  12. import TicketSidebarAttachmentContent from './TicketSidebarAttachmentContent.vue'
  13. import { useTicketAttachments } from './useTicketAttachments.ts'
  14. defineProps<TicketSidebarProps>()
  15. const emit = defineEmits<TicketSidebarEmits>()
  16. const { ticketAttachments, ticketAttachmentsQuery, loading } =
  17. useTicketAttachments()
  18. const { context: contextArticle } = useArticleContext()
  19. watch(contextArticle.articles, (_, oldValue) => {
  20. if (oldValue === undefined) {
  21. return
  22. }
  23. ticketAttachmentsQuery.refetch()
  24. })
  25. watch(ticketAttachments, (newValue) => {
  26. if (newValue.length === 0) {
  27. emit('hide')
  28. return
  29. }
  30. emit('show')
  31. })
  32. const badge = computed<TicketSidebarButtonBadgeDetails | undefined>(() => {
  33. const label = __('Attachments')
  34. return {
  35. type: TicketSidebarButtonBadgeType.Info,
  36. value: ticketAttachments.value.length,
  37. label,
  38. }
  39. })
  40. </script>
  41. <template>
  42. <TicketSidebarWrapper
  43. :key="sidebar"
  44. :sidebar="sidebar"
  45. :sidebar-plugin="sidebarPlugin"
  46. :selected="selected"
  47. :badge="badge"
  48. >
  49. <TicketSidebarAttachmentContent
  50. :context="context"
  51. :sidebar-plugin="sidebarPlugin"
  52. :ticket-attachments="ticketAttachments"
  53. :loading="loading"
  54. />
  55. </TicketSidebarWrapper>
  56. </template>