TicketSidebarAttachment.vue 1.9 KB

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