From 5f8346d66624b43f6745a0ae4a40c6a16c4abb83 Mon Sep 17 00:00:00 2001 From: sdjdd Date: Thu, 16 Nov 2023 14:07:27 +0800 Subject: [PATCH] feat(next/web): patch livequery no object id bug --- .../App/Admin/Tickets/Ticket/timeline-data.ts | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/next/web/src/App/Admin/Tickets/Ticket/timeline-data.ts b/next/web/src/App/Admin/Tickets/Ticket/timeline-data.ts index 73dc6fa56..596ee2d09 100644 --- a/next/web/src/App/Admin/Tickets/Ticket/timeline-data.ts +++ b/next/web/src/App/Admin/Tickets/Ticket/timeline-data.ts @@ -7,6 +7,16 @@ import { ReplySchema } from '@/api/reply'; import { fetchTicketReplies, fetchTicketOpsLogs, OpsLog } from '@/api/ticket'; import { useCurrentRef } from '@/utils/useCurrentRef'; +function patchQueryDecoder(query: any) { + const decoder = query._decoder; + query._decoder = (app: any, data: any, className: string) => { + if (!data.objectId) { + data.objectId = '__objectId__'; + } + return decoder(app, data, className); + }; +} + export function useTicketReplies(ticketId?: string) { const { data, fetchNextPage, refetch } = useInfiniteQuery({ queryKey: ['TicketReplies', ticketId], @@ -49,8 +59,9 @@ export function useTicketReplies(ticketId?: string) { return; } let mounted = true; - const subscription = db - .query('Reply') + const query = db.query('Reply'); + patchQueryDecoder(query); + const subscription = query .where('ticket', '==', db.class('Ticket').object(ticketId)) .subscribe(); subscription.then((s) => { @@ -109,8 +120,9 @@ export function useTicketOpsLogs(ticketId?: string) { return; } let mounted = true; - const subscription = db - .query('OpsLog') + const query = db.query('OpsLog'); + patchQueryDecoder(query); + const subscription = query .where('ticket', '==', db.class('Ticket').object(ticketId)) .subscribe(); subscription.then((s) => {