Incorporate Circular Implementation#33
Conversation
…ation for the new circular model
…terfaces for defaultPlant and defaultProduct, imported idex.css as well
…om products to plants
…ustomize) all added
| centers: {}, | ||
|
|
||
|
|
||
| }); |
There was a problem hiding this comment.
Please reformat all source code files using prettier
| import "../Common/Forms/Tables.css"; | ||
| import Footer from "./Footer"; | ||
| import React, { useState,useRef } from "react"; | ||
| import {CircularData} from "./CircularData"; |
There was a problem hiding this comment.
There is no need to refer to everything as CircularSomething. This could be InstanceData instead.
| export interface CircularPlant { | ||
| uid: string; | ||
| name: string; | ||
| x: number; | ||
| y: number; | ||
| inputs: string[]; | ||
| outputs: string[]; | ||
|
|
||
|
|
||
| } | ||
|
|
||
| export interface CircularProduct { | ||
| uid: string; | ||
| name: string; | ||
| x: number; | ||
| y: number; | ||
| } | ||
|
|
||
| export interface CircularData { | ||
| plants: Record<string, CircularPlant>; | ||
| products: Record<string, CircularProduct>; | ||
| centers: Record<string, CircularCenter>; | ||
|
|
||
|
|
||
| } | ||
|
|
||
| export interface CircularCenter { | ||
| uid: string; | ||
| name: string; | ||
| x: number; | ||
| y: number; | ||
|
|
||
| //single input, multiple outputs | ||
| input?: string; | ||
| output: string[]; | ||
| } No newline at end of file |
There was a problem hiding this comment.
Instead of having these isolated data structures in a custom format, could you modify this code so that we have a single structure containing the entire data for the test case, in the JSON format we describe in our documentation? See UnitCommitmentScenario in the UCJL case builder for an example. Each operation in the web interface (such as adding a plant) should modify this data structure while ensuring that the JSON format remains in a valid format. This is also important because we should be able to load/save the test case.
Feel free to add any necessary fields to the JSON format required to persist the pipeline visualization (e.g., x/y location of each copy of that component).
There was a problem hiding this comment.
Added RELOGScenario interface that uses the current interfaces as shapes and combines them into one
| const randomPosition = (): [number,number] => { | ||
| if (window.nextX === undefined) window.nextX = 15; | ||
| if (window.nextY === undefined) window.nextY = 15; | ||
|
|
||
| window.nextY +=60; | ||
| if (window.nextY >=500) { | ||
| window.nextY = 15; | ||
| window.nextX += 150; | ||
|
|
||
| } | ||
| return [window.nextX, window.nextY]; | ||
|
|
||
| }; |
There was a problem hiding this comment.
Could you rename this method? It's not really generating a random position.
There was a problem hiding this comment.
Taken from current casebuilder, changed to nextNodePosition
| const onAddPlant = () => { | ||
| setCircularData((prevData) => { | ||
| const name = promptName(prevData); | ||
| if (name ===undefined) return prevData; | ||
|
|
||
| const uid = `${name}-${nextUid.current++}`; | ||
| const [x,y] = randomPosition(); | ||
| const newData: CircularData = { | ||
| ...prevData, | ||
| plants: { | ||
| ...prevData.plants, | ||
| [uid]: { | ||
| ...defaultPlant, | ||
| x, | ||
| y, | ||
| name, | ||
| uid | ||
| } | ||
| } | ||
| }; | ||
| return newData; | ||
| }); | ||
| }; | ||
|
|
||
| const onAddProduct = () => { | ||
| setCircularData((prevData) => { | ||
| const name = promptName(prevData); | ||
| if (name ===undefined) return prevData; | ||
| const uid = `${name}-${nextUid.current++}`; | ||
| const [x,y] = randomPosition(); | ||
| const newData: CircularData = { | ||
| ...prevData, | ||
| products: { | ||
| ...prevData.products, | ||
| [uid]: { | ||
| ...defaultProduct, | ||
| x, | ||
| y, | ||
| name, | ||
| uid | ||
| } | ||
| } | ||
| }; | ||
| return newData; | ||
| }); | ||
|
|
||
| }; | ||
|
|
||
| const onAddCenter = () => { | ||
| setCircularData((prevData) => { | ||
| const name = promptName(prevData); | ||
| if (name ===undefined) return prevData; | ||
| const uid = `${name}-${nextUid.current++}`; | ||
| const [x,y] = randomPosition(); | ||
| const newData: CircularData = { | ||
| ...prevData, | ||
| centers: { | ||
| ...prevData.centers, | ||
| [uid]: { | ||
| ...defaultCenter, | ||
| x, | ||
| y, | ||
| name, | ||
| uid | ||
| } | ||
| } | ||
| }; | ||
| return newData; | ||
| }); | ||
| }; |
There was a problem hiding this comment.
This logic was taken from the current casebuilder but you are right and there shouldn't be a reason why these can be connected to 'onAdd' function
There was a problem hiding this comment.
Consolidated to onAddNode function
| <button style={{ margin: '0 8px' }} onClick={props.onAddProduct}>Add product</button> | ||
| <button style={{ margin: '0 8px' }} onClick={props.onAddPlant}>Add plant</button> | ||
| <button style={{ margin: '0 8px' }} onClick={props.onAddCenter}>Add center</button> | ||
| <button style={{ margin: '0 8px' }} onClick={onLayout}>Auto Layout</button> |
There was a problem hiding this comment.
Please use a common style for these buttons. I think we already have some CSS for buttons that you could use here.
There was a problem hiding this comment.
Incorporated Buttons.module.css file from current casebuilder
| <button style={{ margin: '0 8px' }} onClick={props.onAddCenter}>Add center</button> | ||
| <button style={{ margin: '0 8px' }} onClick={onLayout}>Auto Layout</button> | ||
| <DownloadButton /> | ||
| <button style={{ margin: '0 8px' }} title="Drag & connect. Double-click to rename. Delete to remove.">?</button> |
There was a problem hiding this comment.
This tooltip is not working properly. Compared to the one in relog.axavier.org, it takes too long to show.
| export interface DefaultProduct extends CircularProduct{ | ||
| x: number; | ||
| y: number; | ||
| } | ||
|
|
||
| export interface DefaultPlant extends CircularPlant{ | ||
| x: number; | ||
| y: number; | ||
| } | ||
|
|
||
| export interface DefaultCenter extends CircularPlant{ | ||
| x: number; | ||
| y: number; | ||
| } |
There was a problem hiding this comment.
I don't see the need to declare these interfaces. They are also duplicated.
There was a problem hiding this comment.
These interfaces are the "objects" for the state while the interfaces in CircularData (now InitialData) are purely types.
| "noUnusedParameters": false, | ||
| "checkJs": true | ||
| "checkJs": false, | ||
| "allowImportingTsExtensions": true |
There was a problem hiding this comment.
Could you clarify why is this required?
There was a problem hiding this comment.
Anything updated in the tsconfig file was updated on the download of any libraries used, if you want I can take a deeper dive but I never went in and messed with it.
| "noUnusedLocals": false, | ||
| "noUnusedParameters": false, | ||
| "checkJs": true | ||
| "checkJs": false, |
There was a problem hiding this comment.
We shouldn't have any .js files in this project, so I'm not sure why is this change required.
There was a problem hiding this comment.
Yes definetely, I'll take this out. I know that having it set as false raised a type warning earlier in the code that I wasn't able to get rid of and it was fully typed but if any issues arise now I'll make note of them and let you know.
There was a problem hiding this comment.
checkJs works simultaneously with allowJs, if checkJs is set to true then allowJs has to true as well otherwise it raises errors.
Created an interface in the CircularData.ts file to add some sort of organization for building out the circular model, if you have another idea I'd be happy to go with that!