-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
feat: new UX for submitting changes #224
Changes from 3 commits
85925a5
ae4d806
65fbd8a
6e597f7
0d5d7d1
bd330f5
c53ab42
976577e
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,11 +1,13 @@ | ||
import { Alert, Box, Button, Snackbar, Typography } from "@mui/material"; | ||
import { Alert, Box, Snackbar, Typography, Button } from "@mui/material"; | ||
import SaveIcon from "@mui/icons-material/Save"; | ||
import { useEffect, useState } from "react"; | ||
import useFetch from "../../components/useFetch"; | ||
import ListEntryParents from "./ListEntryParents"; | ||
import ListEntryChildren from "./ListEntryChildren"; | ||
import ListTranslations from "./ListTranslations"; | ||
import ListAllEntryProperties from "./ListAllEntryProperties"; | ||
import ListAllNonEntryInfo from "./ListAllNonEntryInfo"; | ||
import equal from "fast-deep-equal"; | ||
import { createURL, getIdType } from "./createURL"; | ||
|
||
/** | ||
|
@@ -29,8 +31,19 @@ const AccumulateAllComponents = ({ id, taxonomyName, branchName }) => { | |
errorMessage, | ||
} = useFetch(url); | ||
const [nodeObject, setNodeObject] = useState(null); // Storing updates to node | ||
const [originalNodeObject, setOriginalNodeObject] = useState(null); // For tracking changes | ||
const [updateChildren, setUpdateChildren] = useState([]); // Storing updates of children in node | ||
const [open, setOpen] = useState(false); // Used for Dialog component | ||
const [changesMade, setChangesMade] = useState(false); // Used for displaying Fab | ||
|
||
// Tracking changes | ||
useEffect(() => { | ||
if (nodeObject && originalNodeObject) { | ||
const changesMade = | ||
!equal(nodeObject, originalNodeObject) || updateChildren.length !== 0; | ||
setChangesMade(changesMade); | ||
} | ||
}, [nodeObject, originalNodeObject, updateChildren]); | ||
|
||
// Setting state of node after fetch | ||
useEffect(() => { | ||
|
@@ -54,6 +67,7 @@ const AccumulateAllComponents = ({ id, taxonomyName, branchName }) => { | |
}); | ||
} | ||
setNodeObject(duplicateNode); | ||
setOriginalNodeObject(JSON.parse(JSON.stringify(duplicateNode))); // Deep copy | ||
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. Why do we need the |
||
}, [node]); | ||
|
||
// Displaying error messages if any | ||
|
@@ -107,6 +121,7 @@ const AccumulateAllComponents = ({ id, taxonomyName, branchName }) => { | |
) | ||
.then(() => { | ||
setOpen(true); | ||
setChangesMade(false); | ||
}) | ||
.catch(() => {}); | ||
}; | ||
|
@@ -128,6 +143,30 @@ const AccumulateAllComponents = ({ id, taxonomyName, branchName }) => { | |
nodeObject={nodeObject} | ||
setNodeObject={setNodeObject} | ||
/> | ||
{/* Fab for submitting edits */} | ||
{changesMade && ( | ||
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. Please change the variable name to |
||
<div | ||
style={{ | ||
backgroundColor: "white", | ||
position: "sticky", | ||
bottom: 0, | ||
zIndex: 1, | ||
}} | ||
> | ||
<Button | ||
onClick={handleSubmit} | ||
variant="contained" | ||
sx={{ | ||
marginTop: 2, | ||
marginBottom: 2, | ||
marginLeft: 4, | ||
}} | ||
> | ||
<SaveIcon sx={{ mr: 1 }} /> | ||
Save Changes | ||
</Button> | ||
</div> | ||
)} | ||
<ListAllEntryProperties | ||
nodeObject={nodeObject} | ||
setNodeObject={setNodeObject} | ||
|
@@ -145,14 +184,6 @@ const AccumulateAllComponents = ({ id, taxonomyName, branchName }) => { | |
/>{" "} | ||
</> | ||
)} | ||
{/* Button for submitting edits */} | ||
<Button | ||
variant="contained" | ||
onClick={handleSubmit} | ||
sx={{ ml: 4, mt: 2, width: 130, mb: 2 }} | ||
> | ||
Submit | ||
</Button> | ||
{/* Snackbar for acknowledgment of update */} | ||
<Snackbar | ||
anchorOrigin={{ vertical: "top", horizontal: "right" }} | ||
|
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.
We can probably name this to
isNewChange
?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.
what about
hasChanges