From 6b9269eb2d6326efdd663c7a576fb24f752635b2 Mon Sep 17 00:00:00 2001 From: Dave Richer Date: Tue, 9 Apr 2024 16:32:26 -0400 Subject: [PATCH] - Progress Signed-off-by: Dave Richer --- .prettierrc.js | 39 -------------- .../job-lines-expander.component.jsx | 2 +- .../task-list/task-list.container.jsx | 36 +++---------- .../task-upsert-modal.container.jsx | 21 ++++---- client/src/graphql/tasks.queries.js | 54 +++---------------- .../jobs-detail.page.component.jsx | 14 +---- .../src/pages/tasks/allTasksPageContainer.jsx | 4 +- .../src/pages/tasks/tasks.page.component.jsx | 4 +- 8 files changed, 29 insertions(+), 145 deletions(-) diff --git a/.prettierrc.js b/.prettierrc.js index 509834503..244a1b8e1 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -1,21 +1,3 @@ -// Original Version -// exports.default = { -// printWidth: 120, -// useTabs: false, -// tabWidth: 2, -// trailingComma: 'es5', -// semi: true, -// singleQuote: false, -// bracketSpacing: true, -// arrowParens: 'always', -// jsxSingleQuote: false, -// bracketSameLine: false, -// endOfLine: 'lf', -// importOrder: ['^@core/(.*)$', '^@server/(.*)$', '^@ui/(.*)$', '^[./]'], -// importOrderSeparation: true, -// importOrderSortSpecifiers: true, -// }; - // Modified Version (Works with current Changeset, minus files modified recently) const config = { printWidth: 120, @@ -35,24 +17,3 @@ const config = { }; module.exports = config; - -// The warnings you're seeing are because the options importOrder, importOrderSeparation, and importOrderSortSpecifiers are not recognized by Prettier. These options are specific to the @trivago/prettier-plugin-sort-imports plugin, which you have removed from your Prettier configuration. To resolve these warnings, you should remove these options from your .prettierrc.js file. Here's how your updated .prettierrc.js file should look: - -// const config = { -// printWidth: 120, -// useTabs: false, -// tabWidth: 2, -// trailingComma: "es5", -// semi: true, -// singleQuote: true, -// bracketSpacing: true, -// arrowParens: "always", -// jsxSingleQuote: false, -// bracketSameLine: false, -// endOfLine: "lf", -// importOrder: ["^@core/(.*)$", "^@server/(.*)$", "^@ui/(.*)$", "^[./]"], -// importOrderSeparation: true, -// importOrderSortSpecifiers: true -// }; -// -// module.exports = config; diff --git a/client/src/components/job-detail-lines/job-lines-expander.component.jsx b/client/src/components/job-detail-lines/job-lines-expander.component.jsx index b6bba803e..8253986c4 100644 --- a/client/src/components/job-detail-lines/job-lines-expander.component.jsx +++ b/client/src/components/job-detail-lines/job-lines-expander.component.jsx @@ -138,7 +138,7 @@ export function JobLinesExpander({ jobline, jobid, bodyshop, currentUser }) { parentJobId={jobid} relationshipType={"joblineid"} relationshipId={jobline.id} - query={QUERY_JOBLINE_TASKS_PAGINATED} + query={{ QUERY_JOBLINE_TASKS_PAGINATED }} titleTranslation="tasks.titles.job_tasks" /> diff --git a/client/src/components/task-list/task-list.container.jsx b/client/src/components/task-list/task-list.container.jsx index 078f1e533..bb4c10b25 100644 --- a/client/src/components/task-list/task-list.container.jsx +++ b/client/src/components/task-list/task-list.container.jsx @@ -4,7 +4,7 @@ import { useMutation, useQuery } from "@apollo/client"; import { MUTATION_TOGGLE_TASK_COMPLETED, MUTATION_TOGGLE_TASK_DELETED } from "../../graphql/tasks.queries.js"; import { pageLimit } from "../../utils/config.js"; import AlertComponent from "../alert/alert.component.jsx"; -import React, { useEffect } from "react"; +import React from "react"; import TaskListComponent from "./task-list.component.jsx"; import { notification } from "antd"; import { useTranslation } from "react-i18next"; @@ -27,7 +27,7 @@ export default function TaskListContainer({ const searchParams = queryString.parse(useLocation().search); const { page, sortcolumn, sortorder, deleted, completed, mine } = searchParams; const dispatch = useDispatch(); - const { loading, error, data, refetch } = useQuery(query, { + const { loading, error, data, refetch } = useQuery(query[Object.keys(query)[0]], { fetchPolicy: "network-only", nextFetchPolicy: "network-only", variables: { @@ -46,21 +46,6 @@ export default function TaskListContainer({ } }); - /** - * Refetch tasks when a task is updated - */ - useEffect(() => { - const handleTaskUpdated = async (event) => { - await refetch().catch((e) => `Something went wrong fetching tasks: ${e.message || ""}`); - }; - window.addEventListener("taskUpdated", handleTaskUpdated); - - // Clean up the event listener when the component is unmounted. - return () => { - window.removeEventListener("taskUpdated", handleTaskUpdated); - }; - }, [refetch]); - /** * Toggle task completed mutation */ @@ -80,7 +65,8 @@ export default function TaskListContainer({ id: id, completed: !currentStatus, completed_at: completed_at - } + }, + refetchQueries: [Object.keys(query)[0], "GET_JOB_BY_PK"] }); if (!toggledTask.errors) { @@ -95,11 +81,6 @@ export default function TaskListContainer({ ); } - window.dispatchEvent( - new CustomEvent("taskUpdated", { - detail: { message: "A task has been completed." } - }) - ); notification["success"]({ message: t("tasks.successes.completed") }); @@ -130,7 +111,8 @@ export default function TaskListContainer({ id: id, deleted: !currentStatus, deleted_at: deleted_at - } + }, + refetchQueries: [Object.keys(query)[0], "GET_JOB_BY_PK"] }); if (!toggledTask.errors) { dispatch( @@ -144,16 +126,10 @@ export default function TaskListContainer({ ); } - window.dispatchEvent( - new CustomEvent("taskUpdated", { - detail: { message: "A task has been deleted." } - }) - ); notification["success"]({ message: t("tasks.successes.deleted") }); } catch (err) { - console.dir(err); notification["error"]({ message: t("tasks.failures.deleted") }); diff --git a/client/src/components/task-upsert-modal/task-upsert-modal.container.jsx b/client/src/components/task-upsert-modal/task-upsert-modal.container.jsx index 89e88c7d8..dcf992b09 100644 --- a/client/src/components/task-upsert-modal/task-upsert-modal.container.jsx +++ b/client/src/components/task-upsert-modal/task-upsert-modal.container.jsx @@ -154,12 +154,6 @@ export function TaskUpsertModalContainer({ bodyshop, currentUser, taskUpsert, to ); } - window.dispatchEvent( - new CustomEvent("taskUpdated", { - detail: { message: "A task has been created or edited." } - }) - ); - notification["success"]({ message: t("tasks.successes.updated") }); @@ -179,6 +173,15 @@ export function TaskUpsertModalContainer({ bodyshop, currentUser, taskUpsert, to bodyshopid: bodyshop.id } ] + }, + update(cache, { data }) { + cache.modify({ + fields: { + tasks(cached) { + return [...data?.insert_tasks?.returning, ...cached]; + } + } + }); } }); @@ -222,12 +225,6 @@ export function TaskUpsertModalContainer({ bodyshop, currentUser, taskUpsert, to console.error(`Something went wrong sending email to Assigned party on Task edit. ${e.message || ""}`) ); - window.dispatchEvent( - new CustomEvent("taskUpdated", { - detail: { message: "A task has been created or edited." } - }) - ); - notification["success"]({ message: t("tasks.successes.created") }); diff --git a/client/src/graphql/tasks.queries.js b/client/src/graphql/tasks.queries.js index deb3d0f76..d06bf0717 100644 --- a/client/src/graphql/tasks.queries.js +++ b/client/src/graphql/tasks.queries.js @@ -327,13 +327,10 @@ export const QUERY_MY_TASKS_PAGINATED = gql` * @type {DocumentNode} */ export const MUTATION_TOGGLE_TASK_COMPLETED = gql` + ${PARTIAL_TASK_FIELDS} mutation MUTATION_TOGGLE_TASK_COMPLETED($id: uuid!, $completed: Boolean!, $completed_at: timestamptz) { update_tasks_by_pk(pk_columns: { id: $id }, _set: { completed: $completed, completed_at: $completed_at }) { - id - title - completed - completed_at - jobid + ...TaskFields } } `; @@ -343,13 +340,10 @@ export const MUTATION_TOGGLE_TASK_COMPLETED = gql` * @type {DocumentNode} */ export const MUTATION_TOGGLE_TASK_DELETED = gql` + ${PARTIAL_TASK_FIELDS} mutation MUTATION_TOGGLE_TASK_DELETED($id: uuid!, $deleted: Boolean!, $deleted_at: timestamptz) { update_tasks_by_pk(pk_columns: { id: $id }, _set: { deleted: $deleted, deleted_at: $deleted_at }) { - id - title - deleted - deleted_at - jobid + ...TaskFields } } `; @@ -359,27 +353,11 @@ export const MUTATION_TOGGLE_TASK_DELETED = gql` * @type {DocumentNode} */ export const MUTATION_INSERT_NEW_TASK = gql` + ${PARTIAL_TASK_FIELDS} mutation MUTATION_INSERT_NEW_TASK($taskInput: [tasks_insert_input!]!) { insert_tasks(objects: $taskInput) { returning { - id - created_at - updated_at - title - description - deleted - deleted_at - due_date - created_by - assigned_to - completed - completed_at - remind_at - priority - jobid - joblineid - partsorderid - billid + ...TaskFields } } } @@ -390,27 +368,11 @@ export const MUTATION_INSERT_NEW_TASK = gql` * @type {DocumentNode} */ export const MUTATION_UPDATE_TASK = gql` + ${PARTIAL_TASK_FIELDS} mutation MUTATION_UPDATE_TASK($taskId: uuid!, $task: tasks_set_input!) { update_tasks(where: { id: { _eq: $taskId } }, _set: $task) { returning { - id - created_at - updated_at - title - description - deleted - deleted_at - due_date - created_by - assigned_to - completed - completed_at - remind_at - priority - jobid - joblineid - partsorderid - billid + ...TaskFields } } } diff --git a/client/src/pages/jobs-detail/jobs-detail.page.component.jsx b/client/src/pages/jobs-detail/jobs-detail.page.component.jsx index 6f0abaf23..5162e1621 100644 --- a/client/src/pages/jobs-detail/jobs-detail.page.component.jsx +++ b/client/src/pages/jobs-detail/jobs-detail.page.component.jsx @@ -104,18 +104,6 @@ export function JobsDetailPage({ form.resetFields(); }, [form, job]); - useEffect(() => { - const handleTaskUpdated = async (event) => { - await refetch().catch((e) => `Something went wrong fetching tasks: ${e.message || ""}`); - }; - window.addEventListener("taskUpdated", handleTaskUpdated); - - // Clean up the event listener when the component is unmounted. - return () => { - window.removeEventListener("taskUpdated", handleTaskUpdated); - }; - }, [refetch]); - //useKeyboardSaveShortcut(form.submit); const handleFinish = async (values) => { @@ -410,7 +398,7 @@ export function JobsDetailPage({ bodyshop={bodyshop} relationshipType={"jobid"} relationshipId={job.id} - query={QUERY_JOB_TASKS_PAGINATED} + query={{ QUERY_JOB_TASKS_PAGINATED }} titleTranslation="tasks.titles.job_tasks" showRo={false} /> diff --git a/client/src/pages/tasks/allTasksPageContainer.jsx b/client/src/pages/tasks/allTasksPageContainer.jsx index 7533ffc3e..e1855da71 100644 --- a/client/src/pages/tasks/allTasksPageContainer.jsx +++ b/client/src/pages/tasks/allTasksPageContainer.jsx @@ -23,7 +23,7 @@ const mapDispatchToProps = (dispatch) => ({ setTaskUpsertContext: (context) => dispatch(setModalContext({ context, modal: "taskUpsert" })) }); -export function MyTasksPageContainer({ +export function AllTasksPageContainer({ bodyshop, currentUser, setBreadcrumbs, @@ -67,4 +67,4 @@ export function MyTasksPageContainer({ return ; } -export default connect(mapStateToProps, mapDispatchToProps)(MyTasksPageContainer); +export default connect(mapStateToProps, mapDispatchToProps)(AllTasksPageContainer); diff --git a/client/src/pages/tasks/tasks.page.component.jsx b/client/src/pages/tasks/tasks.page.component.jsx index 522cb3778..dc30cef67 100644 --- a/client/src/pages/tasks/tasks.page.component.jsx +++ b/client/src/pages/tasks/tasks.page.component.jsx @@ -11,7 +11,7 @@ export default function TasksPageComponent({ bodyshop, currentUser, type }) { onlyMine={true} relationshipId={currentUser.email} relationshipType={"user"} - query={QUERY_MY_TASKS_PAGINATED} + query={{ QUERY_MY_TASKS_PAGINATED }} bodyshop={bodyshop} titleTranslation={"tasks.titles.my_tasks"} currentUser={currentUser} @@ -20,7 +20,7 @@ export default function TasksPageComponent({ bodyshop, currentUser, type }) { case taskPageTypes.ALL_TASKS: return (