Skip to content

Commit

Permalink
minimized the prop data for overridetable rows
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelPesce committed Jul 12, 2023
1 parent 1419ec5 commit 339ccbc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion electron/ui/src/components/OverrideTable/OverrideTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const renderOutputTable = () => {
</TableHead>
<OverrideTableRows
category={category}
data={data}
data={data[category].slice(1)}
rowNodes={rowNodes}
rowNodesMapping={rowNodesMapping}
columnNodes={columnNodes}
Expand Down
25 changes: 15 additions & 10 deletions electron/ui/src/components/OverrideTable/OverrideTableRows.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ return (
{category === "vb_y_overview_dict" ?

<TableBody>
{data[category].slice(1).map((value, index) => (
{data.map((value, index) => (
<BinaryVariableRow
key={`${value}_${index}`}
category={category}
Expand All @@ -85,7 +85,7 @@ return (
</TableBody>
:
<TableBody>
{data[category].slice(1).map((value, index) => {
{data.map((value, index) => {
if (Object.keys(rowNodes).length === 0 || rowNodes[rowNodesMapping[index]]) {
return (<TableRow key={`row_${value}_${index}`}>
{value.map((cellValue, i)=> {
Expand Down Expand Up @@ -157,6 +157,7 @@ function BinaryVariableRow(props) {
},
}
const [ showData, setShowData ] = useState(false)
const [ overrideChecked, setOverrideChecked ] = useState(null)
const [ rowName, setRowName ] = useState("")
const [ presetValues, setPresetValues ] = useState({})
const [ technology, setTechnology ] = useState(null)
Expand Down Expand Up @@ -197,14 +198,17 @@ function BinaryVariableRow(props) {
setRowName(value[0])
setPresetValues(preset_values)
setShowData(true)
}, [props])
}, [scenario, value])

useEffect(() => {
/*
Logic for creating dictionary with correct values for each infrastructure buildout row
*/
if(Object.keys(scenario.override_values[category]).includes(""+index)) setOverrideChecked(true)
else setOverrideChecked(false)

}, [scenario])

const getCheckboxValue = (index) => {
if(Object.keys(scenario.override_values[category]).includes(""+index)) {
return true
} else return false
}

const generateInfrastructureBuildoutValueOptions = (value, index) => {
if (Object.keys(OVERRIDE_PRESET_VALUES).includes(value[0])) {
Expand Down Expand Up @@ -286,15 +290,16 @@ return (
align={"left"}
key={"" + index + i}
style={i === 0 ? styles.firstCol : styles.other}>
{value[cellIdx].toLocaleString('en-US', {maximumFractionDigits:0})}
{value[cellIdx].toLocaleString('en-US', {maximumFractionDigits:0})
}
</TableCell>
)
)}
<TableCell
align="left"
style={styles.other}>
<Checkbox
checked={getCheckboxValue(index)}
checked={overrideChecked}
onChange={() => handleCheckOverride(index, value)}
/>
</TableCell>
Expand Down

0 comments on commit 339ccbc

Please sign in to comment.