-
Notifications
You must be signed in to change notification settings - Fork 4
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
Enable address editing #1564
Enable address editing #1564
Changes from 18 commits
97a5d7c
59e25d7
27830ad
df19a3e
4b53edf
d017821
7f04709
d676094
c790a76
ef1a471
649fd11
3449372
830d348
9c13dd1
5cdda0d
3aeca4a
ec41697
4615121
f83f24e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import React from "react"; | ||
import React, { useState } from "react"; | ||
import { useQuery } from "@apollo/react-hooks"; | ||
import { useAuth0, isReadOnly } from "../auth/authContext"; | ||
import { formatCostToDollars, formatDateTimeString } from "../helpers/format"; | ||
|
@@ -33,13 +33,22 @@ const DataTable = ({ | |
const roles = getRoles(); | ||
const isReadOnlyUser = isReadOnly(roles); | ||
|
||
// Sets the state of the value for the current field being edited | ||
const [editValue, setEditValue] = useState(""); | ||
|
||
// Import Lookup tables and aggregate an object of uiType= "select" options | ||
const { data: lookupSelectOptions } = useQuery(GET_LOOKUPS); | ||
|
||
const handleEditClick = (field, fieldValue) => { | ||
setEditField(field); | ||
setEditValue(fieldValue ? fieldValue : ""); | ||
}; | ||
|
||
const handleCancelClick = e => { | ||
e.preventDefault(); | ||
|
||
setEditField(""); | ||
setEditValue(""); | ||
}; | ||
|
||
return ( | ||
|
@@ -55,6 +64,7 @@ const DataTable = ({ | |
<SwapAddressButton | ||
crash={data?.crash} | ||
crashRefetch={crashRefetch} | ||
setEditField={setEditField} | ||
/> | ||
)} | ||
</CardHeader> | ||
|
@@ -136,7 +146,9 @@ const DataTable = ({ | |
return ( | ||
<tr | ||
key={i} | ||
onClick={() => canClickToEdit && setEditField(field)} | ||
onClick={() => | ||
canClickToEdit && handleEditClick(field, fieldValue) | ||
} | ||
style={{ | ||
cursor: canClickToEdit ? "pointer" : "auto", | ||
}} | ||
|
@@ -158,12 +170,17 @@ const DataTable = ({ | |
autoFocus | ||
name={field} | ||
id={field} | ||
onChange={e => handleInputChange(e)} | ||
defaultValue={fieldValue} | ||
onChange={e => | ||
setEditValue(e.target.value) | ||
} | ||
value={editValue} | ||
type="select" | ||
> | ||
{selectOptions.map(option => ( | ||
johnclary marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<option value={option[`id`]}> | ||
<option | ||
value={option[`id`]} | ||
key={option["id"]} | ||
> | ||
{option[`label`]} | ||
</option> | ||
))} | ||
|
@@ -175,8 +192,12 @@ const DataTable = ({ | |
name={field} | ||
id={field} | ||
type="text" | ||
defaultValue={fieldValue} | ||
onChange={e => handleInputChange(e)} | ||
value={editValue} | ||
onChange={e => | ||
setEditValue( | ||
e.target.value.toUpperCase() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. auto capitalize user input |
||
) | ||
} | ||
autoComplete="off" | ||
// disable 1password autofill | ||
data-1p-ignore | ||
|
@@ -185,9 +206,11 @@ const DataTable = ({ | |
{fieldUiType === "boolean" && ( | ||
<Input | ||
autoFocus | ||
defaultValue={fieldValue} | ||
value={editValue} | ||
type="select" | ||
onChange={e => handleInputChange(e)} | ||
onChange={e => | ||
setEditValue(e.target.value) | ||
} | ||
> | ||
<option value={true}>YES</option> | ||
<option value={false}>NO</option> | ||
|
@@ -200,6 +223,9 @@ const DataTable = ({ | |
color="primary" | ||
size="sm" | ||
className="btn-pill mr-1" | ||
onClick={e => | ||
handleInputChange(editValue) | ||
} | ||
> | ||
<i className="fa fa-check edit-toggle" /> | ||
</Button> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,14 @@ import ConfirmModal from "../../Components/ConfirmModal"; | |
import { useMutation } from "@apollo/react-hooks"; | ||
import { UPDATE_CRASH } from "../../queries/crashes"; | ||
|
||
const SwapAddressButton = ({ crash, crashRefetch }) => { | ||
const SwapAddressButton = ({ crash, crashRefetch, setEditField }) => { | ||
const [isConfirmModalOpen, setIsConfirmModalOpen] = useState(false); | ||
|
||
const [updateCrash] = useMutation(UPDATE_CRASH); | ||
|
||
const toggleModal = () => { | ||
// make sure we are not in edit mode on a field | ||
setEditField(""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so that if we are in edit mode on a field and click the swap address button, we get out of edit mode |
||
setIsConfirmModalOpen(!isConfirmModalOpen); | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im updating all of these inputs to be controlled components instead of uncontrolled