TicketSidebarSharedDraftStart.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { computed } from 'vue'
  4. import { useTicketSharedDraftStart } from '#shared/entities/ticket-shared-draft-start/composables/useTicketSharedDraftStart.ts'
  5. import { convertToGraphQLId } from '#shared/graphql/utils.ts'
  6. import {
  7. GraphQLErrorTypes,
  8. type GraphQLHandlerError,
  9. } from '#shared/types/error.ts'
  10. import {
  11. type TicketSidebarProps,
  12. type TicketSidebarEmits,
  13. } from '#desktop/pages/ticket/types/sidebar.ts'
  14. import TicketSidebarWrapper from '../TicketSidebarWrapper.vue'
  15. import TicketSidebarSharedDraftStartContent from './TicketSidebarSharedDraftStartContent.vue'
  16. const props = defineProps<TicketSidebarProps>()
  17. const emit = defineEmits<TicketSidebarEmits>()
  18. const groupId = computed(() =>
  19. convertToGraphQLId('Group', Number(props.context.formValues.group_id)),
  20. )
  21. // Silence query error notification in the frontend in case of unknown errors.
  22. // The query may raise a non-specific error if the group has inactive shared drafts.
  23. // Hide the sidebar in that case.
  24. // FIXME: Check if it's possible to silence the console error too.
  25. const errorCallback = (error: GraphQLHandlerError) => {
  26. if (error.type === GraphQLErrorTypes.UnknownError) {
  27. emit('hide')
  28. return false
  29. }
  30. return true
  31. }
  32. const { sharedDraftStartListQuery, sharedDraftStartList } =
  33. useTicketSharedDraftStart(groupId, errorCallback)
  34. sharedDraftStartListQuery.onResult(({ data }) => {
  35. if (!data?.ticketSharedDraftStartList) return
  36. emit('show')
  37. })
  38. </script>
  39. <template>
  40. <TicketSidebarWrapper
  41. :key="sidebar"
  42. :sidebar="sidebar"
  43. :sidebar-plugin="sidebarPlugin"
  44. :selected="selected"
  45. >
  46. <TicketSidebarSharedDraftStartContent
  47. v-if="sharedDraftStartList"
  48. :context="context"
  49. :sidebar-plugin="sidebarPlugin"
  50. :shared-draft-start-list="sharedDraftStartList"
  51. />
  52. </TicketSidebarWrapper>
  53. </template>