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

Adding calculator inputs #2343

Merged
merged 27 commits into from
Nov 1, 2023
Merged

Adding calculator inputs #2343

merged 27 commits into from
Nov 1, 2023

Conversation

OAGr
Copy link
Contributor

@OAGr OAGr commented Oct 18, 2023

Adds input types. Specifically, Text, TextArea, Checkbox, and Select. These now work in the calculator.

I think this is ready for a review. Depending on your take, this might almost be done, or might require a lot more work.

Some obvious things I'd want to spend more time on include:

  1. Move react select component to only exist in squiggle/ui, as a new component called StyledSelect.
  2. Add documentation and a few tests.
  3. Some more cleanup / refactoring.
image

@changeset-bot
Copy link

changeset-bot bot commented Oct 18, 2023

🦋 Changeset detected

Latest commit: 23a61c3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@quri/squiggle-lang Patch
@quri/squiggle-components Patch
@quri/prettier-plugin-squiggle Patch
vscode-squiggle Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@OAGr OAGr temporarily deployed to Preview October 18, 2023 23:25 — with GitHub Actions Inactive
@vercel
Copy link

vercel bot commented Oct 18, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
quri-hub ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 1, 2023 9:07pm
squiggle-components ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 1, 2023 9:07pm
squiggle-website ✅ Ready (Inspect) Visit Preview Nov 1, 2023 9:07pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
quri-ui ⬜️ Ignored (Inspect) Visit Preview Nov 1, 2023 9:07pm

@codecov
Copy link

codecov bot commented Oct 19, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (87884e5) 71.63% compared to head (21e76da) 71.72%.
Report is 22 commits behind head on main.

❗ Current head 21e76da differs from pull request most recent head 23a61c3. Consider uploading reports for the commit 23a61c3 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2343      +/-   ##
==========================================
+ Coverage   71.63%   71.72%   +0.09%     
==========================================
  Files         111      113       +2     
  Lines        5704     5811     +107     
  Branches     1091     1117      +26     
==========================================
+ Hits         4086     4168      +82     
- Misses       1611     1636      +25     
  Partials        7        7              

see 18 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@berekuk berekuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a ~last big change to the calculators functionality in the next few weeks/months then I'm fine with merging this.

If you plan to add more complexity, i.e. field layouts, or something else that would require adding even more moving parts, then I'd prefer to make a pause here for refactoring, or do that refactoring first, to make things more manageable (not a problem if we don't delay this PR for this, and this seems solid enough for 0.8.6 release).

Specific cleanups I have in mind:

  • unifying input components (as I mentioned in one of the comments)
  • RHF
  • cleaning up the reducer part, as I hoped to do earlier during the first Calculators PR

input: (base) => ({
...base,
"input:focus": {
boxShadow: "none",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's to fix the blue rectangles.

packages/squiggle-lang/src/value/index.ts Outdated Show resolved Hide resolved
packages/squiggle-lang/src/value/index.ts Outdated Show resolved Hide resolved
packages/squiggle-lang/src/public/SqValue/SqScale.ts Outdated Show resolved Hide resolved
packages/squiggle-lang/src/public/SqValue/SqInput.ts Outdated Show resolved Hide resolved
packages/squiggle-lang/src/public/SqValue/SqInput.ts Outdated Show resolved Hide resolved
packages/squiggle-lang/src/fr/input.ts Outdated Show resolved Hide resolved
value: option,
label: option,
}))}
styles={{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several comments:

  1. There's probably nothing calculator-specific here, so this all belongs in StyledSelect or SelectFormField, as you mention in the description
  2. I'm not sure what all these styles do, but some of them make things worse, e.g. text is not centered:
Captura de pantalla 2023-10-20 a la(s) 12 54 14

(compare with https://quri-ui-git-calculator-inputs-quantified-uncertainty.vercel.app/?path=/story/ui-forms-selectstringformfield--default)

  1. In my impression this is getting complex enough that RHF would be useful, even if type-safety features of *Field components won't be available (because calculator fields are dynamic). But it's fine if you don't want to deal with it now.

Copy link
Contributor Author

@OAGr OAGr Oct 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give me some tips for making a StyledSelect? I'm not sure how to easily type all of the potential props (there are many).

I'm really only changing the styles, so it seems like maybe I could just export a variable for those styles, like,

StyledSelectStyles = {{input: ...}}

Or could you do some attempt here? Some of the code in the UI around this is fairly gnarly, mainly with the type system.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main thing the styles do is make this input consistent with other inputs; use purple instead of blue. It makes this "small", and this causes the non-centering. I'll improve this later on.

packages/components/src/lib/inputUtils.ts Outdated Show resolved Hide resolved
@OAGr
Copy link
Contributor Author

OAGr commented Oct 20, 2023

If this is a ~last big change to the calculators functionality in the next few weeks/months then I'm fine with merging this.

If you plan to add more complexity, i.e. field layouts, or something else that would require adding even more moving parts, then I'd prefer to make a pause here for refactoring, or do that refactoring first, to make things more manageable (not a problem if we don't delay this PR for this, and this seems solid enough for 0.8.6 release).


I don't have many changes really planned. Haven't thought much about field layouts yet - have no active proposal in mind.

I could definitely imagine adding another 1-3 input types. "TextWithUnit" is the main one I could see being tricky. "Slider" might accept a number instead of a string.

@berekuk
Copy link
Collaborator

berekuk commented Oct 20, 2023

I don't have many changes really planned. Haven't thought much about field layouts yet - have no active proposal in mind.
I could definitely imagine adding another 1-3 input types. "TextWithUnit" is the main one I could see being tricky. "Slider" might accept a number instead of a string.

Yeah, scaling input types horizontally is not a problem, I meant architectural complexity. Though some input types could require that, but "number" thing seems similar to "select is a string which needs to be quoted" thing that you did here and probably won't be hard.

@OAGr OAGr temporarily deployed to Preview November 1, 2023 21:02 — with GitHub Actions Inactive
@OAGr OAGr marked this pull request as ready for review November 1, 2023 21:04
@OAGr OAGr merged commit 021c8d6 into main Nov 1, 2023
3 checks passed
@OAGr OAGr deleted the Calculator-Inputs branch November 1, 2023 21:11
@github-actions github-actions bot mentioned this pull request Nov 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants