TicketSidebarSharedDraftStart.vue 2.1 KB

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