-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1529 from cityofaustin/20328-update-team-table
Update Team table to update workgroup on user select
- Loading branch information
Showing
6 changed files
with
169 additions
and
13 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
moped-editor/src/components/DataGridPro/ViewOnlyTextField.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import React from "react"; | ||
import { TextField } from "@mui/material"; | ||
import { makeStyles } from "@mui/styles"; | ||
import { useGridApiContext } from "@mui/x-data-grid-pro"; | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
readOnlyInput: { | ||
width: "90%", | ||
paddingTop: "inherit", | ||
paddingLeft: theme.spacing(1), | ||
}, | ||
})); | ||
|
||
/** | ||
* @param {String} field - name of field | ||
* @param {Object} value - field value, should have an entry for the id and the corresponding string | ||
* @param {Integer} id - Data Grid row id (same as record id) | ||
* @param {Boolean} hasFocus - does this field have focus | ||
* @param {Boolean} usingShiftKey - if shift key is depressed | ||
* @param {string} previousColumnField - name of previous column in table | ||
* @param {string} nextColumnField - name of next column in table | ||
* @param {string} valueIdName - name of id key, ex: workgroup_id | ||
* @param {Object} lookupTable - mapping of lookup ids to their corresponding name | ||
* @return {JSX.Element} | ||
*/ | ||
const ViewOnlyTextField = ({ | ||
field, | ||
value, | ||
id, | ||
hasFocus, | ||
usingShiftKey, | ||
previousColumnField, | ||
nextColumnField, | ||
valueIdName, | ||
lookupTable, | ||
}) => { | ||
const ref = React.useRef(null); | ||
const apiRef = useGridApiContext(); | ||
const classes = useStyles(); | ||
|
||
// Because this field not editable, it cannot be focused and if a user is tabbing across the cells | ||
// the focus should be forwarded to the next one in the row | ||
React.useEffect(() => { | ||
if (hasFocus) { | ||
// Check if shift key is pressed, and user is trying to tab "backwards" | ||
if (usingShiftKey) { | ||
apiRef.current.setCellFocus(id, previousColumnField); | ||
} else { | ||
apiRef.current.setCellFocus(id, nextColumnField); | ||
} | ||
ref.current.focus(); | ||
} | ||
}, [ | ||
apiRef, | ||
hasFocus, | ||
id, | ||
usingShiftKey, | ||
nextColumnField, | ||
previousColumnField, | ||
]); | ||
|
||
return ( | ||
<TextField | ||
variant="standard" | ||
className={classes.readOnlyInput} | ||
id={field} | ||
inputRef={ref} | ||
name={field} | ||
type="text" | ||
value={lookupTable[value?.[valueIdName]] || ""} | ||
InputProps={{ readOnly: true, disableUnderline: true }} | ||
/> | ||
); | ||
}; | ||
|
||
export default ViewOnlyTextField; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters