Skip to content

Commit

Permalink
Merge pull request #1091 from cityofaustin/9519_edit_recommendations
Browse files Browse the repository at this point in the history
9519 edit recommendations
  • Loading branch information
mateoclarke authored Aug 30, 2022
2 parents 8904b8a + a586817 commit e3a4d2d
Show file tree
Hide file tree
Showing 9 changed files with 456 additions and 86 deletions.
54 changes: 53 additions & 1 deletion atd-vze/src/queries/recommendations.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,70 @@ import { gql } from "apollo-boost";

export const GET_RECOMMENDATIONS = gql`
query FindRecommendations($crashId: Int) {
recommendations(where: {crash_id: {_eq: $crashId}}) {
recommendations(where: { crash_id: { _eq: $crashId } }) {
id
created_at
text
created_by
crash_id
update
atd__coordination_partners_lkp {
description
}
atd__recommendation_status_lkp {
description
}
}
atd__coordination_partners_lkp {
id
description
}
atd__recommendation_status_lkp {
id
description
}
}
`;

export const INSERT_RECOMMENDATION = gql`
mutation InsertRecommendation(
$text: String
$update: String
$crashId: Int
$userEmail: String
$coordination_partner_id: Int
$recommendation_status_id: Int
) {
insert_recommendations(
objects: {
text: $text
update: $update
crash_id: $crashId
created_by: $userEmail
coordination_partner_id: $coordination_partner_id
recommendation_status_id: $recommendation_status_id
}
) {
returning {
crash_id
update
text
created_at
created_by
}
}
}
`;

export const UPDATE_RECOMMENDATION = gql`
mutation UpdateRecommendations(
$id: Int!
$changes: recommendations_set_input
) {
update_recommendations_by_pk(pk_columns: { id: $id }, _set: $changes) {
crash_id
text
update
}
}
`;
23 changes: 17 additions & 6 deletions atd-vze/src/views/Crashes/Crash.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from "reactstrap";
import { withApollo } from "react-apollo";
import { useQuery } from "@apollo/react-hooks";
import { useAuth0, isAdmin, isItSupervisor } from "../../auth/authContext";

import CrashCollapses from "./CrashCollapses";
import CrashMap from "./Maps/CrashMap";
Expand All @@ -22,7 +23,7 @@ import CrashNarrative from "./CrashNarrative";
import DataTable from "../../Components/DataTable";
import Notes from "./Notes";
import { crashDataMap } from "./crashDataMap";
import Recommendations from "./Recommendations";
import Recommendations from "./Recommendations/Recommendations";

import "./crash.scss";

Expand Down Expand Up @@ -63,6 +64,14 @@ function Crash(props) {
const [formData, setFormData] = useState({});
const [isEditingCoords, setIsEditingCoords] = useState(false);

const { getRoles } = useAuth0();
const roles = getRoles();

const isCrashFatal =
data?.atd_txdot_crashes?.[0]?.atd_fatality_count > 0 ? true : false;
const shouldShowFatalityRecommendations =
(isAdmin(roles) || isItSupervisor(roles)) && isCrashFatal;

if (loading || peopleLoading) return "Loading...";
if (error) return `Error! ${error.message}`;
if (peopleError) return `Error! ${peopleError.message}`;
Expand Down Expand Up @@ -281,11 +290,13 @@ function Crash(props) {
) : (
<div></div>
)}
<Row>
<Col>
<Recommendations crashId={props.match.params.id} />
</Col>
</Row>
{shouldShowFatalityRecommendations && (
<Row>
<Col>
<Recommendations crashId={props.match.params.id} />
</Col>
</Row>
)}
<Row>
<Col>
<Notes crashId={props.match.params.id} />
Expand Down
21 changes: 10 additions & 11 deletions atd-vze/src/views/Crashes/Notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ const Notes = ({ crashId }) => {
.then(response => {
refetch().then(response => {
setEditedNote("");
setEditRow("");
});
})
.catch(error => console.error(error));
Expand Down Expand Up @@ -122,26 +121,26 @@ const Notes = ({ crashId }) => {
<th
style={{
width: "10%",
"border-top": "0px",
"border-bottom": "1px",
borderTop: "0px",
borderBottom: "1px",
}}
>
{fieldConfig.fields.date.label}
</th>
<th
style={{
width: "24%",
"border-top": "0px",
"border-bottom": "1px",
borderTop: "0px",
borderBottom: "1px",
}}
>
{fieldConfig.fields.user_email.label}
</th>
<th
style={{
width: "54%",
"border-top": "0px",
"border-bottom": "1px",
borderTop: "0px",
borderBottom: "1px",
}}
>
{fieldConfig.fields.text.label}
Expand All @@ -151,8 +150,8 @@ const Notes = ({ crashId }) => {
<th
style={{
width: "6%",
"border-top": "0px",
"border-bottom": "1px",
borderTop: "0px",
borderBottom: "1px",
}}
></th>
)}
Expand All @@ -161,8 +160,8 @@ const Notes = ({ crashId }) => {
<th
style={{
width: "6%",
"border-top": "0px",
"border-bottom": "1px",
borderTop: "0px",
borderBottom: "1px",
}}
></th>
)}
Expand Down
61 changes: 0 additions & 61 deletions atd-vze/src/views/Crashes/Recommendations.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React, { useState } from "react";
import {
Dropdown,
DropdownToggle,
DropdownMenu,
DropdownItem,
} from "reactstrap";

const RecommendationSelectValueDropdown = ({
value,
onOptionClick,
options,
field,
}) => {
const [isOpen, setIsOpen] = useState(false);

const handleOptionClick = e => {
const { id } = e.target;

// Mutation expect lookup IDs as integers
const valuesObject = { [field]: parseInt(id) };
onOptionClick(valuesObject);
};

// Add a null option to enable users to clear out the value
const makeOptionsWithNullOption = options => [
{ id: null, description: "None" },
...options,
];

return (
<Dropdown
toggle={() => {
setIsOpen(!isOpen);
}}
isOpen={isOpen}
className="mb-3"
>
<DropdownToggle
className="w-100 pt-1 pl-2 d-flex text-left"
style={{ backgroundColor: "transparent", border: "0" }}
>
<div className="flex-grow-1">{value}</div>
<div className="pl-3">
<i className="fa fa-caret-down fa-lg"></i>
</div>
</DropdownToggle>
<DropdownMenu className="w-100">
{makeOptionsWithNullOption(options).map(option => {
return (
<DropdownItem
id={option.id}
key={option.id}
onClick={handleOptionClick}
className="pl-2"
>
{option.description}
</DropdownItem>
);
})}
</DropdownMenu>
</Dropdown>
);
};

export default RecommendationSelectValueDropdown;
Loading

0 comments on commit e3a4d2d

Please sign in to comment.