From 42505ad74e6c1327bfe6b56e08eaf7e442f03e03 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Wed, 22 Jan 2020 14:45:10 -0800 Subject: [PATCH] Cleanup database + updates to apollo error handler to check all errors + added hash history to jobs list. --- .../jobs-list/jobs-list.component.jsx | 9 +- client/src/graphql/apollo-error-handling.js | 18 +- client/src/pages/jobs/jobs.page.jsx | 8 +- .../down.yaml | 3 + .../up.yaml | 3 + .../down.yaml | 216 +++++++++++++++++ .../up.yaml | 217 ++++++++++++++++++ .../down.yaml | 216 +++++++++++++++++ .../up.yaml | 212 +++++++++++++++++ .../down.yaml | 214 +++++++++++++++++ .../up.yaml | 210 +++++++++++++++++ .../down.yaml | 216 +++++++++++++++++ .../up.yaml | 212 +++++++++++++++++ .../down.yaml | 7 + .../up.yaml | 3 + .../down.yaml | 6 + .../up.yaml | 3 + .../down.yaml | 6 + .../up.yaml | 3 + .../down.yaml | 6 + .../up.yaml | 3 + .../down.yaml | 7 + .../up.yaml | 3 + .../down.yaml | 6 + .../up.yaml | 6 + 25 files changed, 1803 insertions(+), 10 deletions(-) create mode 100644 hasura/migrations/1579729421561_alter_table_public_jobs_add_column_loss_cat/down.yaml create mode 100644 hasura/migrations/1579729421561_alter_table_public_jobs_add_column_loss_cat/up.yaml create mode 100644 hasura/migrations/1579729438238_update_permission_user_public_table_jobs/down.yaml create mode 100644 hasura/migrations/1579729438238_update_permission_user_public_table_jobs/up.yaml create mode 100644 hasura/migrations/1579729459311_update_permission_user_public_table_jobs/down.yaml create mode 100644 hasura/migrations/1579729459311_update_permission_user_public_table_jobs/up.yaml create mode 100644 hasura/migrations/1579729474321_update_permission_user_public_table_jobs/down.yaml create mode 100644 hasura/migrations/1579729474321_update_permission_user_public_table_jobs/up.yaml create mode 100644 hasura/migrations/1579729492341_update_permission_user_public_table_jobs/down.yaml create mode 100644 hasura/migrations/1579729492341_update_permission_user_public_table_jobs/up.yaml create mode 100644 hasura/migrations/1579729507972_alter_table_public_jobs_drop_column_pit_owner_first_name/down.yaml create mode 100644 hasura/migrations/1579729507972_alter_table_public_jobs_drop_column_pit_owner_first_name/up.yaml create mode 100644 hasura/migrations/1579729524654_alter_table_public_jobs_drop_column_pit_owner_last_name/down.yaml create mode 100644 hasura/migrations/1579729524654_alter_table_public_jobs_drop_column_pit_owner_last_name/up.yaml create mode 100644 hasura/migrations/1579729535626_alter_table_public_jobs_drop_column_pit_owner_phone/down.yaml create mode 100644 hasura/migrations/1579729535626_alter_table_public_jobs_drop_column_pit_owner_phone/up.yaml create mode 100644 hasura/migrations/1579729546834_alter_table_public_jobs_drop_column_pit_owner_email/down.yaml create mode 100644 hasura/migrations/1579729546834_alter_table_public_jobs_drop_column_pit_owner_email/up.yaml create mode 100644 hasura/migrations/1579729565695_alter_table_public_jobs_drop_column_pit_vehicle_plate_no/down.yaml create mode 100644 hasura/migrations/1579729565695_alter_table_public_jobs_drop_column_pit_vehicle_plate_no/up.yaml create mode 100644 hasura/migrations/1579730319740_alter_table_public_jobs_alter_column_est_number/down.yaml create mode 100644 hasura/migrations/1579730319740_alter_table_public_jobs_alter_column_est_number/up.yaml diff --git a/client/src/components/jobs-list/jobs-list.component.jsx b/client/src/components/jobs-list/jobs-list.component.jsx index 592144dbb..15bdc7d96 100644 --- a/client/src/components/jobs-list/jobs-list.component.jsx +++ b/client/src/components/jobs-list/jobs-list.component.jsx @@ -4,12 +4,14 @@ import { useTranslation } from "react-i18next"; import { Link } from "react-router-dom"; import PhoneFormatter from "../../utils/PhoneFormatter"; import { alphaSort } from "../../utils/sorters"; +import { withRouter } from "react-router-dom"; -export default function JobsList({ +export default withRouter(function JobsList({ loading, jobs, selectedJob, - setSelectedJob + setSelectedJob, + history }) { const [state, setState] = useState({ sortedInfo: {}, @@ -182,6 +184,7 @@ export default function JobsList({ if (record) { if (record.id) { setSelectedJob(record.id); + history.push(`#${record.id}`); return; } } @@ -222,4 +225,4 @@ export default function JobsList({ /> ); -} +}); diff --git a/client/src/graphql/apollo-error-handling.js b/client/src/graphql/apollo-error-handling.js index 617259f3d..322164f9a 100644 --- a/client/src/graphql/apollo-error-handling.js +++ b/client/src/graphql/apollo-error-handling.js @@ -9,10 +9,20 @@ const errorLink = onError( console.log("networkError", networkError); console.log("operation", operation); console.log("forward", forward); - if ( - graphQLErrors[0]?.message.includes("JWTExpired") || - networkError?.message.includes("JWTExpired") - ) { + + let expired = false; + + if (graphQLErrors) { + if (graphQLErrors[0].message.includes("JWTExpired")) { + expired = true; + } + } + if (networkError) { + if (networkError?.message.includes("JWTExpired")) { + expired = true; + } + } + if (expired) { //User access token has expired //props.history.push("/network-error"); console.log("We need a new token!"); diff --git a/client/src/pages/jobs/jobs.page.jsx b/client/src/pages/jobs/jobs.page.jsx index 857b22623..ee640a0e6 100644 --- a/client/src/pages/jobs/jobs.page.jsx +++ b/client/src/pages/jobs/jobs.page.jsx @@ -8,7 +8,7 @@ import JobsList from "../../components/jobs-list/jobs-list.component"; import JobDetailCards from "../../components/job-detail-cards/job-detail-cards.component"; //TODO: Implement pagination for this. -export default function JobsPage() { +export default function JobsPage({ match, location }) { const { loading, error, data } = useSubscription(SUBSCRIPTION_ALL_OPEN_JOBS, { fetchPolicy: "network-only" }); @@ -18,9 +18,11 @@ export default function JobsPage() { document.title = t("titles.jobs"); }, [t]); - const [selectedJob, setSelectedJob] = useState(null); + const { hash } = location; + const [selectedJob, setSelectedJob] = useState(hash ? hash.substr(1) : null); + console.log("Jobs Page Render."); - if (error) return ; + if (error) return ; return (