Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to view temp records in the crashes list and also soft-delete them #1495

Merged
merged 24 commits into from
Aug 6, 2024

Conversation

roseeichelmann
Copy link
Contributor

@roseeichelmann roseeichelmann commented Jul 31, 2024

Associated issues

Closes cityofaustin/atd-data-tech#18429

Testing

URL to test:
Local

Steps to test:

  1. Start up your VZ data model, run the migrations and apply metadata from this branch. You can run the cris import script to get some more data.
  2. Create some temp records with varying units, injuries, etc.
  3. Test deleting the temp record. In the database make sure the crash and all its associated units and people records all had their is_deleted columns updated to true.
  4. Make sure the temp records you deleted are no longer showing up in the crashes list page, the fatalities page, or in the dashboard totals.
  5. Will crash if you try to go to the old temp crash details page but I think there is another issue open to address routing to the 404 page so i think we can address this in that PR

Ship list

  • Check migrations for any conflicts with latest migrations in master branch
  • Confirm Hasura role permissions for necessary access
  • Code reviewed
  • Product manager approved

@roseeichelmann roseeichelmann added the WIP Work in progress label Jul 31, 2024
@@ -231,7 +232,7 @@ const CreateCrashRecord = ({ client }) => {
id="hf-case-id"
name="hf-case-id"
placeholder="Enter Case ID..."
autocomplete="off"
autoComplete="off"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixes dom warning

@@ -193,6 +193,7 @@ const CreateCrashRecord = ({ client }) => {
created_by: userEmail,
cris_schema_version: "2023",
is_temp_record: true,
private_dr_fl: false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default to private_dr_fl = false on temp record creation, meaning the crash will show up in our socrata totals and in the crashes list page, etc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect. glad you mentioned Socrata—I think we should the is_temp_record column to public datasets. i'll add it to the todo list :)

@@ -419,6 +419,7 @@ left join
left join
lookups.injry_sev_lkp
on lookups.injry_sev_lkp.id = crash_injury_metrics_view.crash_injry_sev_id
where crashes.is_deleted = false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

crashes list view only has records that havent been soft deleted now

@@ -173,6 +173,7 @@ create or replace view person_injury_metrics_view as (
left join
public.crashes as crashes
on units.crash_id = crashes.id
where people.is_deleted = false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updating all of these views to filter out soft deleted records

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i made a todo that we should index those columns 👍

@@ -3,7 +3,7 @@ export const createCrashDataMap = isTempRecord => {
{
title: "Details",
fields: {
crash_id: {
record_locator: {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now the temp records wont have an empty space here on the crash details page

@@ -5,13 +5,13 @@ export const fatalityGridTableColumns = {
label_table: "Year",
type: "Int",
},
cris_crash_id: {
record_locator: {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also to show the temp crash ids of temp records

@@ -147,15 +135,15 @@ const CreateCrashRecordTable = ({ crashesData, loading, error }) => {
</Link>
</td>
<td>{item.case_id}</td>
<td>{item.crash_timestamp}</td>
<td>{formatDateTimeString(item.crash_timestamp)}</td>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previously these werent formatted and were showing up as ugly ISO strings

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@roseeichelmann roseeichelmann removed the WIP Work in progress label Aug 1, 2024
@roseeichelmann roseeichelmann removed the WIP Work in progress label Aug 1, 2024
Copy link
Member

@johnclary johnclary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roseeichelmann this looks great and works great—so nice to have this missing piece in place.

I have a tiny change request to fix that delete confirmation text.

These other things can happily be out of scope, but I want to ask if you would address them in this PR and/or give your feedback:

  1. I don't like this text that says SECONDARY ADDRESS MISSING. I think it would be better to not render anything if the secondary address is null.
Screenshot 2024-08-02 at 9 49 29 AM
  1. It would be nice to change the text that appears in the crash diagram card. For temp records, the text can say "Crash diagrams are not available for user-created crash records" 👇
Screenshot 2024-08-02 at 9 47 13 AM
  1. Lastly—I'm not sure about this one—I noticed that people records do not get created unless the injury severity was fatal or serious. But units do get created no matter what. See this example, where we have three units but only two person records, because the fatal and serious injury count were both 0 for unit 2:
Screenshot 2024-08-02 at 10 01 04 AM

I think ideally we should create a person record with no injury in these cases. Right? I also wonder what we're doing in production today...

I'm happy to open separate issues for these tasks ☝️

}
}
update_people_cris(
where: { units_cri: { crash_id: { _eq: $recordId } } }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome to see this nested where! i'm going to rename the relationship units_cri to units_cris in a forthcoming PR that branches from here. that's an artifact of Hasura trying to guess at pluralization 🤖

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was gonna point out the cri thing and ask if we should rename but i forgot, glad you pointed it out!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multiple cri = cris. this whole thing is hilarious to me. Thanks for the laugh, Hasura! 😄 And, thanks y'all for fixing. 🚀

primary_key: true,
searchable: true,
sortable: true,
label_search: "Search by Crash ID",
label_table: "Crash ID",
type: "Int",
type: "String",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes, we should index record_locator as well. i'm tracking that ✅

@@ -193,6 +193,7 @@ const CreateCrashRecord = ({ client }) => {
created_by: userEmail,
cris_schema_version: "2023",
is_temp_record: true,
private_dr_fl: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect. glad you mentioned Socrata—I think we should the is_temp_record column to public datasets. i'll add it to the todo list :)

const openModalDelete = crashId => {
setDeleteId(crashId);
const openModalDelete = recordId => {
setDeleteId(recordId);
toggleModalDelete();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind updating the warning message inside the modal? Remove "This cannot be undone" since that is no longer true.

warning

@@ -147,15 +135,15 @@ const CreateCrashRecordTable = ({ crashesData, loading, error }) => {
</Link>
</td>
<td>{item.case_id}</td>
<td>{item.crash_timestamp}</td>
<td>{formatDateTimeString(item.crash_timestamp)}</td>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@johnclary
Copy link
Member

Here's the issue to fix the 404 handler: cityofaustin/atd-data-tech#18479

@roseeichelmann
Copy link
Contributor Author

@johnclary i addressed all your requested changes, as for your last point, not adding any people unless they are injuries/fatalities is how it currently works in production. i think the vz team truly just cares about injuries and fatalities for temp records and it was a conscious choice to only create ppl records for that. plus, there could be 5 people in a unit and if none of them had any injuries or fatalities and we just auto added 1 person to the unit that wouldnt make much sense either?

Copy link
Member

@johnclary johnclary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢 🚢 🚢 🚢 🚢 🚢 🚢 🚢

)}
<h2 className="h2 mb-3">{`${primaryAddress ? primaryAddress : ""} ${
secondaryAddress ? "& " + secondaryAddress : ""
}`}</h2>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnclary
Copy link
Member

@roseeichelmann great points—I agree with you wrt to those person records 🙏

Copy link
Contributor

@mddilley mddilley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested all of the steps, and it is all working as expected. So nice to see these soft deletes!!! This PR really shows off the record locator too! Good stuff!! 🚢 😎 🙌

(isTempRecord ? (
<CardBody>
<p>
Crash diagrams are not available for user-created crash records.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i like this detail!

// });
// };
/**
* Soft deletes the temporary crash and all its associated unit and people records
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for being more specific about the types of records affected in this comment. the old comment threw me for a loop!

variables: { recordId: deleteId, updatedBy: userEmail },
})
.then(() => {
setSuccessfulNewRecordId(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at first i was confused about why this needs to be set to null but now i see that this makes the green alert go away if it happens to be there after previously adding a temp record. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup you got it!

@roseeichelmann roseeichelmann merged commit bc645cf into data-model-v2 Aug 6, 2024
@roseeichelmann roseeichelmann deleted the 18429_temp_records_soft_delete branch August 6, 2024 16:41
@johnclary johnclary mentioned this pull request Oct 21, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants