Browse Source

Feature: Desktop view - Fixed small problem with switching tickets and loading of checklists.

Co-authored-by: Dominik Klein <dk@zammad.com>
Co-authored-by: Florian Liebe <fl@zammad.com>
Dominik Klein 6 months ago
parent
commit
905dbce223

+ 2 - 3
app/frontend/apps/desktop/pages/ticket/components/TicketSidebar/TicketSidebarChecklist/__tests__/TicketSidebarChecklistContent.spec.ts

@@ -90,9 +90,7 @@ const checklistItemsMock: Partial<ChecklistItem>[] = [
   },
 ]
 
-/**
- * partialTicketChecklist - Overrides the default checklist values if set to null, checklist will be empty
- * */
+// Overrides the default checklist values if set to null, checklist will be empty
 const mockChecklistUpdateSubscription = async (
   partialTicketChecklist: Partial<
     TicketChecklistUpdatesSubscription['ticketChecklistUpdates']['ticketChecklist']
@@ -102,6 +100,7 @@ const mockChecklistUpdateSubscription = async (
     await getTicketChecklistUpdatesSubscriptionHandler().trigger({
       ticketChecklistUpdates: {
         ticketChecklist: null,
+        removedTicketChecklist: true,
       },
     })
     return

+ 8 - 3
app/frontend/apps/desktop/pages/ticket/components/TicketSidebar/TicketSidebarChecklist/useTicketChecklist.ts

@@ -60,10 +60,15 @@ export const useTicketChecklist = (
       ticketId: ticketId.value as string,
     },
     updateQuery: (prev, { subscriptionData }) => {
-      if (!subscriptionData.data.ticketChecklistUpdates)
+      if (
+        !subscriptionData.data.ticketChecklistUpdates.ticketChecklist &&
+        !subscriptionData.data.ticketChecklistUpdates.removedTicketChecklist
+      ) {
         return null as unknown as TicketChecklistQuery
+      }
 
-      const { ticketChecklist } = subscriptionData.data.ticketChecklistUpdates
+      const { ticketChecklist, removedTicketChecklist } =
+        subscriptionData.data.ticketChecklistUpdates
 
       if (
         checklist.value?.items?.length &&
@@ -77,7 +82,7 @@ export const useTicketChecklist = (
 
       // When a complete checklist was removed, we need to update the result.
       if (
-        ticketChecklist === null ||
+        removedTicketChecklist ||
         (prev.ticketChecklist === null && ticketChecklist !== null)
       ) {
         return {

+ 1 - 0
app/frontend/apps/desktop/pages/ticket/graphql/subscriptions/ticketChecklistUpdates.api.ts

@@ -30,6 +30,7 @@ export const TicketChecklistUpdatesDocument = gql`
         ticketAccess
       }
     }
+    removedTicketChecklist
   }
 }
     `;

+ 1 - 0
app/frontend/apps/desktop/pages/ticket/graphql/subscriptions/ticketChecklistUpdates.graphql

@@ -22,5 +22,6 @@ subscription ticketChecklistUpdates($ticketId: ID!) {
         ticketAccess
       }
     }
+    removedTicketChecklist
   }
 }

+ 3 - 1
app/frontend/shared/graphql/types.ts

@@ -3461,6 +3461,8 @@ export type TicketChecklistTitleUpdatePayload = {
 /** Autogenerated return type of TicketChecklistUpdates. */
 export type TicketChecklistUpdatesPayload = {
   __typename?: 'TicketChecklistUpdatesPayload';
+  /** Ticket checklist was removed from ticket */
+  removedTicketChecklist?: Maybe<Scalars['Boolean']['output']>;
   /** Ticket checklist */
   ticketChecklist?: Maybe<Checklist>;
 };
@@ -5173,7 +5175,7 @@ export type TicketChecklistUpdatesSubscriptionVariables = Exact<{
 }>;
 
 
-export type TicketChecklistUpdatesSubscription = { __typename?: 'Subscriptions', ticketChecklistUpdates: { __typename?: 'TicketChecklistUpdatesPayload', ticketChecklist?: { __typename?: 'Checklist', id: string, name?: string | null, completed: boolean, incomplete: number, items: Array<{ __typename?: 'ChecklistItem', id: string, text: string, checked: boolean, ticketAccess?: EnumChecklistItemTicketAccess | null, ticket?: { __typename?: 'Ticket', id: string, internalId: number, number: string, title: string, stateColorCode: EnumTicketStateColorCode, state: { __typename?: 'TicketState', name: string } } | null }> } | null } };
+export type TicketChecklistUpdatesSubscription = { __typename?: 'Subscriptions', ticketChecklistUpdates: { __typename?: 'TicketChecklistUpdatesPayload', removedTicketChecklist?: boolean | null, ticketChecklist?: { __typename?: 'Checklist', id: string, name?: string | null, completed: boolean, incomplete: number, items: Array<{ __typename?: 'ChecklistItem', id: string, text: string, checked: boolean, ticketAccess?: EnumChecklistItemTicketAccess | null, ticket?: { __typename?: 'Ticket', id: string, internalId: number, number: string, title: string, stateColorCode: EnumTicketStateColorCode, state: { __typename?: 'TicketState', name: string } } | null }> } | null } };
 
 export type OrganizationUpdateMutationVariables = Exact<{
   id: Scalars['ID']['input'];

+ 3 - 0
app/graphql/gql/subscriptions/ticket/checklist_updates.rb

@@ -8,12 +8,15 @@ module Gql::Subscriptions
     argument :ticket_id, GraphQL::Types::ID, description: 'Ticket identifier'
 
     field :ticket_checklist, Gql::Types::ChecklistType, description: 'Ticket checklist'
+    field :removed_ticket_checklist, Boolean, description: 'Ticket checklist was removed from ticket'
 
     def authorized?(ticket_id:)
       context.current_user.permissions?('ticket.agent') && Gql::ZammadSchema.authorized_object_from_id(ticket_id, type: ::Ticket, user: context.current_user)
     end
 
     def update(ticket_id:)
+      return { removed_ticket_checklist: true } if object.nil?
+
       { ticket_checklist: object }
     end
   end

+ 14 - 0
app/graphql/graphql_introspection.json

@@ -20452,6 +20452,20 @@
           "name": "TicketChecklistUpdatesPayload",
           "description": "Autogenerated return type of TicketChecklistUpdates.",
           "fields": [
+            {
+              "name": "removedTicketChecklist",
+              "description": "Ticket checklist was removed from ticket",
+              "args": [
+
+              ],
+              "type": {
+                "kind": "SCALAR",
+                "name": "Boolean",
+                "ofType": null
+              },
+              "isDeprecated": false,
+              "deprecationReason": null
+            },
             {
               "name": "ticketChecklist",
               "description": "Ticket checklist",

+ 2 - 1
spec/graphql/gql/subscriptions/ticket/checklist_updates_spec.rb

@@ -34,6 +34,7 @@ RSpec.describe Gql::Subscriptions::Ticket::ChecklistUpdates, type: :graphql do
               ticketAccess
             }
           }
+          removedTicketChecklist
         }
       }
     QUERY
@@ -89,7 +90,7 @@ RSpec.describe Gql::Subscriptions::Ticket::ChecklistUpdates, type: :graphql do
 
         result = mock_channel.mock_broadcasted_messages.first[:result]['data']['ticketChecklistUpdates']
 
-        expect(result).to include('ticketChecklist' => nil)
+        expect(result).to include('ticketChecklist' => nil, 'removedTicketChecklist' => true)
       end
 
       it 'triggers after checklist item create' do