-
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 #24 from BoostV/feature/editable_data_points
Feature/editable data points
- Loading branch information
Showing
12 changed files
with
899 additions
and
127 deletions.
There are no files selected for viewing
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,39 @@ | ||
import { FormControl, MenuItem, Select, TableCell, TextField } from "@material-ui/core" | ||
import { ChangeEvent } from "react" | ||
|
||
type EditableTableCellProps = { | ||
value: string | ||
isEditMode: boolean | ||
options?: string[] | ||
onChange: (value: string) => void | ||
} | ||
|
||
export function EditableTableCell(props: EditableTableCellProps) { | ||
const { value, isEditMode, options, onChange } = props | ||
|
||
return ( | ||
<> | ||
{isEditMode ? | ||
<TableCell> | ||
{options && options.length > 0 ? | ||
<FormControl> | ||
<Select | ||
value={value} | ||
onChange={(e: ChangeEvent<any>) => onChange(e.target.value as string)} | ||
displayEmpty | ||
inputProps={{ 'aria-label': 'select value' }}> | ||
{options.map((item, i) => <MenuItem key={i} value={item}>{item}</MenuItem>)} | ||
</Select> | ||
</FormControl> | ||
: | ||
<TextField | ||
value={value} | ||
onChange={(e: ChangeEvent) => onChange("" + (e.target as HTMLInputElement).value)}/> | ||
} | ||
</TableCell> | ||
: | ||
<TableCell>{value}</TableCell> | ||
} | ||
</> | ||
) | ||
} |
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,82 @@ | ||
import { IconButton, Table, TableBody, TableCell, TableHead, TableRow } from "@material-ui/core" | ||
import { EditableTableCell } from "./editable-table-cell" | ||
import EditIcon from "@material-ui/icons/Edit" | ||
import CheckCircleIcon from "@material-ui/icons/CheckCircle" | ||
import CancelIcon from "@material-ui/icons/Cancel" | ||
import AddIcon from "@material-ui/icons/Add" | ||
import DeleteIcon from "@material-ui/icons/Delete"; | ||
import { TableDataRow } from "../types/common"; | ||
|
||
type EditableTableProps = { | ||
rows: TableDataRow[] | ||
useArrayForValue: string | ||
onEdit: (editValue: string, rowIndex: number, itemIndex: number) => void | ||
onEditConfirm: (row: TableDataRow, rowIndex: number) => void | ||
onEditCancel: (rowIndex: number) => void | ||
onToggleEditMode: (rowIndex: number) => void | ||
onDelete: (rowIndex: number) => void | ||
} | ||
|
||
export function EditableTable(props: EditableTableProps) { | ||
const { rows, useArrayForValue, onEdit, onEditConfirm, onEditCancel, onToggleEditMode, onDelete } = props | ||
|
||
return ( | ||
<Table size="small"> | ||
<TableHead> | ||
<TableRow> | ||
{rows[0].dataPoints.map((item, index) => | ||
<TableCell key={index}>{item.name}</TableCell> | ||
)} | ||
<TableCell /> | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{rows.map((row, rowIndex) => | ||
<TableRow key={rowIndex}> | ||
{row.dataPoints.map((item, itemIndex) => | ||
<EditableTableCell | ||
key={itemIndex} | ||
value={item.name === useArrayForValue ? item.value[0] : item.value} | ||
isEditMode={row.isEditMode} | ||
options={item.options} | ||
onChange={(value: string) => onEdit(value, rowIndex, itemIndex) }/> | ||
)} | ||
<TableCell key={rowIndex}> | ||
{row.isEditMode ? | ||
<> | ||
<IconButton | ||
size="small" | ||
aria-label="confirm edit" | ||
onClick={() => onEditConfirm(row, rowIndex)}> | ||
{row.isNew ? <AddIcon color="primary" /> : | ||
<CheckCircleIcon color="primary" />} | ||
</IconButton> | ||
<IconButton | ||
size="small" | ||
aria-label="cancle edit" | ||
onClick={() => onEditCancel(rowIndex)}> | ||
<CancelIcon color="primary" /> | ||
</IconButton> | ||
</> : | ||
<> | ||
<IconButton | ||
size="small" | ||
aria-label="toggle edit" | ||
onClick={() => onToggleEditMode(rowIndex)}> | ||
<EditIcon color="primary" /> | ||
</IconButton> | ||
<IconButton | ||
size="small" | ||
aria-label="delete" | ||
onClick={() => onDelete(rowIndex)}> | ||
<DeleteIcon color="primary" /> | ||
</IconButton> | ||
</> | ||
} | ||
</TableCell> | ||
</TableRow> | ||
)} | ||
</TableBody> | ||
</Table> | ||
) | ||
} |
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.