From 66c51a4be54826b15a65dfa609c392948f9239f8 Mon Sep 17 00:00:00 2001 From: Dave Richer Date: Thu, 31 Jul 2025 15:46:34 -0400 Subject: [PATCH] release/2025-08-01 - Fix Notes via refetch queries, cache manipulation too complex --- .../job-notes-pin-toggle.component.jsx | 33 ++---------------- .../note-upsert-modal.container.jsx | 34 +++---------------- 2 files changed, 8 insertions(+), 59 deletions(-) diff --git a/client/src/components/job-notes-pin-toggle/job-notes-pin-toggle.component.jsx b/client/src/components/job-notes-pin-toggle/job-notes-pin-toggle.component.jsx index a54bac4a4..7d503c89d 100644 --- a/client/src/components/job-notes-pin-toggle/job-notes-pin-toggle.component.jsx +++ b/client/src/components/job-notes-pin-toggle/job-notes-pin-toggle.component.jsx @@ -1,44 +1,17 @@ import { PushpinFilled, PushpinOutlined } from "@ant-design/icons"; import { useMutation } from "@apollo/client"; -import { GET_JOB_BY_PK } from "../../graphql/jobs.queries"; import { UPDATE_NOTE } from "../../graphql/notes.queries"; function JobNotesPinToggle({ note }) { - const [updateNote] = useMutation(UPDATE_NOTE, { - update(cache, { data: { updateNote: updatedNote } }) { - try { - const existingJob = cache.readQuery({ - query: GET_JOB_BY_PK, - variables: { id: note.jobid } - }); - - if (existingJob) { - cache.writeQuery({ - query: GET_JOB_BY_PK, - variables: { id: note.jobid }, - data: { - ...existingJob, - job: { - ...existingJob.job, - notes: updatedNote.pinned - ? [updatedNote, ...existingJob.job.notes] - : existingJob.job.notes.filter((n) => n.id !== updatedNote.id) - } - } - }); - } - } catch (error) { - // Query not yet executed is most likely. No logging as this isn't a fatal error. - } - } - }); + const [updateNote] = useMutation(UPDATE_NOTE); const handlePinToggle = () => { updateNote({ variables: { noteId: note.id, note: { pinned: !note.pinned } - } + }, + refetchQueries: ["GET_JOB_BY_PK", "QUERY_JOB_CARD_DETAILS", "QUERY_PARTS_QUEUE_CARD_DETAILS"] }); }; diff --git a/client/src/components/note-upsert-modal/note-upsert-modal.container.jsx b/client/src/components/note-upsert-modal/note-upsert-modal.container.jsx index b5b8cb54e..8f3e33d69 100644 --- a/client/src/components/note-upsert-modal/note-upsert-modal.container.jsx +++ b/client/src/components/note-upsert-modal/note-upsert-modal.container.jsx @@ -1,4 +1,4 @@ -import { useMutation } from "@apollo/client"; +import { useApolloClient, useMutation } from "@apollo/client"; import { Form, Modal } from "antd"; import { useEffect } from "react"; import { useTranslation } from "react-i18next"; @@ -43,6 +43,8 @@ export function NoteUpsertModalContainer({ currentUser, noteUpsertModal, toggleM const [form] = Form.useForm(); + const { client } = useApolloClient(); + useEffect(() => { //Required to prevent infinite looping. if (existingNote && open) { @@ -67,34 +69,8 @@ export function NoteUpsertModalContainer({ currentUser, noteUpsertModal, toggleM noteId: existingNote.id, note: values }, - update(cache, { data: { updateNote: updatedNote } }) { - try { - const existingJob = cache.readQuery({ - query: GET_JOB_BY_PK, - variables: { id: jobId } - }); - - if (existingJob) { - cache.writeQuery({ - query: GET_JOB_BY_PK, - variables: { id: jobId }, - data: { - ...existingJob, - job: { - ...existingJob.job, - notes: updatedNote.pinned - ? [updatedNote, ...existingJob.job.notes] - : existingJob.job.notes.filter((n) => n.id !== updatedNote.id) - } - } - }); - } - } catch (error) { - // Cache miss is okay, query hasn't been executed yet - console.log("Cache miss for GET_JOB_BY_PK"); - } - } - }).then((r) => { + refetchQueries: ["GET_JOB_BY_PK", "QUERY_JOB_CARD_DETAILS", "QUERY_PARTS_QUEUE_CARD_DETAILS"] + }).then(() => { notification["success"]({ message: t("notes.successes.updated") });