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

[Interactive Graph Editor] Add UI for updating starting coordinates (linear and ray) #1382

Merged
merged 19 commits into from
Jul 15, 2024

Conversation

nishasy
Copy link
Contributor

@nishasy nishasy commented Jun 27, 2024

Summary:

Implement a UI in the interactive graph editor to allow conten authors
to set custom starting coordinates for interactive graphs. This is a
prerequisite for hint mode.

Note: There was some funky stuff happening when I tried using coords.
I added a startCoords field to the graph types, and that seemed to fix
all my issues. This change is included in this PR.

Included in this PR

  • The creation of the StartCoordSettings component
  • The flag that this feature is behind
  • The UI itself, only for linear and ray graphs
  • Added startCoords field

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

Test plan:

Storybook existing starting coords

Storybook new graph

Copy/pasting

  • Press the "+ Add a hint" button at the bottom of the page
  • Copy/paste the interactive graph ("[[interactive-graph 1]]")
    into the hint text box
  • Confirm that the graph is copied correctly with the same
    start coords
  • Confirm that the "correct" preview is still interact-able and does not interfere with the start coords preview
  • Press "Use default start coords" and confirm it uses the start coords

Screenshot 2024-06-28 at 5 18 33 PM

@nishasy nishasy self-assigned this Jun 27, 2024
Copy link
Contributor

github-actions bot commented Jun 27, 2024

Size Change: +936 B (+0.11%)

Total Size: 854 kB

Filename Size Change
packages/perseus-editor/dist/es/index.js 273 kB +798 B (+0.29%)
packages/perseus/dist/es/index.js 414 kB +138 B (+0.03%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 38.2 kB
packages/kmath/dist/es/index.js 4.27 kB
packages/math-input/dist/es/index.js 80.8 kB
packages/math-input/dist/es/strings.js 1.73 kB
packages/perseus-core/dist/es/index.js 1.48 kB
packages/perseus-linter/dist/es/index.js 21.6 kB
packages/perseus/dist/es/strings.js 3.21 kB
packages/pure-markdown/dist/es/index.js 3.67 kB
packages/simple-markdown/dist/es/index.js 12.4 kB

compressed-size-action

@nishasy nishasy changed the title [Interactive Graph Editor] Add UI for updating starting coordinates (linear and ray) WIP!!!! [Interactive Graph Editor] Add UI for updating starting coordinates (linear and ray) Jun 28, 2024
@nishasy nishasy marked this pull request as ready for review June 28, 2024 22:22
@khan-actions-bot
Copy link
Contributor

khan-actions-bot commented Jun 28, 2024

Gerald

Required Reviewers
  • @Khan/perseus for changes to .changeset/chilly-planets-walk.md, packages/perseus/src/index.ts, packages/perseus/src/perseus-types.ts, packages/perseus/src/types.ts, packages/perseus-editor/src/__stories__/flags-for-api-options.ts, packages/perseus-editor/src/__stories__/interactive-graph-editor.stories.tsx, packages/perseus-editor/src/components/coordinate-pair-input.tsx, packages/perseus-editor/src/components/start-coord-settings.tsx, packages/perseus-editor/src/widgets/interactive-graph-editor.tsx, packages/perseus/src/widgets/interactive-graphs/interactive-graph-question-builder.test.ts, packages/perseus/src/widgets/interactive-graphs/interactive-graph-question-builder.ts, packages/perseus/src/widgets/interactive-graphs/stateful-mafs-graph.tsx, packages/perseus-editor/src/components/__tests__/start-coord-settings.test.tsx, packages/perseus/src/widgets/interactive-graphs/reducer/initialize-graph-state.ts

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

@khan-actions-bot khan-actions-bot requested a review from a team June 28, 2024 22:22
@nishasy nishasy marked this pull request as draft June 28, 2024 22:55
@nishasy nishasy marked this pull request as ready for review June 28, 2024 23:46
Copy link
Contributor

github-actions bot commented Jun 29, 2024

npm Snapshot: Published

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

Example:

yarn add @khanacademy/perseus@PR1382

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

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

Copy link

codecov bot commented Jun 29, 2024

Codecov Report

Attention: Patch coverage is 83.10502% with 37 lines in your changes missing coverage. Please review.

Project coverage is 71.09%. Comparing base (a8a1a0f) to head (a741a28).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1382      +/-   ##
==========================================
+ Coverage   69.78%   71.09%   +1.31%     
==========================================
  Files         503      508       +5     
  Lines      105061   105355     +294     
  Branches     7563    10771    +3208     
==========================================
+ Hits        73315    74903    +1588     
+ Misses      31630    30452    -1178     
+ Partials      116        0     -116     

Impacted file tree graph

Files Coverage Δ
...us-editor/src/components/coordinate-pair-input.tsx 100.00% <100.00%> (ø)
packages/perseus/src/index.ts 100.00% <100.00%> (ø)
...ctive-graphs/interactive-graph-question-builder.ts 98.55% <100.00%> (ø)
...widgets/interactive-graphs/stateful-mafs-graph.tsx 98.42% <100.00%> (-1.58%) ⬇️
...eus-editor/src/components/start-coord-settings.tsx 97.52% <97.52%> (ø)
...teractive-graphs/reducer/initialize-graph-state.ts 94.30% <69.23%> (-2.21%) ⬇️
...us-editor/src/widgets/interactive-graph-editor.tsx 89.29% <47.61%> (-2.32%) ⬇️

... and 124 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 a8a1a0f...a741a28. Read the comment docs.

@nishasy nishasy changed the title WIP!!!! [Interactive Graph Editor] Add UI for updating starting coordinates (linear and ray) [Interactive Graph Editor] Add UI for updating starting coordinates (linear and ray) Jun 29, 2024
@@ -254,12 +255,18 @@ class InteractiveGraphEditor extends React.Component<Props> {
let correct = this.props.correct;
// @ts-expect-error - TS2532 - Object is possibly 'undefined'.
if (correct.type === newProps.graph.type) {
correct = _.extend({}, correct, newProps.graph);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

lodash removal

this.props.onChange({
correct: correct,
graph: this.props.graph,
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added graph here because it's required for the update to happen correctly.

Copy link
Member

@catandthemachines catandthemachines left a comment

Choose a reason for hiding this comment

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

Overall test coverage and implementation looks pretty clean and straight forward to me, Approved! Though highly recommend a review from a fellow interactive graph peep ;)

graph: {
type: correct.type,
coords:
this.props.graph?.type === "circle"
Copy link
Member

Choose a reason for hiding this comment

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

I'm very curious, why do these property need to be exposed now for the starting coordinates work? (non-blocking question 😉)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the serialization function, which is used to copy/paste the graph across editors. Before, coords was never being used, because it was never part of the initial state. It was always undefined, and then it got set as the user would start interacting with it.

In this PR, I'm trying to set initial specific coordinates on the graph, and it needs to be copy/pastable in that state, which is why I now needed to add coords here when it wasn't there before.

I'll add a comment here for clarity!

@catandthemachines
Copy link
Member

Just confirming, it only meant to work once in Storybook? It uses the default coordinates, but if I move it again it doesn't work to more to default. Might need to check it out.
image
https://650db21c3f5d1b2f13c02952-jijqmcqxid.chromatic.com/?path=/story/perseuseditor-editorpage--interactive-graph-linear-with-starting-coords

};
this.props.onChange({graph: graph});
};

serialize(): PerseusInteractiveGraphWidgetOptions {
Copy link
Member

@benchristel benchristel Jul 1, 2024

Choose a reason for hiding this comment

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

Where is serialize called? GoLand's "find usages" feature isn't turning up anything. I was also able to delete serialize and got no type errors.

Asking because there's a change to this function (below).

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 think it's used here inside _maybeCopyWidgets.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's also called by the save mechanism in webapp by calling serialize() on a ref to the EditorPage component. The call stack is essentially:

The Editor then calls serialize on each widget (through a ref handle).

…'t need startCoords as a separate prop"

This reverts commit 16095ae.

Turns out we can't use the same coords after all
@khan-actions-bot khan-actions-bot requested a review from a team July 2, 2024 18:29
@nishasy nishasy requested a review from benchristel July 2, 2024 20:45
nishasy added 2 commits July 8, 2024 14:31
…, we don't need startCoords as a separate prop""

This reverts commit 71081af (which reverts commit 16095ae).
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.

Agree with @catandthemachines. LGTM!

@nishasy
Copy link
Contributor Author

nishasy commented Jul 8, 2024

Talked about @catandthemachines's comment offline - that behavior is expected. The preview on the right is not a wysiwyg for the starting coords. When you update the starting coords, it updates the starting state and thus displays it in the preview. But that preview is still only showing the learner experience.

nishasy added 2 commits July 15, 2024 11:01
…rlier PR, we don't need startCoords as a separate prop"""

This reverts commit 64eb1ba.

Adding back `startCoords`
@nishasy nishasy merged commit f392dcf into main Jul 15, 2024
11 checks passed
@nishasy nishasy deleted the start-coords-linear branch July 15, 2024 18:19
benchristel pushed a commit that referenced this pull request Jul 15, 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/[email protected]

### Minor Changes

-   [#1382](#1382) [`f392dcfba`](f392dcf) Thanks [@nishasy](https://github.com/nishasy)! - [Interactive Graph Editor] Implement UI to edit start coordinates for linear and ray graphs

## @khanacademy/[email protected]

### Minor Changes

-   [#1382](#1382) [`f392dcfba`](f392dcf) Thanks [@nishasy](https://github.com/nishasy)! - [Interactive Graph Editor] Implement UI to edit start coordinates for linear and ray graphs

### Patch Changes

-   Updated dependencies \[[`f392dcfba`](f392dcf)]:
    -   @khanacademy/[email protected]

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, ✅ Jest Coverage (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ gerald

Pull Request URL: #1414
Comment on lines +121 to +123
startCoords,
latestPropsRef,
startCoords,
Copy link
Collaborator

Choose a reason for hiding this comment

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

@nishasy Was this intentional to list startCoords twice here? :)

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.

5 participants