Merge remote-tracking branch 'origin/release/2025-08-01' into feature/IO-3255-simplified-part-management
This commit is contained in:
@@ -1,44 +1,17 @@
|
|||||||
import { PushpinFilled, PushpinOutlined } from "@ant-design/icons";
|
import { PushpinFilled, PushpinOutlined } from "@ant-design/icons";
|
||||||
import { useMutation } from "@apollo/client";
|
import { useMutation } from "@apollo/client";
|
||||||
import { GET_JOB_BY_PK } from "../../graphql/jobs.queries";
|
|
||||||
import { UPDATE_NOTE } from "../../graphql/notes.queries";
|
import { UPDATE_NOTE } from "../../graphql/notes.queries";
|
||||||
|
|
||||||
function JobNotesPinToggle({ note }) {
|
function JobNotesPinToggle({ note }) {
|
||||||
const [updateNote] = useMutation(UPDATE_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 handlePinToggle = () => {
|
const handlePinToggle = () => {
|
||||||
updateNote({
|
updateNote({
|
||||||
variables: {
|
variables: {
|
||||||
noteId: note.id,
|
noteId: note.id,
|
||||||
note: { pinned: !note.pinned }
|
note: { pinned: !note.pinned }
|
||||||
}
|
},
|
||||||
|
refetchQueries: ["GET_JOB_BY_PK", "QUERY_JOB_CARD_DETAILS", "QUERY_PARTS_QUEUE_CARD_DETAILS"]
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useMutation } from "@apollo/client";
|
import { useApolloClient, useMutation } from "@apollo/client";
|
||||||
import { Form, Modal } from "antd";
|
import { Form, Modal } from "antd";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
@@ -43,6 +43,8 @@ export function NoteUpsertModalContainer({ currentUser, noteUpsertModal, toggleM
|
|||||||
|
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
|
|
||||||
|
const { client } = useApolloClient();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
//Required to prevent infinite looping.
|
//Required to prevent infinite looping.
|
||||||
if (existingNote && open) {
|
if (existingNote && open) {
|
||||||
@@ -67,34 +69,8 @@ export function NoteUpsertModalContainer({ currentUser, noteUpsertModal, toggleM
|
|||||||
noteId: existingNote.id,
|
noteId: existingNote.id,
|
||||||
note: values
|
note: values
|
||||||
},
|
},
|
||||||
update(cache, { data: { updateNote: updatedNote } }) {
|
refetchQueries: ["GET_JOB_BY_PK", "QUERY_JOB_CARD_DETAILS", "QUERY_PARTS_QUEUE_CARD_DETAILS"]
|
||||||
try {
|
}).then(() => {
|
||||||
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) => {
|
|
||||||
notification["success"]({
|
notification["success"]({
|
||||||
message: t("notes.successes.updated")
|
message: t("notes.successes.updated")
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user