Skip to content
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

Add ability to configure model options from the GUI #90

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

This repository is for work on the user interface (UI) for the WaterTAP library. The UI installer can be downloaded from our homepage at: https://watertap-org.github.io/

The core WaterTAP repository is at https://github.com/watertap-org/watertap

## Getting started (developer)

### Prerequisites
Expand Down Expand Up @@ -149,4 +151,4 @@ npm run dist:win
```console
cd <watertap-ui-path>/electron
npm run dist:mac
```
```
2 changes: 2 additions & 0 deletions backend/app/routers/flowsheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ async def get_config(id_: str, build: str = "0") -> FlowsheetExport:
if not info.built:
flowsheet.build()
info.updated(built=True)
print(f"@@ getConfig: fs_exp keys = {list(flowsheet.fs_exp.dict().keys())}")
print(f"@@ getConfig: fs_exp = {flowsheet.fs_exp.json()}")
return flowsheet.fs_exp


Expand Down
114 changes: 114 additions & 0 deletions electron/ui/src/components/FlowsheetOptions/FlowsheetOptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// React base
import React from 'react';
import {useEffect, useState} from 'react';
// MUI components
import Accordion from '@mui/material/Accordion';
import AccordionSummary from '@mui/material/AccordionSummary';
import Box from '@mui/material/Box';
import Tooltip from '@mui/material/Tooltip';
import TextField from '@mui/material/TextField';
import Typography from '@mui/material/Typography';
/* import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; */

/**
* FlowsheetOptions component.
*
* Create a box showing the flowsheet options, which users can edit to set
* new values.
*
* Assume that there actually *are* options to display in the component.
*
* @param props
* @returns {JSX.Element}
* @constructor
*/
export default function FlowsheetOptions({data}) {
console.info("All data =>", data);
let options = data.options;
console.info("Option data =>", options);
// Whether the values have changed
const [changed, setChanged] = useState(false);

// XXX: For accordion open/close
const [expanded, setExpanded] = useState(false);
// XXX: For accordion open/close
const handleAccordionChange = (panel) => (event, isExpanded) => {
setExpanded(isExpanded);
};

/**
* Convert input value to type specified in 't', which may be one of:
* 's' - string (no conversion)
* 'i' - integer
* 'f' - float
*
* @returns {String|Number}
*/
const convertValue = (v, t) => {
let cv = null;
switch (t) {
case 's':
cv = v;
break;
case 'i':
cv = parseInt(v);
break;
case 'f':
cv = parseFloat(v);
break;
default:
console.warning('Unknown type code: "' + t + '": not converting value:',v)
cv = v;
}
return cv;
}

/**
* Render all the flowsheet options for inclusion in an Accordion parent component.
* This is the main work of this component.
*
* @returns {JSX.Element}
*/
const renderOptionItems = () => {
let optionItems = Array();
for (const [key, opt] of Object.entries(options)) {
// create setOption function for this option
const setOption = (value) => {
if (value != opt.value) {
opt.value = value;
setChanged(true);
}
}
// create and add a new TextField to the list
optionItems.push(
<Tooltip
title={
<React.Fragment>
<Typography variant="body1">{opt.description}</Typography>
<Typography variant="body2">{opt.long_description}</Typography>
</React.Fragment>
}>
<TextField
id={key}
label={opt.display_name}
variant="outlined"
value={opt.value}
onChange={(event) => {
setOption(event.target.value);
}} />
</Tooltip>
);
}
// Put a Box around all the TextField components
return <Box>{optionItems}</Box>
}

// Create and return an Accordion component with the option items inside it
return (
<Accordion defaultExpanded="{true}">
<AccordionSummary>Flowsheet options</AccordionSummary>
{renderOptionItems()}
</Accordion>
)

}
11 changes: 8 additions & 3 deletions electron/ui/src/views/FlowsheetConfig/ConfigInput/ConfigInput.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

import React from 'react';
import {useEffect, useState } from 'react';
import InputAccordion from "../../../components/InputAccordion/InputAccordion";
import InputAccordion from "../../../components/InputAccordion/InputAccordion";
import FlowsheetOptions from "../../../components/FlowsheetOptions/FlowsheetOptions";
import { loadConfig, listConfigNames } from '../../../services/output.service.js'
import { useParams } from "react-router-dom";
import { deleteConfig } from '../../../services/input.service.js'
Expand Down Expand Up @@ -222,8 +223,7 @@ export default function ConfigInput(props) {
}

};



return (
<>
<Toolbar spacing={2}>
Expand Down Expand Up @@ -274,6 +274,11 @@ export default function ConfigInput(props) {
</Stack>
</Toolbar>

<Grid container spacing={2} alignItems="flex-start">
<Grid item xs={6} key="flowsheet-options">
<FlowsheetOptions data={flowsheetData.inputData} />
</Grid>
</Grid>

<Grid container spacing={2} alignItems="flex-start">
{
Expand Down