-
Notifications
You must be signed in to change notification settings - Fork 361
[Keypad] Update Keypad to use WonderBlocks Tabs component #2952
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
base: main
Are you sure you want to change the base?
Conversation
🗄️ Schema Change: No Changes ✅ |
|
Size Change: -467 B (-0.09%) Total Size: 499 kB
ℹ️ View Unchanged
|
🛠️ Item Splitting: No Changes ✅ |
ee14db4 to
714a009
Compare
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (6ea88ca) and published it to npm. You Example: pnpm add @khanacademy/perseus@PR2952If you are working in Khan Academy's frontend, you can run the below command. ./dev/tools/bump_perseus_version.ts -t PR2952If you are working in Khan Academy's webapp, you can run the below command. ./dev/tools/bump_perseus_version.js -t PR2952 |
4187e5a to
e8abe23
Compare
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 used to be inside the Keypad component. Moved it to a utility function to dry the Keypad code. Intention is still the same as the original but the logic is now follows the props required for the WB Tabs component.
|
|
||
| return ( | ||
| <div style={{padding: "1rem 2rem"}}> | ||
| <div style={{padding: "1rem 2rem", minHeight: "400px"}}> |
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.
handeyeco
left a comment
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.
It's a huge win when we can use someone else's code instead of maintaining our own version of things! Thanks for digging into this. 🌈
In the future it might be helpful to try stacked PRs. This PR accomplishes a lot but not everything is related so it's can be hard to follow.
| import {CursorContext} from "../../input/cursor-contexts"; | ||
|
|
||
| import type {MathInputStrings} from "../../strings"; | ||
| import type {MathInputStrings} from "@khanacademy/math-input/strings"; |
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.
Packages shouldn't import from themselves. I was thinking we had a lint rule for this 🤔
math-input shouldn't import from @khanacademy/math-input
| @@ -0,0 +1,5 @@ | |||
| export {getAvailableTabs} from "./get-available-tabs"; | |||
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.
I don't really get the point of the index.ts file here. Now there are two ways to import these:
import {getAvailableTabs} from "./utils"
import {getAvailableTabs} from "./utils/get-available-tabs"
IMO, for the sake of consistency, it would be better to only have one way.
| @@ -1,5 +1,3 @@ | |||
| /* eslint-disable @khanacademy/ts-no-error-suppressions */ | |||
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.
Why add a folder for math-input if it only contains the math-input.tsx file? Doesn't seem like the folder is needed but, if it is, maybe it would make sense for this file to be index.ts so that we don't have to update imports.
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.
Good catch! this was a left over of my initial refactor attempt. I'll update that.
| import Clickable from "@khanacademy/wonder-blocks-clickable"; | ||
| import {View} from "@khanacademy/wonder-blocks-core"; | ||
| import {Popover, PopoverContentCore} from "@khanacademy/wonder-blocks-popover"; | ||
| import {color, spacing} from "@khanacademy/wonder-blocks-tokens"; |
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.
(comment on file/dir, not this line of code)
I don't think we need to add a math-input folder if the only file in it is just math-input.tsx. If for some reason we do need the math-input folder, maybe it would make sense for this file to be index.tsx so we don't need to update imports.
| setSelectedPage(newSelectedPage as KeypadPageType); | ||
| }} | ||
| styles={{ | ||
| tab: { |
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.
Can we move these styles out of the JSX rendering? If we move them out of the component it will make the JSX easier to read and we'll get an added bonus in that we won't have to redeclare them every time we rerender.
|
|
||
| handleKeypadPress: (key: KeypadKey, e: any) => void = (key, e) => { | ||
| // Handle dismiss key to close the keypad | ||
| if (key === "DISMISS") { |
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.
Do we still need a "DISMISS" key? Seems like that's obsolete now if we're using WB.
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.
Unfortunately yes,
- Initial approach was using the WB Tabs for the x button and had it styled to be positioned on the right most away from the other tabs, that didn't looked so good
- Second approach is using Popover x button but had to remove that solution because other usages of the keypad doesn't have a popover
- So i added back in the DISMISS key and hooked it in IconButton and positioned it at the right of the Tabs component
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.
@handeyeco we do have potential code that we can remove though related to DIMISS. I'm just not confident if it's safe to remove now that we use the WB IconButton, you might have more context to this:
- https://github.com/Khan/perseus/blob/main/packages/math-input/src/components/keypad/button-assets.tsx#L388
- packages/math-input/src/components/keypad/tab-icon-label.tsx (this one will cause a ts error)
| import type {KeypadProps} from "./keypad"; | ||
| import type {KeypadPageType} from "../../types"; | ||
|
|
||
| export type KeypadFractionsOnlyProps = Pick< |
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.
It's not clear to me why we need both KeypadFractionsOnly and FractionsPage. Couldn't KeypadFractionsOnly just be part of Keypad?
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.
During the refactor i've separated the logic
- Displaying of the fractions only without any tabs
- Displaying of fractions together with other tabs
Both of this uses the FractionsPage, the first one is rendered directly from the KeyPad while the second one is is rendered via the util getAvailableTabs which will form the props that will be provided to the WB Tabs component.
Initially with #1 I added it in the Keypad component, but since it has a number of lines of code i decided to make it a different component so it will be easier to read in Keypad component like this (making the code dry):
// We don't want to show any available tabs on the fraction keypad
if (fractionsOnly) {
return <KeypadFractionsOnly {...props} />;
}
| import type {PerseusAnalyticsEvent, KeypadKey} from "@khanacademy/perseus-core"; | ||
|
|
||
| type Props = { | ||
| export interface KeypadProps { |
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.
Just curious: is there a reason for switching from type to interface?
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.
Our team had a discussion about this preference using interface.
Thanks @handeyeco for the review and i'll take note on your suggestion for stacking the PRs in the future 🙏🏼 |
|
|
||
| // We don't want to show any available tabs on the fraction keypad | ||
| if (fractionsOnly) { | ||
| return <KeypadFractionsOnly {...props} />; |
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.
I'm not a huge fan of the name. What about FractionKeypad? If we're splitting out FractionKeypad, I wonder if it would make sense to also split out a ExpressionKeypad too. Then Keypads return could be something like
return fractionsOnly ? <FractionKeypad {...props} /> : <ExpressionKeypad {...props} />Although I'm not a fan of spreading props either. For instance you're still passing advancedRelations to FractionKeypad even though it's not used (and the type system doesn't allow using it). I think it makes more sense to explicitly pass props except in places where you really want to pass all props (like in forwardRef).
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 @handeyeco i'll look into it and do a follow-up PR.
## Summary: Temporary add code ownership to math-input and keypad while keypad refactor is ongoing in #2952 Issue: LEMS-3361 ## Test plan: Author: ivyolamit Reviewers: anakaren-rojas, mark-fitzgerald Required Reviewers: Approved By: anakaren-rojas, mark-fitzgerald Checks: ✅ 10 checks were successful, ⏭️ 1 check has been skipped Pull Request URL: #3051
939212e to
6c5d1e3
Compare
## Summary: Add Tabs and IconButton packages for math-input/keypad refactor Context: Extracted package addition change from #2952 to minimize the risk of merge conflict since we will be waiting for Keypad QA. Issue: LEMS-3361 ## Test plan: Author: ivyolamit Reviewers: nishasy, ivyolamit Required Reviewers: Approved By: nishasy Checks: ✅ 10 checks were successful, ⏭️ 1 check has been skipped Pull Request URL: #3054
…o use WonderBlocks Tabs component
…instead of popover close button
…es related to popover dismiss was removed
13f025e to
6ea88ca
Compare
|
👆🏼 Rebased from latest master which includes the adding for the packages, to minimize the merge conflict later as package files are often updated. |

Summary:
Refactor Keypad to use WB Tabs instead of Tabbar:
Issue: LEMS-3361
Limitations
Test plan:
Co-Authored by Claude Code