-
Notifications
You must be signed in to change notification settings - Fork 0
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 #40 from concord-consortium/188211532-edit-data-in…
…-nested-table feat: edit data in nested table (PT-188211532)
- Loading branch information
Showing
15 changed files
with
5,350 additions
and
2,440 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.editableTableCell { | ||
input { | ||
width: calc(100% - 8px); | ||
} | ||
} |
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,57 @@ | ||
import React, { ReactNode, useState } from "react"; | ||
import { Editable, EditablePreview, EditableInput } from "@chakra-ui/react"; | ||
import { updateCaseById } from "@concord-consortium/codap-plugin-api"; | ||
|
||
import css from "./editable-table-cell.scss"; | ||
|
||
interface IProps { | ||
attrTitle: string; | ||
caseId: string; | ||
children: ReactNode; | ||
handleUpdateCollections: () => void; | ||
selectedDataSetName: string; | ||
} | ||
|
||
export const EditableTableCell = (props: IProps) => { | ||
const { attrTitle, caseId, children, handleUpdateCollections, selectedDataSetName } = props; | ||
const displayValue = String(children); | ||
const [editingValue, setEditingValue] = useState(displayValue); | ||
const [isEditing, setIsEditing] = useState(false); | ||
|
||
const handleChangeValue = (newValue: string) => { | ||
setEditingValue(newValue); | ||
}; | ||
|
||
const handleCancel = () => { | ||
setEditingValue(displayValue); | ||
setIsEditing(false); | ||
}; | ||
|
||
const handleSubmit = async (newValue: string) => { | ||
try { | ||
await updateCaseById(selectedDataSetName, caseId, {[attrTitle]: newValue}); | ||
setEditingValue(newValue); | ||
setIsEditing(false); | ||
handleUpdateCollections(); | ||
} catch (e) { | ||
console.error("Case not updated: ", e); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className={css.editableTableCell}> | ||
<Editable | ||
isPreviewFocusable={true} | ||
onCancel={handleCancel} | ||
onChange={handleChangeValue} | ||
onEdit={() => setIsEditing(true)} | ||
onSubmit={handleSubmit} | ||
submitOnBlur={true} | ||
value={isEditing ? editingValue : displayValue} | ||
> | ||
{!isEditing && <EditablePreview />} | ||
<EditableInput /> | ||
</Editable> | ||
</div> | ||
); | ||
}; |
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
Oops, something went wrong.