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

Implement soft deletes for crash notes #1540

Merged
merged 8 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions atd-vzd/metadata/databases/default/tables/public_crash_notes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,55 @@ insert_permissions:
permission:
check: {}
columns:
- id
- crash_pk
- created_at
- updated_at
- date
- id
- is_deleted
- text
- crash_pk
- updated_at
- user_email
- role: vz-admin
permission:
check: {}
columns:
- id
- crash_pk
- created_at
- updated_at
- date
- id
- is_deleted
- text
- crash_pk
- updated_at
- user_email
select_permissions:
- role: editor
permission:
columns:
- crash_pk
- id
- text
- user_email
- created_at
- date
- id
- is_deleted
- text
- updated_at
- user_email
filter: {}
- role: readonly
permission:
columns:
- crash_pk
- id
- text
- user_email
- created_at
- date
- id
- is_deleted
- text
- updated_at
- user_email
filter: {}
- role: vz-admin
permission:
columns:
- is_deleted
- crash_pk
- id
- text
Expand All @@ -66,6 +71,7 @@ update_permissions:
- role: editor
permission:
columns:
- is_deleted
- crash_pk
- id
- text
Expand All @@ -79,12 +85,13 @@ update_permissions:
permission:
columns:
- crash_pk
- id
- text
- user_email
- created_at
- date
- id
- is_deleted
- text
- updated_at
- user_email
filter: {}
check: null
delete_permissions:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table public.crash_notes
drop column if exists is_deleted;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table public.crash_notes add column is_deleted bool
not null default false;
15 changes: 7 additions & 8 deletions atd-vze/src/Components/Notes/Notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Notes = ({
notes,
INSERT_NOTE,
UPDATE_NOTE,
DELETE_NOTE,
SOFT_DELETE_NOTE,
Copy link
Contributor

Choose a reason for hiding this comment

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

🚀

refetch,
}) => {
// add a state variable to manage value when new note is entered
Expand All @@ -30,7 +30,7 @@ const Notes = ({
// declare mutation functions
const [addNote] = useMutation(INSERT_NOTE);
const [editNote] = useMutation(UPDATE_NOTE);
const [deleteNote] = useMutation(DELETE_NOTE);
const [deleteNote] = useMutation(SOFT_DELETE_NOTE);
Copy link
Member

Choose a reason for hiding this comment

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

Screenshot 2024-09-05 at 11 09 23 AM

It's not quite right that we show the "Are you sure?" text and note text with the same styling. What do you think about not showing the note text at all in the modal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah i am very down to remove the note text completely!

Copy link
Member

Choose a reason for hiding this comment

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

thanks, Rose! 🚢

const fieldConfig = notesDataMap[0];

// function to handle add button click
Expand Down Expand Up @@ -154,8 +154,8 @@ const Notes = ({
{/* display user input row for users with edit permissions*/}
{!isReadOnly(roles) && (
<tr>
<td></td>
<td></td>
<td />
<td />
<td>
<Input
type="textarea"
Expand All @@ -176,7 +176,7 @@ const Notes = ({
Add
</Button>
</td>
<td></td>
<td />
</tr>
)}
{/* iterate through each row in notes table */}
Expand Down Expand Up @@ -222,7 +222,7 @@ const Notes = ({
</td>
) : (
// else if user has edit permissions and is not editing render empty cell
!isReadOnly(roles) && !isEditing && <td></td>
!isReadOnly(roles) && !isEditing && <td />
)}
{/* display delete button if row was created by current user,
user has edit permissions, and user is not currently editing */}
Expand All @@ -234,14 +234,13 @@ const Notes = ({
modalBody={
<div>
Are you sure you want to delete this note?
<p className="mt-2 text-truncate">{row.text}</p>
</div>
}
/>
</td>
) : (
// else if user has edit permissions and is not editing render empty cell
!isReadOnly(roles) && !isEditing && <td></td>
!isReadOnly(roles) && !isEditing && <td />
)}
{/* display save button if user is editing */}
{!isReadOnly(roles) && isEditing && (
Expand Down
27 changes: 18 additions & 9 deletions atd-vze/src/queries/crashNotes.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { gql } from "apollo-boost";

export const INSERT_NOTE = gql`
mutation InsertNote($note: String!, $parentRecordId: Int!, $userEmail: String) {
mutation InsertNote(
$note: String!
$parentRecordId: Int!
$userEmail: String
) {
insert_crash_notes(
objects: { text: $note, crash_pk: $parentRecordId, user_email: $userEmail }
objects: {
text: $note
crash_pk: $parentRecordId
user_email: $userEmail
}
) {
returning {
crash_pk
Expand All @@ -26,13 +34,14 @@ export const UPDATE_NOTE = gql`
}
`;

export const DELETE_NOTE = gql`
mutation DeleteNote($id: Int!) {
delete_crash_notes_by_pk(id: $id) {
crash_pk
text
date
user_email
export const SOFT_DELETE_NOTE = gql`
mutation SoftDeleteNote($id: Int!) {
update_crash_notes_by_pk(
pk_columns: { id: $id }
_set: { is_deleted: true }
) {
id
is_deleted
}
}
`;
5 changes: 4 additions & 1 deletion atd-vze/src/queries/crashes.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ export const GET_CRASH = gql`
}
}
}
crash_notes(order_by: { date: desc }) {
crash_notes(
where: { is_deleted: { _eq: false } }
order_by: { date: desc }
) {
id
created_at
updated_at
Expand Down
4 changes: 2 additions & 2 deletions atd-vze/src/views/Crashes/Crash.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { UPDATE_CRASH, GET_CRASH } from "../../queries/crashes";
import {
INSERT_NOTE,
UPDATE_NOTE,
DELETE_NOTE,
SOFT_DELETE_NOTE,
} from "../../queries/crashNotes";

function Crash(props) {
Expand Down Expand Up @@ -286,7 +286,7 @@ function Crash(props) {
notes={crashRecord?.crash?.crash_notes}
INSERT_NOTE={INSERT_NOTE}
UPDATE_NOTE={UPDATE_NOTE}
DELETE_NOTE={DELETE_NOTE}
SOFT_DELETE_NOTE={SOFT_DELETE_NOTE}
Copy link
Member

Choose a reason for hiding this comment

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

i love this kind of detail!

refetch={crashRefetch}
/>
</Col>
Expand Down