IO-3292 Add note pinning functionality.
This commit is contained in:
@@ -23,17 +23,22 @@ export function NoteUpsertModalComponent({ form, noteUpsertModal }) {
|
||||
return (
|
||||
<>
|
||||
<Row gutter={[16, 16]}>
|
||||
<Col span={8}>
|
||||
<Col span={6}>
|
||||
<Form.Item label={t("notes.fields.critical")} name="critical" valuePropName="checked">
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Col span={6}>
|
||||
<Form.Item label={t("notes.fields.private")} name="private" valuePropName="checked">
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<Col span={6}>
|
||||
<Form.Item label={t("notes.fields.pinned")} name="pinned" valuePropName="checked">
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<Form.Item label={t("notes.fields.type")} name="type" initialValue="general">
|
||||
<Select
|
||||
options={[
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { useMutation } from "@apollo/client";
|
||||
import { Form, Modal } from "antd";
|
||||
import React, { useEffect } from "react";
|
||||
import { useEffect } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { useNotification } from "../../contexts/Notifications/notificationContext.jsx";
|
||||
import { logImEXEvent } from "../../firebase/firebase.utils";
|
||||
import { GET_JOB_BY_PK } from "../../graphql/jobs.queries.js";
|
||||
import { INSERT_NEW_NOTE, UPDATE_NOTE } from "../../graphql/notes.queries";
|
||||
import { insertAuditTrail } from "../../redux/application/application.actions";
|
||||
import { toggleModalVisible } from "../../redux/modals/modals.actions";
|
||||
@@ -12,7 +14,6 @@ import { selectNoteUpsert } from "../../redux/modals/modals.selectors";
|
||||
import { selectCurrentUser } from "../../redux/user/user.selectors";
|
||||
import AuditTrailMapping from "../../utils/AuditTrailMappings";
|
||||
import NoteUpsertModalComponent from "./note-upsert-modal.component";
|
||||
import { useNotification } from "../../contexts/Notifications/notificationContext.jsx";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
currentUser: selectCurrentUser,
|
||||
@@ -65,6 +66,33 @@ export function NoteUpsertModalContainer({ currentUser, noteUpsertModal, toggleM
|
||||
variables: {
|
||||
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) => {
|
||||
notification["success"]({
|
||||
@@ -86,6 +114,33 @@ export function NoteUpsertModalContainer({ currentUser, noteUpsertModal, toggleM
|
||||
variables: {
|
||||
noteInput: [{ ...values, jobid: jobId, created_by: currentUser.email }]
|
||||
},
|
||||
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");
|
||||
}
|
||||
},
|
||||
refetchQueries: ["QUERY_NOTES_BY_JOB_PK"]
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user