-
Notifications
You must be signed in to change notification settings - Fork 350
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] Open and Closing logic for unlimited polygon. #1852
Conversation
GeraldRequired Reviewers
Don't want to be involved in this pull request? Comment |
Size Change: +374 B (+0.03%) Total Size: 1.29 MB
ℹ️ View Unchanged
|
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (d0842b3) and published it to npm. You Example: yarn add @khanacademy/perseus@PR1852 If you are working in Khan Academy's webapp, you can run: ./dev/tools/bump_perseus_version.sh -t PR1852 |
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 is looking good! Thanks for backfilling tests for the other reducer actions.
I left some suggestions inline about things that I think could be refactored and simplified.
packages/perseus/src/widgets/interactive-graphs/reducer/interactive-graph-reducer.test.ts
Show resolved
Hide resolved
packages/perseus/src/widgets/interactive-graphs/reducer/interactive-graph-reducer.test.ts
Show resolved
Hide resolved
packages/perseus/src/widgets/interactive-graphs/reducer/interactive-graph-reducer.ts
Outdated
Show resolved
Hide resolved
packages/perseus/src/widgets/interactive-graphs/reducer/interactive-graph-reducer.ts
Outdated
Show resolved
Hide resolved
packages/perseus/src/widgets/interactive-graphs/reducer/interactive-graph-reducer.test.ts
Outdated
Show resolved
Hide resolved
packages/perseus/src/widgets/interactive-graphs/reducer/interactive-graph-reducer.test.ts
Show resolved
Hide resolved
const shouldShowRemoveButton = | ||
showRemovePointButton && focusedPointIndex !== 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 variable now controls whether the remove button is enabled, I think it should be called shouldEnableRemoveButton
. It could also incorporate closedPolygon
:
const shouldShowRemoveButton = | |
showRemovePointButton && focusedPointIndex !== null; | |
const shouldEnableRemoveButton = | |
!closedPolygon && showRemovePointButton && focusedPointIndex !== null; |
I wonder if state.showRemovePointButton
should also be renamed to state.enableRemovePointButton
. Or if a different name entirely is appropriate, since that state variable doesn't completely control whether the button is enabled or not.
I'm kind of confused about when the remove button is enabled vs. disabled, and that might be a sign that it will be confusing to learners as well.
kind="secondary" | ||
color="destructive" | ||
// Disable button when polygon is closed. | ||
disabled={closedPolygon || !shouldShowRemoveButton} |
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.
Re: my comment above, maybe closedPolygon
should be incorporated into shouldShowRemoveButton
/shouldEnableRemoveButton
so all the logic can be in one place.
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.
Thanks for the updates! LGTM 🎉
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 nits but overall looks good
EDIT: Sorry i didn't realize this was already merged!
if (closedPolygon) { | ||
const closedPolygonProps = {...props, numSides: coords.length}; | ||
return <LimitedPolygonGraph {...closedPolygonProps} />; | ||
} else { |
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.
small nit: the else isn't needed here since you return in your if statement
height={heightPx} | ||
x={left} | ||
y={top} | ||
onClick={(event) => { |
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.
nit: can this be moved into a handler function?
function handleOnClick(event) {
const elementRect =
event.currentTarget.getBoundingClientRect();
const x = event.clientX - elementRect.x;
const y = event.clientY - elementRect.y;
const graphCoordinates = pixelsToVectors(
[[x, y]],
graphConfig,
);
dispatch(actions.polygon.addPoint(graphCoordinates[0]));
}
then
<rect
style={{
fill: "rgba(0,0,0,0)",
cursor: "crosshair",
}}
width={widthPx}
height={heightPx}
x={left}
y={top}
onClick={handleOnClick}
/>
@@ -192,6 +198,28 @@ function doClickPoint( | |||
return state; | |||
} | |||
|
|||
function doClosePolygon(state: InteractiveGraphState): InteractiveGraphState { |
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.
idk why I read this in a British accent
Do close the polygon
😆
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] ### Major Changes - [#1905](#1905) [`9c225f936`](9c225f9) Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - We're reverting work done for the Server Side Scoring and Input Number Conversion projects. ### Minor Changes - [#1883](#1883) [`adad642ab`](adad642) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Introduces a validation function for the matrix widget (extracted from matrix scoring function). - [#1878](#1878) [`a27f23bb4`](a27f23b) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Add expression validator function ### Patch Changes - [#1890](#1890) [`0afb1a4f7`](0afb1a4) Thanks [@nishasy](https://github.com/nishasy)! - [Locked Labels + Aria] Create math only parser to help parse TeX how we want - [#1889](#1889) [`55a532175`](55a5321) Thanks [@benchristel](https://github.com/benchristel)! - Internal: enable strict typechecking of function parameters - [#1852](#1852) [`4b8836b84`](4b8836b) Thanks [@catandthemachines](https://github.com/catandthemachines)! - Adding open and closing behavior to unlimited polygon graph type. - Updated dependencies \[[`55a532175`](55a5321)]: - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] ## @khanacademy/[email protected] ### Major Changes - [#1905](#1905) [`9c225f936`](9c225f9) Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - We're reverting work done for the Server Side Scoring and Input Number Conversion projects. ### Patch Changes - [#1889](#1889) [`55a532175`](55a5321) Thanks [@benchristel](https://github.com/benchristel)! - Internal: enable strict typechecking of function parameters - Updated dependencies \[[`adad642ab`](adad642), [`0afb1a4f7`](0afb1a4), [`55a532175`](55a5321), [`9c225f936`](9c225f9), [`4b8836b84`](4b8836b), [`a27f23bb4`](a27f23b)]: - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] ## @khanacademy/[email protected] ### Patch Changes - [#1889](#1889) [`55a532175`](55a5321) Thanks [@benchristel](https://github.com/benchristel)! - Internal: enable strict typechecking of function parameters ## @khanacademy/[email protected] ### Patch Changes - [#1889](#1889) [`55a532175`](55a5321) Thanks [@benchristel](https://github.com/benchristel)! - Internal: enable strict typechecking of function parameters ## @khanacademy/[email protected] ### Patch Changes - Updated dependencies \[[`55a532175`](55a5321)]: - @khanacademy/[email protected] ## @khanacademy/[email protected] ### Patch Changes - [#1889](#1889) [`55a532175`](55a5321) Thanks [@benchristel](https://github.com/benchristel)! - Internal: enable strict typechecking of function parameters ## @khanacademy/[email protected] ### Major Changes - [#1905](#1905) [`9c225f936`](9c225f9) Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - We're reverting work done for the Server Side Scoring and Input Number Conversion projects. ### Patch Changes - Updated dependencies \[[`55a532175`](55a5321)]: - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected] - @khanacademy/[email protected]
Summary:
Adding opening and closing behavior to unlimited polygon including:
Issue: LEMS-2570
Test plan:
yarn dev
and enableUnlimited Polygon
option in the Mafs dropdown. Or http://localhost:6006/?path=/story/perseus-widgets-interactive-graph--unlimited-polygon-with-mafs.Close polygon
button the close the polygon.Open polygon
button again to add or remove points.