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

[SR] Circle - Add the interactive elements circle description to the whole graph container #2060

Merged
merged 4 commits into from
Jan 9, 2025

Conversation

nishasy
Copy link
Contributor

@nishasy nishasy commented Dec 24, 2024

Summary:

Add the interactive Circle graph description to the full graph container.

This adds the "Interactive elements: Circle..." description to the outermost graph container.

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

Test plan:

@nishasy nishasy self-assigned this Dec 24, 2024
Copy link
Contributor

github-actions bot commented Dec 24, 2024

Size Change: +184 B (+0.01%)

Total Size: 1.28 MB

Filename Size Change
packages/perseus/dist/es/index.js 419 kB +184 B (+0.04%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 39 kB
packages/keypad-context/dist/es/index.js 760 B
packages/kmath/dist/es/index.js 4.27 kB
packages/math-input/dist/es/index.js 78 kB
packages/math-input/dist/es/strings.js 1.79 kB
packages/perseus-core/dist/es/index.js 1.48 kB
packages/perseus-editor/dist/es/index.js 688 kB
packages/perseus-linter/dist/es/index.js 22.2 kB
packages/perseus/dist/es/strings.js 4.64 kB
packages/pure-markdown/dist/es/index.js 3.66 kB
packages/simple-markdown/dist/es/index.js 12.5 kB

compressed-size-action

@@ -221,3 +207,59 @@ function crossProduct<A, B>(as: A[], bs: B[]): [A, B][] {
}
return result;
}

function CircleGraphDescription({state}: {state: CircleGraphState}) {
// CircleGraphDescription needs to the `usePerseusI18n`, hook so it has]
Copy link
Contributor

@anakaren-rojas anakaren-rojas Dec 27, 2024

Choose a reason for hiding this comment

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

?

Suggested change
// CircleGraphDescription needs to the `usePerseusI18n`, hook so it has]
// CircleGraphDescription needs the `usePerseusI18n` hook so it has

@@ -221,3 +207,59 @@ function crossProduct<A, B>(as: A[], bs: B[]): [A, B][] {
}
return result;
}

function CircleGraphDescription({state}: {state: CircleGraphState}) {
Copy link
Contributor

@anakaren-rojas anakaren-rojas Dec 27, 2024

Choose a reason for hiding this comment

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

this is the same as state: CircleGraphState? Or is there an additional benefit to the destructing in this case?

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 that works too. I think the reason it was done this way (I was following what Ben did for the point description) is so it follows the prop structure the way they're standardly written for other functional components.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

// Exported for testing
export function describeCircleGraph(
state: CircleGraphState,
i18n: {strings: PerseusStrings; locale: string},
Copy link
Contributor

@anakaren-rojas anakaren-rojas Dec 27, 2024

Choose a reason for hiding this comment

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

theres a I18nContextType that might be worth exporting to use here and around in the other graphs as needed. Alternatively, we could create a type in a utility file and destructure
{strings: PerseusStrings; locale: string}: I18ContextType then remove line 225

Copy link
Contributor

github-actions bot commented Dec 28, 2024

npm Snapshot: Published

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

Example:

yarn add @khanacademy/perseus@PR2060

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

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

@nishasy nishasy marked this pull request as ready for review December 28, 2024 01:24
@@ -30,7 +31,7 @@ export function renderCircleGraph(
): InteractiveGraphElementSuite {
return {
graph: <CircleGraph graphState={state} dispatch={dispatch} />,
interactiveElementsDescription: null,
interactiveElementsDescription: CircleGraphDescription({state}),
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 slightly surprised that this works. Since CircleGraphDescription is calling a hook, I'd expect it to have to be used as a JSX element:

<CircleGraphDescription state={state} />

If the component calling renderCircleGraph does so conditionally, e.g.

if (graphType === "circle") {
  return renderCircleGraph(state, dispatch)
}

And graphType changes between renders, this code will break the Rules of Hooks. The usePerseusI18n hook will be called on one render and not called on the next.

I think it's working (mostly?) because the graph type rarely changes between renders. It probably only does so in the content 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.

Ack! My mistake. I 100% meant to use your code for Point as the blueprint for this, which means I was supposed to write <CircleGraphDescription state={state} />.

srCircleRadiusPoint,
srCircleRadius,
srCircleOuterPoints,
} = describeCircleGraph(graphState, {strings, locale});
Copy link
Member

Choose a reason for hiding this comment

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

I like this way of splitting up the logic! Makes it much easier to read and test :)

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!

@nishasy nishasy merged commit 43e99d2 into main Jan 9, 2025
8 checks passed
@nishasy nishasy deleted the whole-graph-sr-circle branch January 9, 2025 18:41
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.

3 participants