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

Show error if locked line has length 0 #1277

Merged
merged 4 commits into from
May 21, 2024
Merged

Show error if locked line has length 0 #1277

merged 4 commits into from
May 21, 2024

Conversation

nishasy
Copy link
Contributor

@nishasy nishasy commented May 15, 2024

Summary:

It doesn't make sense for a locked line to have length 0, so
I'm adding an error message if the user were to set the two
points to the same value.

Implementation notes/questions:

  • I really tried to use WB TextField validate for this, but it
    was extremely convoluted to get the four text fieds to stay in
    sync. Or even to keep two of them in sync. If it has the error
    in one, but you update it in the other point, it would just
    not update the original error. I sort of used a manual state
    for this instead and replicated the style. It's much easier
    and cleaner this way.
  • This implementation does not stop the graph from receiving
    a line with the same two defining points. Is that something
    worth doing? I'd have to change where the error gets set,
    but it's doable.

Issue: https://khanacademy.atlassian.net/browse/LEMS-1991

Test plan:

yarn jest packages/perseus-editor/src/components/__tests__/locked-line-settings.test.tsx

Storybook
http://localhost:6006/?path=/story/perseuseditor-components-locked-line-settings--controlled

Demo

Screen.Recording.2024-05-15.at.3.50.56.PM.mov

@nishasy nishasy self-assigned this May 15, 2024
@nishasy nishasy requested review from mark-fitzgerald, jeremyspangler, benchristel, a team and jeremywiebe and removed request for jeremyspangler May 15, 2024 22:52
Copy link
Contributor

github-actions bot commented May 15, 2024

Size Change: +119 B (+0.01%)

Total Size: 839 kB

Filename Size Change
packages/perseus-editor/dist/es/index.js 268 kB +143 B (+0.05%)
packages/perseus/dist/es/index.js 403 kB -24 B (-0.01%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 38.1 kB
packages/kmath/dist/es/index.js 4.27 kB
packages/math-input/dist/es/index.js 80.5 kB
packages/math-input/dist/es/strings.js 1.73 kB
packages/perseus-core/dist/es/index.js 908 B
packages/perseus-error/dist/es/index.js 877 B
packages/perseus-linter/dist/es/index.js 21.8 kB
packages/perseus/dist/es/strings.js 3.22 kB
packages/pure-markdown/dist/es/index.js 3.68 kB
packages/simple-markdown/dist/es/index.js 12.4 kB

compressed-size-action

@nishasy nishasy marked this pull request as ready for review May 15, 2024 22:58
@khan-actions-bot
Copy link
Contributor

khan-actions-bot commented May 15, 2024

Gerald

Required Reviewers
  • @Khan/perseus for changes to .changeset/thirty-bugs-march.md, packages/perseus-editor/src/components/coordinate-pair-input.tsx, packages/perseus-editor/src/components/defining-point-settings.tsx, packages/perseus-editor/src/components/locked-line-settings.tsx, packages/perseus-editor/src/components/__stories__/locked-line-settings.stories.tsx, packages/perseus-editor/src/components/__tests__/locked-line-settings.test.tsx

Don't want to be involved in this pull request? Comment #removeme and we won't notify you of further changes.

Copy link

codecov bot commented May 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.28%. Comparing base (e14a003) to head (c3a157e).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1277      +/-   ##
==========================================
+ Coverage   68.81%   70.28%   +1.47%     
==========================================
  Files         477      481       +4     
  Lines      101842   101960     +118     
  Branches     7213    10300    +3087     
==========================================
+ Hits        70082    71667    +1585     
+ Misses      31581    30293    -1288     
+ Partials      179        0     -179     

Impacted file tree graph

Files Coverage Δ
...us-editor/src/components/coordinate-pair-input.tsx 100.00% <100.00%> (ø)
...-editor/src/components/defining-point-settings.tsx 100.00% <100.00%> (+9.16%) ⬆️
...eus-editor/src/components/locked-line-settings.tsx 100.00% <100.00%> (ø)

... and 141 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e14a003...c3a157e. Read the comment docs.

Copy link
Collaborator

@jeremywiebe jeremywiebe left a comment

Choose a reason for hiding this comment

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

I don't have any concerns with the code, but showing 2 errors for the same issue feels off to me. It also causes quite a bit of junk as they are shown/hidden. I wonder if we could put the error above the two points. It really is an issue with the line and not the individual locked points.

Also, the editor system has a way to generate errors to block saving via the getSaveWarnings() function. Any widget editor can implement that and return an array of strings representing the issues. Webapp will then prevent saving if the top-level function returns any issues. I'd recommend doing that here so that we do more than simply render an error, we actually block saving.

@nishasy
Copy link
Contributor Author

nishasy commented May 16, 2024

@jeremywiebe

showing 2 errors for the same issue feels off to me. It also causes quite a bit of junk as they are shown/hidden. I wonder if we could put the error above the two points

That makes sense to me. I'll move the error. Do you think it still makes sense to highlight those four text fields in red so it's apparent which inputs are related to the error?

image

@jeremywiebe
Copy link
Collaborator

@jeremywiebe

showing 2 errors for the same issue feels off to me. It also causes quite a bit of junk as they are shown/hidden. I wonder if we could put the error above the two points

That makes sense to me. I'll move the error. Do you think it still makes sense to highlight those four text fields in red so it's apparent which inputs are related to the error?

image

Nice. I think that's much better. It still highlights the fields that contribute to the error state, but it's not so "loud". :)

Copy link
Contributor

github-actions bot commented May 17, 2024

npm Snapshot: Published

Good news!! We've packaged up the latest commit from this PR (c3a157e) and published it to npm. You
can install it using the tag PR1277.

Example:

yarn add @khanacademy/perseus@PR1277

If you are working in Khan Academy's webapp, you can run:

./dev/tools/bump_perseus_version.sh -t PR1277

Copy link
Member

@benchristel benchristel left a comment

Choose a reason for hiding this comment

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

LGTM! Just one question inline about i18n.

@@ -26,6 +26,8 @@ import type {
LockedPointType,
} from "@khanacademy/perseus";

const lengthZeroStr = "The line cannot have length 0.";
Copy link
Member

Choose a reason for hiding this comment

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

This string doesn't need to be added to PerseusStrings for translation, does it? Do we have a policy of not doing i18n for the editor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did a quick search, and it doesn't look like any of the editor strings are translated anywhere else.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Confirmed. We don't translate the content editor.

@nishasy nishasy merged commit f8539c8 into main May 21, 2024
12 of 13 checks passed
@nishasy nishasy deleted the line-length branch May 21, 2024 21:19
benchristel pushed a commit that referenced this pull request May 21, 2024
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.


# Releases
## @khanacademy/perseus@22.6.0

### Minor Changes

-   [#1293](#1293) [`e14a003be`](e14a003) Thanks [@benchristel](https://github.com/benchristel)! - Fill Mafs interactive circles with blue on hover


-   [#1241](#1241) [`a0dfc66cc`](a0dfc66) Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - New Axis Tick Labels and Ticks that can render outside of graph bounds

### Patch Changes

-   [#1289](#1289) [`42c0c607f`](42c0c60) Thanks [@benchristel](https://github.com/benchristel)! - Internal: replace some brittle SVG snapshot tests with less brittle visual snapshot tests


-   [#1271](#1271) [`55039a430`](55039a4) Thanks [@mark-fitzgerald](https://github.com/mark-fitzgerald)! - Bugfix: Arrowhead Rotation Was Incorrect on Some Graphs


-   [#1295](#1295) [`f6be03dd8`](f6be03d) Thanks [@benchristel](https://github.com/benchristel)! - Fix a bug where the arrow at the end of a line or ray would sometimes point to the origin and not the edge of the graph


-   [#1294](#1294) [`fba227fe8`](fba227f) Thanks [@benchristel](https://github.com/benchristel)! - Fix a bug where axis tick labels on Mafs interactive graphs could be selected and interfere with drag interactions


-   [#1255](#1255) [`dc0adedeb`](dc0aded) Thanks [@mark-fitzgerald](https://github.com/mark-fitzgerald)! - Ensure that axis lines and arrowheads have a 2px thickness in Interactive Graphs


-   [#1264](#1264) [`d70fab6a7`](d70fab6) Thanks [@mark-fitzgerald](https://github.com/mark-fitzgerald)! - Show Radio Widget Images on New Line


-   [#1285](#1285) [`5b52a1569`](5b52a15) Thanks [@benchristel](https://github.com/benchristel)! - Internal: refactor the code for initializing linear graph states

## @khanacademy/perseus-editor@6.5.0

### Minor Changes

-   [#1277](#1277) [`f8539c880`](f8539c8) Thanks [@nishasy](https://github.com/nishasy)! - Shows error in the editor if locked line has length 0


-   [#1284](#1284) [`8534a9f01`](8534a9f) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Add ToggleableCaret component and use in TexErrorView

### Patch Changes

-   [#1287](#1287) [`d9b51dcc0`](d9b51dc) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Interactive Graph Editor: Make the common graph settings a collapsable panel


-   [#1278](#1278) [`fffd130db`](fffd130) Thanks [@nishasy](https://github.com/nishasy)! - Nit: put the line kind dropdown options in alphabetical order


-   [#1280](#1280) [`5b1e04abc`](5b1e04a) Thanks [@nishasy](https://github.com/nishasy)! - Fix the bug where the first added locked figure settings would be collapsed when it's supposed to be expanded on add

-   Updated dependencies \[[`e14a003be`](e14a003), [`42c0c607f`](42c0c60), [`55039a430`](55039a4), [`f6be03dd8`](f6be03d), [`fba227fe8`](fba227f), [`dc0adedeb`](dc0aded), [`a0dfc66cc`](a0dfc66), [`d70fab6a7`](d70fab6), [`5b52a1569`](5b52a15)]:
    -   @khanacademy/perseus@22.6.0

## @khanacademy/perseus-dev-ui@1.5.8

### Patch Changes

-   [#1291](#1291) [`cceca19c7`](cceca19) Thanks [@benchristel](https://github.com/benchristel)! - Update dependency versions


-   [#1290](#1290) [`d41feb9be`](d41feb9) Thanks [@benchristel](https://github.com/benchristel)! - Internal: upgrade to @khanacademy/wonder-blocks-timing@5 in dev UI

Author: khan-actions-bot

Reviewers: benchristel

Required Reviewers:

Approved By: benchristel

Checks: ✅ codecov/project, ✅ codecov/patch, ✅ Upload Coverage (ubuntu-latest, 20.x), ⏭️  Publish npm snapshot, ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Jest Coverage (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ gerald

Pull Request URL: #1279
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants