-
Notifications
You must be signed in to change notification settings - Fork 5
Conversation
this.state = { | ||
argsValues: null, | ||
argsValidation: {}, | ||
argsValid: false, | ||
sortedArgKeys: null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this is now just this.props.uiSpec.order
I don't think it needs to be part of the state
anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a great start @emlys . It looks like the code & the spec files will all be getting simpler and easier to read, so that's great!
I had one minor comment on the spec itself. And then my other suggestion is to get the tests passing and then we can do another closer review of the changes from there. There are several tests that define UI specs and test the various functionalities. Ideally, those tests can be made passing just by updating their spec data.
"lulc_cur_path": {}, | ||
"calc_sequestration": { | ||
"ui_option": "disable", | ||
"ui_control": [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though I came up with them, these property names kinda trip me up, like I always have to pause and think about what they really mean.
ui_control
might be better as control_targets
because it holds an array of the args that are under control of calc_sequestration
. And ui_option
again is the option applied to the targets, not to the controller, so maybe better as control_option
? Those are just suggestions, feel free to go with whatever makes sense to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
control_targets
and control_option
sound good to me!
After working on this more, I'm thinking that the UI spec files should be required, but each arg in the spec file should be optional. Since the
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like this redesign! I left some miscellaneous comments inline to check out. And we should look into the failing puppeteer test. I can try to reproduce that on Windows if it's not easy for you to reproduce and debug.
And one more thought I had is about some sort of testing/validation for the json files since they are now required and things might break in unexpected ways if one is missing or malformed. Do you have any thoughts about this? I could imagine a CI step that just validates their structure without running any part of the React app. Or way at the other end of the spectrum, we could have puppeteer click on every model to see that it loads. Whatever we do I think it's okay to push it to a separate issue, maybe flagged with the beta release milestone.
src/components/SetupTab/index.jsx
Outdated
// invest model (e.g. Rec model's 'port' & 'hostname' args). | ||
if (argkey === 'n_workers' | ||
|| argsSpec[argkey].order === 'hidden') { return; } | ||
// Object.keys(argsSpec).forEach((argkey) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A leftover commented line here.
src/components/SetupTab/index.jsx
Outdated
@@ -83,18 +83,22 @@ function initializeArgValues(argsSpec, argsDict) { | |||
touched: !initIsEmpty, // touch them only if initializing with values | |||
}; | |||
}); | |||
return ({ argsValues: argsValues, argsValidation: argsValidation }); | |||
return ({ argsValues: argsValues }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call moving this argsValidation
initialization stuff out of this function and into the constructor.
Since we're only returning one object now, I think we can drop the nested structure here and just return argsValues
itself.
src/components/SetupTab/index.jsx
Outdated
// these argkeys do not get rendered inputs | ||
if (argkey === 'n_workers' | ||
|| argsSpec[argkey].order === 'hidden') { return; } | ||
let { argsValues } = initializeArgValues(argsSpec, uiSpec, argsInitValues || {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related to the comment about this functions return
, we probably won't need to "destructure" the returned value.
src/components/SetupTab/index.jsx
Outdated
// Update any dependent args in response to this arg's value | ||
// Update any dependent args in response to each arg's value | ||
// uiSpec.order is a 2D array so flatten it before iterating | ||
uiSpec.order.flat().forEach((argkey) => { | ||
const argumentSpec = { ...argsSpec[argkey] }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this line goes with all the stuff that was removed here, so it should go as well. It was only there to make all the subsequent references to argsSpec[argkey]
properties a little less verbose.
sortedGroup.map((item) => Object.values(item)[0]) | ||
); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sad to see this whole mess go! And pretty good evidence that the new design is the better design.
src/components/SetupTab/index.jsx
Outdated
const updatedArgsValues = toggleDependentInputs( | ||
this.props.argsSpec, argsValues, key | ||
this.props.uiSpec, argsValues, key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not mandatory, but here's a case where we could use destructuring to make things a little less verbose. const { uiSpec } = this.props;
I think eslint might suggest this, and I tend to do it in places where there are many this.props....
references.
@@ -0,0 +1,21 @@ | |||
# Explanation of UI spec JSON format |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice addition!
src/ui_data/README.md
Outdated
|
||
* `"control_option"`: A string that determines the CSS style to apply to this arg's input field, conditional | ||
on the state of the controlling field. If `"control_option": "x"`, then the style `arg-x` is applied. | ||
Currently `"disable"`, `"hide"`, and `"group"` are available. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think "group" is an option, is it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a .arg-group
class in styles.css, but I don't think we have a use for it at the moment. I'll take it out of the README
fileRegistry.INVEST_UI_DATA, `${spec.module}.json` | ||
); | ||
fs.writeFileSync(uiSpecFilePath, JSON.stringify(uiSpec)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will these files get cleaned up after the tests? We might want a beforeAll
and afterAll
functions to take care of that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the writeFileSync
into beforeAll
and added unlinkSync
to afterAll
@@ -340,18 +349,27 @@ describe('UI spec functionality', () => { | |||
args: { | |||
controller: { | |||
name: 'afoo', | |||
type: 'csv', | |||
ui_control: ['arg2'], | |||
type: 'csv' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few lines above where I can't leave a comment, there's a code comment that I think we can get rid of now.
Thanks for catching those miscellaneous things @davemfish. I agree some kind of validation would be good. Since a lot is changing in #84 as well I'd wait until both PRs are done. In general, I like your idea of clicking on each model to make sure it loads. |
The failing windows test error looks like this one: electron/electron#25267 |
Closing because all changes have been merged into #84. |
As discussed in #31, this PR refactors the UI spec "order" property into its own top-level attribute.