From f21d573985705cba5553b524100d74d4bde005f6 Mon Sep 17 00:00:00 2001
From: rose <rose.eichelmann@gmail.com>
Date: Thu, 25 Jul 2024 17:55:47 -0400
Subject: [PATCH 01/14] add years of life lost as field to socrata export view

---
 .../data_model/python/sql_templates/socrata_export_views.sql     | 1 +
 .../migrations/default/1715960023005_socrata_export_views/up.sql | 1 +
 2 files changed, 2 insertions(+)

diff --git a/atd-toolbox/data_model/python/sql_templates/socrata_export_views.sql b/atd-toolbox/data_model/python/sql_templates/socrata_export_views.sql
index af7be4540..0714aa87d 100644
--- a/atd-toolbox/data_model/python/sql_templates/socrata_export_views.sql
+++ b/atd-toolbox/data_model/python/sql_templates/socrata_export_views.sql
@@ -49,6 +49,7 @@ select
     cimv.micromobility_sus_serious_injry_count as micromobility_serious_injury_count,
     cimv.other_fatality_count as other_death_count,
     cimv.other_sus_serious_injry_count as other_serious_injury_count,
+    cimv.years_of_life_lost,
     to_char(
         crashes.crash_timestamp, 'YYYY-MM-DD"T"HH24:MI:SS'
     ) as crash_timestamp,
diff --git a/atd-vzd/migrations/default/1715960023005_socrata_export_views/up.sql b/atd-vzd/migrations/default/1715960023005_socrata_export_views/up.sql
index 5c4606041..cf3f774f6 100644
--- a/atd-vzd/migrations/default/1715960023005_socrata_export_views/up.sql
+++ b/atd-vzd/migrations/default/1715960023005_socrata_export_views/up.sql
@@ -49,6 +49,7 @@ select
     cimv.micromobility_sus_serious_injry_count as micromobility_serious_injury_count,
     cimv.other_fatality_count as other_death_count,
     cimv.other_sus_serious_injry_count as other_serious_injury_count,
+    cimv.years_of_life_lost,
     to_char(
         crashes.crash_timestamp, 'YYYY-MM-DD"T"HH24:MI:SS'
     ) as crash_timestamp,

From 4473149c80be64bb766e16eacddcede9280cac74 Mon Sep 17 00:00:00 2001
From: rose <rose.eichelmann@gmail.com>
Date: Thu, 25 Jul 2024 17:56:00 -0400
Subject: [PATCH 02/14] add permissions to socrata view

---
 .../public_socrata_export_crashes_view.yaml   | 142 ++++++++++++++++++
 1 file changed, 142 insertions(+)

diff --git a/atd-vzd/metadata/databases/default/tables/public_socrata_export_crashes_view.yaml b/atd-vzd/metadata/databases/default/tables/public_socrata_export_crashes_view.yaml
index 37180bdef..9fe3317fb 100644
--- a/atd-vzd/metadata/databases/default/tables/public_socrata_export_crashes_view.yaml
+++ b/atd-vzd/metadata/databases/default/tables/public_socrata_export_crashes_view.yaml
@@ -1,3 +1,145 @@
 table:
   name: socrata_export_crashes_view
   schema: public
+select_permissions:
+  - role: editor
+    permission:
+      columns:
+        - bicycle_death_count
+        - bicycle_serious_injury_count
+        - death_cnt
+        - law_enf_fatality_count
+        - micromobility_death_count
+        - micromobility_serious_injury_count
+        - motorcycle_death_count
+        - motorcycle_serious_injury_count
+        - motor_vehicle_death_count
+        - motor_vehicle_serious_injury_count
+        - nonincap_injry_cnt
+        - non_injry_cnt
+        - other_death_count
+        - other_serious_injury_count
+        - pedestrian_death_count
+        - pedestrian_serious_injury_count
+        - poss_injry_cnt
+        - sus_serious_injry_cnt
+        - tot_injry_cnt
+        - unkn_injry_cnt
+        - years_of_life_lost
+        - crash_fatal_fl
+        - onsys_fl
+        - private_dr_fl
+        - road_constr_zone_fl
+        - crash_id
+        - crash_sev_id
+        - crash_speed_limit
+        - id
+        - latitude
+        - longitude
+        - address_primary
+        - address_secondary
+        - case_id
+        - crash_timestamp
+        - crash_timestamp_ct
+        - point
+        - rpt_block_num
+        - rpt_street_name
+        - rpt_street_sfx
+        - units_involved
+      filter: {}
+      allow_aggregations: true
+    comment: ""
+  - role: readonly
+    permission:
+      columns:
+        - bicycle_death_count
+        - bicycle_serious_injury_count
+        - death_cnt
+        - law_enf_fatality_count
+        - micromobility_death_count
+        - micromobility_serious_injury_count
+        - motorcycle_death_count
+        - motorcycle_serious_injury_count
+        - motor_vehicle_death_count
+        - motor_vehicle_serious_injury_count
+        - nonincap_injry_cnt
+        - non_injry_cnt
+        - other_death_count
+        - other_serious_injury_count
+        - pedestrian_death_count
+        - pedestrian_serious_injury_count
+        - poss_injry_cnt
+        - sus_serious_injry_cnt
+        - tot_injry_cnt
+        - unkn_injry_cnt
+        - years_of_life_lost
+        - crash_fatal_fl
+        - onsys_fl
+        - private_dr_fl
+        - road_constr_zone_fl
+        - crash_id
+        - crash_sev_id
+        - crash_speed_limit
+        - id
+        - latitude
+        - longitude
+        - address_primary
+        - address_secondary
+        - case_id
+        - crash_timestamp
+        - crash_timestamp_ct
+        - point
+        - rpt_block_num
+        - rpt_street_name
+        - rpt_street_sfx
+        - units_involved
+      filter: {}
+      allow_aggregations: true
+    comment: ""
+  - role: vz-admin
+    permission:
+      columns:
+        - bicycle_death_count
+        - bicycle_serious_injury_count
+        - death_cnt
+        - law_enf_fatality_count
+        - micromobility_death_count
+        - micromobility_serious_injury_count
+        - motorcycle_death_count
+        - motorcycle_serious_injury_count
+        - motor_vehicle_death_count
+        - motor_vehicle_serious_injury_count
+        - nonincap_injry_cnt
+        - non_injry_cnt
+        - other_death_count
+        - other_serious_injury_count
+        - pedestrian_death_count
+        - pedestrian_serious_injury_count
+        - poss_injry_cnt
+        - sus_serious_injry_cnt
+        - tot_injry_cnt
+        - unkn_injry_cnt
+        - years_of_life_lost
+        - crash_fatal_fl
+        - onsys_fl
+        - private_dr_fl
+        - road_constr_zone_fl
+        - crash_id
+        - crash_sev_id
+        - crash_speed_limit
+        - id
+        - latitude
+        - longitude
+        - address_primary
+        - address_secondary
+        - case_id
+        - crash_timestamp
+        - crash_timestamp_ct
+        - point
+        - rpt_block_num
+        - rpt_street_name
+        - rpt_street_sfx
+        - units_involved
+      filter: {}
+      allow_aggregations: true
+    comment: ""

From 67bb56fa619bcd241858a5e0ef7c2c0df8871a2e Mon Sep 17 00:00:00 2001
From: rose <rose.eichelmann@gmail.com>
Date: Thu, 25 Jul 2024 17:56:25 -0400
Subject: [PATCH 03/14] query the socrata view instead for ytd aggregates

---
 atd-vze/src/queries/dashboard.js | 77 ++------------------------------
 1 file changed, 4 insertions(+), 73 deletions(-)

diff --git a/atd-vze/src/queries/dashboard.js b/atd-vze/src/queries/dashboard.js
index b73268283..9241557a8 100644
--- a/atd-vze/src/queries/dashboard.js
+++ b/atd-vze/src/queries/dashboard.js
@@ -4,89 +4,20 @@ import { gql } from "apollo-boost";
 // so that the VZV and VZE widget totals match up
 // See https://github.com/cityofaustin/atd-vz-data/blob/master/atd-etl/app/process/socrata_queries.py
 export const GET_CRASHES_YTD = gql`
-  query GetCrashesYTD($yearStart: date, $yearEnd: date) {
-    fatalities: atd_txdot_crashes_aggregate(
-      where: {
-        crash_date: { _lt: $yearEnd, _gte: $yearStart }
-        private_dr_fl: { _eq: "N" }
-        _and: [
-          { crash_date: { _is_null: false } }
-          { crash_time: { _is_null: false } }
-        ]
-        _or: [
-          { in_austin_full_purpose: { _eq: true } }
-          { _and: [{ city_id: { _eq: 22 } }, { position: { _is_null: true } }] }
-        ]
-      }
+  query GetCrashesYTD($yearStart: String, $yearEnd: String) {
+    socrata_export_crashes_view_aggregate(
+      where: { crash_timestamp: { _lt: $yearEnd, _gte: $yearStart } }
     ) {
       aggregate {
         sum {
-          atd_fatality_count
+          death_cnt
         }
       }
-    }
-    seriousInjuriesAndTotal: atd_txdot_crashes_aggregate(
-      where: {
-        crash_date: { _lt: $yearEnd, _gte: $yearStart }
-        private_dr_fl: { _eq: "N" }
-        _and: [
-          { crash_date: { _is_null: false } }
-          { crash_time: { _is_null: false } }
-        ]
-        _or: [
-          { in_austin_full_purpose: { _eq: true } }
-          { _and: [{ city_id: { _eq: 22 } }, { position: { _is_null: true } }] }
-        ]
-      }
-    ) {
       aggregate {
         sum {
           sus_serious_injry_cnt
         }
       }
-    }
-    primaryPersonFatalities: atd_txdot_primaryperson_aggregate(
-      where: {
-        crash: { private_dr_fl: { _eq: "N" } }
-        _and: {
-          prsn_injry_sev_id: { _eq: 4 }
-          crash: { crash_date: { _lt: $yearEnd, _gte: $yearStart } }
-          _or: [
-            { crash: { in_austin_full_purpose: { _eq: true } } }
-            {
-              _and: [
-                { crash: { city_id: { _eq: 22 } } }
-                { crash: { position: { _is_null: true } } }
-              ]
-            }
-          ]
-        }
-      }
-    ) {
-      aggregate {
-        sum {
-          years_of_life_lost
-        }
-      }
-    }
-    personFatalities: atd_txdot_person_aggregate(
-      where: {
-        crash: { private_dr_fl: { _eq: "N" } }
-        _and: {
-          prsn_injry_sev_id: { _eq: 4 }
-          crash: { crash_date: { _lt: $yearEnd, _gte: $yearStart } }
-          _or: [
-            { crash: { in_austin_full_purpose: { _eq: true } } }
-            {
-              _and: [
-                { crash: { city_id: { _eq: 22 } } }
-                { crash: { position: { _is_null: true } } }
-              ]
-            }
-          ]
-        }
-      }
-    ) {
       aggregate {
         sum {
           years_of_life_lost

From f71e5c9d6b8d51d5a414a4b594894e423197b50a Mon Sep 17 00:00:00 2001
From: rose <rose.eichelmann@gmail.com>
Date: Thu, 25 Jul 2024 17:56:33 -0400
Subject: [PATCH 04/14] rework to use new query

---
 atd-vze/src/views/VZDashboard/VZDashboard.js | 26 ++++++--------------
 1 file changed, 7 insertions(+), 19 deletions(-)

diff --git a/atd-vze/src/views/VZDashboard/VZDashboard.js b/atd-vze/src/views/VZDashboard/VZDashboard.js
index e877afd85..d42a049f3 100644
--- a/atd-vze/src/views/VZDashboard/VZDashboard.js
+++ b/atd-vze/src/views/VZDashboard/VZDashboard.js
@@ -13,33 +13,21 @@ import bi_logo from "../../assets/img/brand/power_bi_icon_white_on_transparent.p
 
 function VZDashboard() {
   const year = new Date().getFullYear();
-  const yearStart = `${year}-01-01`;
+  const yearStart = `${year}-01-01T00:00:00`;
   // We use the same end date as VZV so VZE widget totals match VZV widgets
-  const yearEnd = format(subDays(new Date(), 14), "yyyy-MM-dd");
+  const yearEnd = format(subDays(new Date(), 14), "yyyy-MM-dd'T'HH:mm:ss");
   const { loading, error, data } = useQuery(GET_CRASHES_YTD, {
     variables: { yearStart, yearEnd },
   });
-
   if (loading) return "Loading...";
   if (error) return `Error! ${error.message}`;
 
-  const {
-    years_of_life_lost: yearsOfLifeLostPrimaryPerson,
-  } = data.primaryPersonFatalities.aggregate.sum;
-
-  const {
-    years_of_life_lost: yearsOfLifeLostPerson,
-  } = data.personFatalities.aggregate.sum;
-
-  const {
-    sus_serious_injry_cnt: seriousInjuryCount,
-  } = data.seriousInjuriesAndTotal.aggregate.sum;
-  const { atd_fatality_count: deathCount } = data.fatalities.aggregate.sum;
+  const aggregateData =
+    data.socrata_export_crashes_view_aggregate.aggregate.sum;
 
-  const yearsOfLifeLostYTD =
-    yearsOfLifeLostPrimaryPerson + yearsOfLifeLostPerson;
-  const fatalitiesYTD = deathCount;
-  const seriousInjuriesYTD = seriousInjuryCount;
+  const yearsOfLifeLostYTD = aggregateData.years_of_life_lost;
+  const fatalitiesYTD = aggregateData.death_cnt;
+  const seriousInjuriesYTD = aggregateData.sus_serious_injry_cnt;
 
   // Widget02 expects a string value, DB returns number or null
   const commaSeparator = number =>

From 54919e3cf030977804fd9f3549d95cb235278fe6 Mon Sep 17 00:00:00 2001
From: rose <rose.eichelmann@gmail.com>
Date: Thu, 25 Jul 2024 18:29:08 -0400
Subject: [PATCH 05/14] update this comment

---
 atd-vze/src/queries/dashboard.js | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/atd-vze/src/queries/dashboard.js b/atd-vze/src/queries/dashboard.js
index 9241557a8..e8d176234 100644
--- a/atd-vze/src/queries/dashboard.js
+++ b/atd-vze/src/queries/dashboard.js
@@ -1,8 +1,7 @@
 import { gql } from "apollo-boost";
 
-// These queries are derived from the ETL that populates our Socrata data sets
+// This query is derived from the view that populates our Socrata dataset
 // so that the VZV and VZE widget totals match up
-// See https://github.com/cityofaustin/atd-vz-data/blob/master/atd-etl/app/process/socrata_queries.py
 export const GET_CRASHES_YTD = gql`
   query GetCrashesYTD($yearStart: String, $yearEnd: String) {
     socrata_export_crashes_view_aggregate(

From fab2dde39803f1bcd661d1eaf4b6cd7c8311b693 Mon Sep 17 00:00:00 2001
From: rose <rose.eichelmann@gmail.com>
Date: Sun, 28 Jul 2024 23:37:14 -0500
Subject: [PATCH 06/14] linting

---
 .../views/Crashes/crashGridTableParameters.js | 38 +++++++++----------
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/atd-vze/src/views/Crashes/crashGridTableParameters.js b/atd-vze/src/views/Crashes/crashGridTableParameters.js
index 1eeeec54a..2516fba4f 100644
--- a/atd-vze/src/views/Crashes/crashGridTableParameters.js
+++ b/atd-vze/src/views/Crashes/crashGridTableParameters.js
@@ -52,7 +52,7 @@ export const crashGridTableColumns = {
     label_table: "Est Comprehensive Cost",
     type: "Currency",
   },
-  "collsn_desc": {
+  collsn_desc: {
     searchable: false,
     sortable: true,
     label_table: "Collision Description",
@@ -65,7 +65,7 @@ export const crashGridTableColumns = {
     type: "String",
     hidden: true,
   },
-  "is_manual_geocode": {
+  is_manual_geocode: {
     searchable: false,
     sortable: true,
     label_table: "Manual geocode",
@@ -209,7 +209,7 @@ export const crashGridTableAdvancedFilters = {
         filter: {
           where: [
             {
-                is_manual_geocode: "_eq: true",
+              is_manual_geocode: "_eq: true",
             },
           ],
         },
@@ -220,7 +220,7 @@ export const crashGridTableAdvancedFilters = {
         filter: {
           where: [
             {
-                has_no_cris_coordinates: "_eq: true",
+              has_no_cris_coordinates: "_eq: true",
             },
           ],
         },
@@ -243,13 +243,13 @@ export const crashGridTableAdvancedFilters = {
     icon: "bicycle",
     label: "Unit Type",
     filters: [
-    {
-      id: "motor_vehicle",
-      label: "Motor Vehicle",
-      filter: {
-        where: [
-          {
-            [`
+      {
+        id: "motor_vehicle",
+        label: "Motor Vehicle",
+        filter: {
+          where: [
+            {
+              [`
               units: {
                 unit_desc_id: {
                   _eq: 1
@@ -258,11 +258,11 @@ export const crashGridTableAdvancedFilters = {
                   _nin: [71, 90]
                 },
               },
-            `]: null
-          },
-        ],
+            `]: null,
+            },
+          ],
+        },
       },
-    },
       {
         id: "motorcycle",
         label: "Motorcycle",
@@ -278,7 +278,7 @@ export const crashGridTableAdvancedFilters = {
                     _in: [71, 90]
                   },
                 },
-              `]: null
+              `]: null,
             },
           ],
         },
@@ -332,7 +332,7 @@ export const crashGridTableAdvancedFilters = {
                     _eq: 177
                   },
                 },
-              `]: null
+              `]: null,
             },
           ],
         },
@@ -357,7 +357,7 @@ export const crashGridTableAdvancedFilters = {
                   },
                 },
               },
-              `]: null
+              `]: null,
             },
           ],
         },
@@ -386,7 +386,7 @@ export const crashGridTableAdvancedFilters = {
         filter: {
           where: [
             {
-              private_dr_fl: '_neq: true',
+              private_dr_fl: "_neq: true",
             },
           ],
         },

From 9233a7c4dcdab3b50e9f7bdb635287a17e04af74 Mon Sep 17 00:00:00 2001
From: rose <rose.eichelmann@gmail.com>
Date: Mon, 29 Jul 2024 09:40:29 -0700
Subject: [PATCH 07/14] fix this typo

---
 atd-vze/src/views/Tools/CreateCrashRecord.js | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/atd-vze/src/views/Tools/CreateCrashRecord.js b/atd-vze/src/views/Tools/CreateCrashRecord.js
index f2912f8c5..515e5cc1c 100644
--- a/atd-vze/src/views/Tools/CreateCrashRecord.js
+++ b/atd-vze/src/views/Tools/CreateCrashRecord.js
@@ -347,13 +347,13 @@ const CreateCrashRecord = ({ client }) => {
                     fade={false}
                   >
                     {/*eslint-disable-next-line*/}
-                    <i className="fa fa-check-circle" /> Successfsully
-                    created crash{" "}
+                    <i className="fa fa-check-circle" /> Successfully created
+                    crash{" "}
                     <Link
                       to={`/crashes/T${successfulNewRecordId}`}
                       className="alert-link"
                     >
-                      #{successfulNewRecordId}
+                      #T{successfulNewRecordId}
                     </Link>
                   </Alert>
                   <Alert

From 23ab6cd8c395c25e0323d9b94109d58c695cdfbe Mon Sep 17 00:00:00 2001
From: rose <rose.eichelmann@gmail.com>
Date: Mon, 29 Jul 2024 09:41:06 -0700
Subject: [PATCH 08/14] use ISO format and get the time stuff all sorted out

---
 atd-vze/src/views/VZDashboard/VZDashboard.js | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/atd-vze/src/views/VZDashboard/VZDashboard.js b/atd-vze/src/views/VZDashboard/VZDashboard.js
index d42a049f3..fdaa7eeac 100644
--- a/atd-vze/src/views/VZDashboard/VZDashboard.js
+++ b/atd-vze/src/views/VZDashboard/VZDashboard.js
@@ -5,7 +5,7 @@ import { useQuery } from "@apollo/react-hooks";
 import Widget02 from "../Widgets/Widget02";
 import VZLinksWidget from "../Widgets/VZLinksWidget";
 import VZNoticeWidget from "../Widgets/VZNoticeWidget";
-import { format, subDays } from "date-fns";
+import { subDays } from "date-fns";
 
 import { GET_CRASHES_YTD } from "../../queries/dashboard";
 
@@ -15,7 +15,9 @@ function VZDashboard() {
   const year = new Date().getFullYear();
   const yearStart = `${year}-01-01T00:00:00`;
   // We use the same end date as VZV so VZE widget totals match VZV widgets
-  const yearEnd = format(subDays(new Date(), 14), "yyyy-MM-dd'T'HH:mm:ss");
+  const yearEnd = subDays(new Date(), 14)
+    .toISOString()
+    .substring(0, 19); // to match the ISO string format in the socrata view crash_timestamp column
   const { loading, error, data } = useQuery(GET_CRASHES_YTD, {
     variables: { yearStart, yearEnd },
   });

From a55f54e024e6b6fa423fd1d9fff17fa19131aca4 Mon Sep 17 00:00:00 2001
From: rose <rose.eichelmann@gmail.com>
Date: Mon, 29 Jul 2024 12:27:22 -0500
Subject: [PATCH 09/14] sort by asc

---
 atd-vze/src/views/Tools/CreateCrashRecordTable.js | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/atd-vze/src/views/Tools/CreateCrashRecordTable.js b/atd-vze/src/views/Tools/CreateCrashRecordTable.js
index c0bce176f..ef8f3908a 100644
--- a/atd-vze/src/views/Tools/CreateCrashRecordTable.js
+++ b/atd-vze/src/views/Tools/CreateCrashRecordTable.js
@@ -23,7 +23,10 @@ import {
 
 const GET_TEMP_RECORDS = gql`
   query getTempRecords {
-    crashes(where: { is_temp_record: { _eq: true } }) {
+    crashes(
+      where: { is_temp_record: { _eq: true } }
+      order_by: { record_locator: asc }
+    ) {
       record_locator
       case_id
       crash_timestamp

From ecc66ebd99b19ac9186862e9df961c6b1a450818 Mon Sep 17 00:00:00 2001
From: rose <rose.eichelmann@gmail.com>
Date: Mon, 29 Jul 2024 17:06:47 -0500
Subject: [PATCH 10/14] remove year end variable from socrata query

---
 atd-vze/src/queries/dashboard.js | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/atd-vze/src/queries/dashboard.js b/atd-vze/src/queries/dashboard.js
index e8d176234..20fa60f78 100644
--- a/atd-vze/src/queries/dashboard.js
+++ b/atd-vze/src/queries/dashboard.js
@@ -3,9 +3,9 @@ import { gql } from "apollo-boost";
 // This query is derived from the view that populates our Socrata dataset
 // so that the VZV and VZE widget totals match up
 export const GET_CRASHES_YTD = gql`
-  query GetCrashesYTD($yearStart: String, $yearEnd: String) {
+  query GetCrashesYTD($yearStart: String!) {
     socrata_export_crashes_view_aggregate(
-      where: { crash_timestamp: { _lt: $yearEnd, _gte: $yearStart } }
+      where: { crash_timestamp: { _gte: $yearStart } }
     ) {
       aggregate {
         sum {

From bd92fe0b9999a0c65baa7fd8629f7cb09359b9a1 Mon Sep 17 00:00:00 2001
From: rose <rose.eichelmann@gmail.com>
Date: Mon, 29 Jul 2024 17:07:46 -0500
Subject: [PATCH 11/14] refetch temp record table on submit

---
 atd-vze/src/views/Tools/CreateCrashRecord.js | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/atd-vze/src/views/Tools/CreateCrashRecord.js b/atd-vze/src/views/Tools/CreateCrashRecord.js
index 515e5cc1c..53c9ea638 100644
--- a/atd-vze/src/views/Tools/CreateCrashRecord.js
+++ b/atd-vze/src/views/Tools/CreateCrashRecord.js
@@ -1,5 +1,6 @@
 import React, { useState, useReducer } from "react";
 import { Link } from "react-router-dom";
+import { useQuery } from "@apollo/react-hooks";
 
 import {
   Alert,
@@ -23,6 +24,7 @@ import { gql } from "apollo-boost";
 import "./CreateCrashRecord.css";
 import UnitsForm from "./UnitsForm";
 import CreateCrashRecordTable from "./CreateCrashRecordTable";
+import { GET_TEMP_RECORDS } from "../../queries/tempRecords";
 import { useAuth0 } from "../../auth/authContext";
 
 // Builds an array of units objects with nested arrays of person objects within them
@@ -71,6 +73,10 @@ function buildNestedObjects(unitFormState, userEmail) {
 }
 
 const CreateCrashRecord = ({ client }) => {
+  const { loading, error, data, refetch } = useQuery(GET_TEMP_RECORDS, {
+    fetchPolicy: "no-cache",
+  });
+
   const { user } = useAuth0();
 
   const userEmail = user.email;
@@ -196,6 +202,7 @@ const CreateCrashRecord = ({ client }) => {
       .then(res => {
         // Re-route to the crash details page for the new temp record on successful creation
         setSuccessfulNewRecordId(res.data.insert_crashes_cris.returning[0].id);
+        refetch();
       })
       .catch(error => {
         setFeedback({ title: "Error", message: String(error) });
@@ -374,7 +381,11 @@ const CreateCrashRecord = ({ client }) => {
       </Row>
       <Row>
         <Col>
-          <CreateCrashRecordTable />
+          <CreateCrashRecordTable
+            crashesData={data.crashes}
+            loading={loading}
+            error={error}
+          />
         </Col>
       </Row>
     </>

From 636684e8e6f87c31faf11a8a5bb4cb48c921c103 Mon Sep 17 00:00:00 2001
From: rose <rose.eichelmann@gmail.com>
Date: Mon, 29 Jul 2024 17:08:08 -0500
Subject: [PATCH 12/14] get data from parent component

---
 .../src/views/Tools/CreateCrashRecordTable.js | 77 +++++++------------
 1 file changed, 27 insertions(+), 50 deletions(-)

diff --git a/atd-vze/src/views/Tools/CreateCrashRecordTable.js b/atd-vze/src/views/Tools/CreateCrashRecordTable.js
index ef8f3908a..187cdd09e 100644
--- a/atd-vze/src/views/Tools/CreateCrashRecordTable.js
+++ b/atd-vze/src/views/Tools/CreateCrashRecordTable.js
@@ -1,9 +1,9 @@
-import React, { useState, useEffect } from "react";
+import React, { useState } from "react";
 import { Link } from "react-router-dom";
 
 import { withApollo } from "react-apollo";
 import { gql } from "apollo-boost";
-import { useQuery, useMutation } from "@apollo/react-hooks";
+import { useMutation } from "@apollo/react-hooks";
 
 import {
   Alert,
@@ -21,21 +21,6 @@ import {
   Table,
 } from "reactstrap";
 
-const GET_TEMP_RECORDS = gql`
-  query getTempRecords {
-    crashes(
-      where: { is_temp_record: { _eq: true } }
-      order_by: { record_locator: asc }
-    ) {
-      record_locator
-      case_id
-      crash_timestamp
-      updated_by
-      updated_at
-    }
-  }
-`;
-
 const DELETE_TEMP_RECORD = gql`
   mutation deleteTempRecords($crashId: Int!) {
     delete_atd_txdot_crashes(where: { crash_id: { _eq: $crashId } }) {
@@ -53,20 +38,15 @@ const DELETE_TEMP_RECORD = gql`
   }
 `;
 
-const CreateCrashRecordTable = () => {
-  const [crashesData, setCrashesData] = useState(null);
+const CreateCrashRecordTable = ({ crashesData, loading, error }) => {
   const [crashSearch, setCrashSearch] = useState("");
   const [modalOpen, setModalOpen] = useState(false);
   const [deleteId, setDeleteId] = useState(null);
   const [feedback, setFeedback] = useState(null);
-  const { loading, error, data } = useQuery(GET_TEMP_RECORDS, {
-    fetchPolicy: "no-cache",
-  });
   const [deleteRecord] = useMutation(DELETE_TEMP_RECORD);
 
-  useEffect(() => {
-    setCrashesData(data);
-  }, [data]);
+  if (loading) return "Loading...";
+  if (error) return `Error! ${error.message}`;
 
   /**
    * Updates the case_id being searched
@@ -76,26 +56,26 @@ const CreateCrashRecordTable = () => {
     setCrashSearch(e.target.value);
   };
 
-  /**
-   * Deletes all the temporary records in the database
-   */
-  const handleDelete = () => {
-    setFeedback(null);
-    deleteRecord({ variables: { crashId: deleteId } })
-      .then(() => {
-        const newData = crashesData["crashes"].filter(item => {
-          return item.crash_id !== deleteId;
-        });
-        setDeleteId(null);
-        setFeedback(`Crash ID ${deleteId} has been deleted.`);
-        setCrashesData({ atd_txdot_crashes: newData });
-        toggleModalDelete();
-      })
-      .catch(err => {
-        setFeedback(String(err));
-        setDeleteId(null);
-      });
-  };
+  // /**
+  //  * Deletes all the temporary records in the database
+  //  */
+  // const handleDelete = () => {
+  //   setFeedback(null);
+  //   deleteRecord({ variables: { crashId: deleteId } })
+  //     .then(() => {
+  //       const newData = data["crashes"].filter(item => {
+  //         return item.crash_id !== deleteId;
+  //       });
+  //       setDeleteId(null);
+  //       setFeedback(`Crash ID ${deleteId} has been deleted.`);
+  //       setCrashesData({ atd_txdot_crashes: newData });
+  //       toggleModalDelete();
+  //     })
+  //     .catch(err => {
+  //       setFeedback(String(err));
+  //       setDeleteId(null);
+  //     });
+  // };
 
   /**
    * Opens/Closes the delete modal
@@ -155,8 +135,7 @@ const CreateCrashRecordTable = () => {
               </thead>
               <tbody>
                 {crashesData &&
-                  crashesData["crashes"] &&
-                  crashesData.crashes.map((item, index) => {
+                  crashesData.map((item, index) => {
                     if (crashSearch !== "" && item.case_id !== crashSearch)
                       return null;
 
@@ -202,9 +181,7 @@ const CreateCrashRecordTable = () => {
           This cannot be undone.
         </ModalBody>
         <ModalFooter>
-          <Button color="danger" onClick={handleDelete}>
-            Ok
-          </Button>
+          <Button color="danger">Ok</Button>
           <Button color="secondary" onClick={toggleModalDelete}>
             Cancel
           </Button>

From 73ce076fdbdd06901e556149988ec7dea2391b5d Mon Sep 17 00:00:00 2001
From: rose <rose.eichelmann@gmail.com>
Date: Mon, 29 Jul 2024 17:08:25 -0500
Subject: [PATCH 13/14] remove year end var

---
 atd-vze/src/views/VZDashboard/VZDashboard.js | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/atd-vze/src/views/VZDashboard/VZDashboard.js b/atd-vze/src/views/VZDashboard/VZDashboard.js
index fdaa7eeac..24957d131 100644
--- a/atd-vze/src/views/VZDashboard/VZDashboard.js
+++ b/atd-vze/src/views/VZDashboard/VZDashboard.js
@@ -5,21 +5,16 @@ import { useQuery } from "@apollo/react-hooks";
 import Widget02 from "../Widgets/Widget02";
 import VZLinksWidget from "../Widgets/VZLinksWidget";
 import VZNoticeWidget from "../Widgets/VZNoticeWidget";
-import { subDays } from "date-fns";
 
 import { GET_CRASHES_YTD } from "../../queries/dashboard";
 
 import bi_logo from "../../assets/img/brand/power_bi_icon_white_on_transparent.png";
 
 function VZDashboard() {
-  const year = new Date().getFullYear();
+  const year = new Date().getUTCFullYear();
   const yearStart = `${year}-01-01T00:00:00`;
-  // We use the same end date as VZV so VZE widget totals match VZV widgets
-  const yearEnd = subDays(new Date(), 14)
-    .toISOString()
-    .substring(0, 19); // to match the ISO string format in the socrata view crash_timestamp column
   const { loading, error, data } = useQuery(GET_CRASHES_YTD, {
-    variables: { yearStart, yearEnd },
+    variables: { yearStart },
   });
   if (loading) return "Loading...";
   if (error) return `Error! ${error.message}`;

From 0a13a197bf45909c259c4f53bf1157318f6ad35c Mon Sep 17 00:00:00 2001
From: rose <rose.eichelmann@gmail.com>
Date: Mon, 29 Jul 2024 17:08:46 -0500
Subject: [PATCH 14/14] lets move this query into its own file in the query
 folder

---
 atd-vze/src/queries/tempRecords.js | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
 create mode 100644 atd-vze/src/queries/tempRecords.js

diff --git a/atd-vze/src/queries/tempRecords.js b/atd-vze/src/queries/tempRecords.js
new file mode 100644
index 000000000..e8019eca9
--- /dev/null
+++ b/atd-vze/src/queries/tempRecords.js
@@ -0,0 +1,16 @@
+import { gql } from "apollo-boost";
+
+export const GET_TEMP_RECORDS = gql`
+  query getTempRecords {
+    crashes(
+      where: { is_temp_record: { _eq: true } }
+      order_by: { record_locator: desc }
+    ) {
+      record_locator
+      case_id
+      crash_timestamp
+      updated_by
+      updated_at
+    }
+  }
+`;