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

Rfj 22 save to pdf #88

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
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
130 changes: 109 additions & 21 deletions components/CaseRow.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from "react";
import React, { useState, useContext, useEffect } from "react";
import { CaseContext } from "../contexts/casecontroller";

import chargeContainer from "../static/chargecontainer.json";
import getAnalysis from "../libs/evaluator";

// components
Expand All @@ -20,21 +20,109 @@ import CardContent from "@material-ui/core/CardContent";
import TextField from "@material-ui/core/TextField";

function CaseRow(props) {
const [showForm, setShowForm] = useState(false); // default to collapsed
const value = useContext(CaseContext);
let charge = props.charges[props.title] || {};
const [showForm, setShowForm] = useState(true);

// Charge properties
const [description, setDescription] = useState(chargeContainer.description);
const [description, setDescription] = useState(charge.description);
const [classification, setClassification] = useState(
chargeContainer.classification
charge.classification
);
const [isBRAFelony, setIsBRAFelony] = useState(chargeContainer.isBRAFelony);
const [convicted, setConvicted] = useState(chargeContainer.isConvicted);
const [papered, setPapered] = useState(chargeContainer.isPapered);
const [offense, setOffense] = useState(chargeContainer.offense);
const [chargeDispositionDate, setChargeDispositionDate] = useState(
chargeContainer.dispositionDate
const [isBRAFelony, setIsBRAFelony] = useState(charge.isBRAFelony);
const [convicted, setConvicted] = useState(charge.isConvicted);
const [papered, setPapered] = useState(charge.isPapered);
const [offense, setOffense] = useState(charge.offense);
const [dispositionDate, setDispositionDate] = useState(
charge.dispositionDate
);

useEffect(() => {
if(props.charges && props.charges[props.title]){
setDescription(props.charges[props.title].description);
setClassification(props.charges[props.title].classification);
setIsBRAFelony(props.charges[props.title].isBRAFelony);
setConvicted(props.charges[props.title].isConvicted);
setPapered(props.charges[props.title].isPapered);
setOffense(props.charges[props.title].offense);
setDispositionDate(props.charges[props.title].dispositionDate);
}
}, [props]);

const getUpdater = () => {
return {
caseData: {
...value.caseData,
case: {
...value.caseData.case,
charges: {
...value.caseData.case.charges,
},
},
client: {
...value.caseData.client,
}
}
};
}


const persistClassification = classification => {
setClassification(classification);
let update = getUpdater();
let updateCharge = update.caseData.case.charges[props.title];
updateCharge.classification = classification;
value.updater(update);
}

const persistDescription = description => {
setDescription(description);
let update = getUpdater();
let updateCharge = update.caseData.case.charges[props.title];
updateCharge.description = description;
value.updater(update);
}

const persistIsBRAFelony = isBRAFelony => {
setIsBRAFelony(isBRAFelony);
let update = getUpdater();
let updateCharge = update.caseData.case.charges[props.title];
updateCharge.isBRAFelony = isBRAFelony;
value.updater(update);
}

const persistConvicted = isConvicted => {
setConvicted(isConvicted);
let update = getUpdater();
let updateCharge = update.caseData.case.charges[props.title];
updateCharge.isConvicted = isConvicted;
value.updater(update);
}

const persistPapered = isPapered => {
setPapered(isPapered);
let update = getUpdater();
let updateCharge = update.caseData.case.charges[props.title];
updateCharge.isPapered = isPapered;
value.updater(update);
}

const persistOffense = offense => {
setOffense(offense);
let update = getUpdater();
let updateCharge = update.caseData.case.charges[props.title];
updateCharge.offense = offense;
value.updater(update);
}

const persistDispositionDate = dispositionDate => {
setDispositionDate(dispositionDate);
let update = getUpdater();
let updateCharge = update.caseData.case.charges[props.title];
updateCharge.dispositionDate = dispositionDate;
value.updater(update);
}

function analysis() {
return getAnalysis(
convicted,
Expand All @@ -48,7 +136,7 @@ function CaseRow(props) {
return (
<Card>
<CardHeader
title={props.charge}
title={props.title}
action={
<IconButton
aria-label="Show form"
Expand All @@ -68,14 +156,14 @@ function CaseRow(props) {
autoComplete="off"
label="Offense"
value={offense}
onChange={e => setOffense(e.target.value)}
onChange={e => persistOffense(e.target.value)}
margin="normal"
/>
<ComposedDatePicker
ctxKeys={["caseData", "case", "charges", props.charge]}
ctxKeys={["caseData", "case", "charges", charge]}
label={"Disposition Date"}
initialDate={chargeDispositionDate}
hoist={e => setChargeDispositionDate(e)}
initialDate={dispositionDate}
hoist={e => persistDispositionDate(e)}
/>
<TextField
id="classification-field"
Expand All @@ -84,7 +172,7 @@ function CaseRow(props) {
label="Classification"
value={classification}
SelectProps={{ native: true }}
onChange={e => setClassification(e.target.value)}
onChange={e => persistClassification(e.target.value)}
margin="normal"
>
<option key="" value=""></option>
Expand All @@ -100,14 +188,14 @@ function CaseRow(props) {
autoComplete="off"
label="Description"
value={description}
onChange={e => setDescription(e.target.value)}
onChange={e => persistDescription(e.target.value)}
margin="normal"
/>
<FormControlLabel
control={
<Switch
checked={papered}
onChange={e => setPapered(e.target.checked)}
onChange={e => persistPapered(e.target.checked)}
value="Papered"
inputProps={{ "aria-label": "Papered checkbox" }}
/>
Expand All @@ -118,7 +206,7 @@ function CaseRow(props) {
control={
<Switch
checked={isBRAFelony}
onChange={e => setIsBRAFelony(e.target.checked)}
onChange={e => persistIsBRAFelony(e.target.checked)}
value="ChargeIsBRAFelony"
inputProps={{ "aria-label": "ChargeIsBRAFelony checkbox" }}
/>
Expand All @@ -129,7 +217,7 @@ function CaseRow(props) {
control={
<Switch
checked={convicted}
onChange={e => setConvicted(e.target.checked)}
onChange={e => persistConvicted(e.target.checked)}
value="Convicted"
inputProps={{ "aria-label": "Convicted checkbox" }}
/>
Expand Down
100 changes: 63 additions & 37 deletions components/CaseTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import TextField from "@material-ui/core/TextField";
import { FormControlLabel } from "@material-ui/core";
import ComposedDatePicker from "./ComposedDatePicker.js";
import Switch from "@material-ui/core/Switch";
import Button from "@material-ui/core/Button";

// components
import CaseRow from "./CaseRow";
Expand Down Expand Up @@ -49,50 +50,76 @@ function CaseTable(props) {
const pushCharge = () => {
let chargeNum = Object.keys(value.caseData.case.charges).length + 1;
let newChargeKey = `Charge ${chargeNum}`;
persist(newChargeKey, value.chargeFormat);
// save all data, including new charge,
// to update display without changing original json caseContainer
let update = getUpdater();
update.caseData.case.charges[newChargeKey] = value.chargeFormat;
value.updater(update);
};

const persistEvaluatorName = name => {
value.updater({
caseData: {
...value.caseData,
evaluatorName: name,
case: {
...value.caseData.case
},
client: {
...value.caseData.client
}
}
});
setEvaluatorName(name);
let update = getUpdater();
update.caseData.evaluatorName = name;
value.updater(update);
};

const persistEvaluatorComments = comments => {
setComments(comments);
let update = getUpdater();
update.caseData.evaluatorComments = comments;
value.updater(update);
};

const persistTerminationDate = terminationDate => {
setTerminationDate(terminationDate);
let update = getUpdater();
update.caseData.case.terminationDate = terminationDate;
value.updater(update);
};

const persist = (newChargeKey, newCharge) => {
value.updater({
const persistClientName = clientName => {
setClientName(clientName);
let update = getUpdater();
update.caseData.client.name = clientName;
value.updater(update);
}

const persistOnProbation = isOnProbation => {
setOnProbation(isOnProbation);
let update = getUpdater();
update.caseData.client.isOnProbation = isOnProbation;
value.updater(update);
}

const persistPdId = pdId => {
setPdId(pdId);
let update = getUpdater();
update.caseData.client.pdId = pdId;
value.updater(update);
}

const getUpdater = () => {
return {
caseData: {
...value.caseData,
evaluatorName: evaluatorName,
evaluatorComments: comments,
case: {
...value.caseData.case,
charges: {
...value.caseData.case.charges,
[newChargeKey]: newCharge
},
terminationDate: terminationDate
},
client: {
...value.caseData.client,
dob: birthDate,
isOnProbation: isOnProbation,
name: clientName,
pdId: pdId
}
}
});
};
};
}

const persistBirthDate = dob => {
setBirthDate(dob);
let update = getUpdater();
update.caseData.client.dob = dob;
value.updater(update);
}

return (
<Card>
Expand All @@ -104,7 +131,6 @@ function CaseTable(props) {
label="Evaluator Name"
value={evaluatorName}
onChange={e => {
setEvaluatorName(e.target.value);
persistEvaluatorName(e.target.value);
}}
/>
Expand All @@ -113,23 +139,23 @@ function CaseTable(props) {
multiline
value={comments}
onChange={e => {
setComments(e.target.value);
persistEvaluatorComments(e.target.value);
}}
/>
<TextField
label="Client Name"
autoComplete="off"
value={clientName}
onChange={e => {
setClientName(e.target.value);
persistClientName(e.target.value);
}}
/>
<FormControlLabel
control={
<Switch
checked={isOnProbation}
onChange={e => {
setOnProbation(e.target.checked);
persistOnProbation(e.target.checked);
}}
inputProps={{ "aria-label": "isOnProbation checkbox" }}
/>
Expand All @@ -141,33 +167,33 @@ function CaseTable(props) {
autoComplete="off"
value={pdId}
onChange={e => {
setPdId(e.target.value);
persistPdId(e.target.value);
}}
/>
<ComposedDatePicker
label={"Client DOB"}
hoist={e => {
setBirthDate(e);
persistBirthDate(e);
}}
initialDate={birthDate}
/>
<ComposedDatePicker
label={"Case Terminated On"}
hoist={e => {
setTerminationDate(e);
persistTerminationDate(e);
}}
initialDate={terminationDate}
/>
</Grid>

{/* Cases in Context object */}
<div>
{Object.keys(charges).map((charge, idx) => {
{Object.keys(charges).map((chargeKey, idx) => {
return (
<CaseRow
charge={charge}
title={chargeKey}
terminationDate={terminationDate}
key={`${idx}-charge`}
charges={value.caseData.case.charges}
/>
);
})}
Expand Down
Loading