-
Notifications
You must be signed in to change notification settings - Fork 480
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
Remove Radium from Animation Picker components #47478
Conversation
@@ -127,7 +127,7 @@ export default class AnimationPickerBody extends React.Component { | |||
}; | |||
|
|||
onCategoryChange = event => { | |||
const categoryQuery = event.target.className; | |||
const categoryQuery = event.target.className.split(' ')[0]; |
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 feature relies on the class(es) associated with a target animation to determine if it should be included in the filtered results displayed when changing categories. Because we are now using a SCSS module, all targets have multiple classes. These SCSS classes are always added after the class representing an animation's category.
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.
Update: We refactored this to use a data-* attribute instead of a class.
@@ -199,7 +201,7 @@ export default class AnimationPickerBody extends React.Component { | |||
if (!this.props.libraryManifest) { | |||
return <div>{msg.loading()}</div>; | |||
} | |||
const {searchQuery, categoryQuery, results} = this.state; | |||
let {searchQuery, categoryQuery, results} = this.state; |
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 probably leftover from previous changes, but this should probably stay as const
because we shouldn't be mutating anything in this.state
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.
Great catch! This was leftover from when I had tried splitting the string at this point.
hover && style.multiSelectBorder, | ||
hover && style.hoverBorder, | ||
selected && style.selectBorder, |
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.
now that we're using CSS, i wonder if this state is necessary anymore or if we can replace it with :hover
and :active
styles
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 actually reverted this today because it seemed to not be working as expected. Happy to take another look.
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.
eh, it's also an improvement we can make later. if it isn't easily fixable, i'd say it's outside the scope of this refactor since we can get rid of radium without this additional change
@import 'color.scss'; | ||
|
||
.allAnimations { | ||
color: $purple; |
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: the indentation from this line on is one tab too far indented
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.
These kinds of things (indentation and newline) can be caught if we disable prettier ... or re-add these rules in. Do you have a thought about best practice here?
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.
ahh, i should've checked the stylelint.config.js file -- now i see "rule-empty-line-before" and "declaration-empty-line-before" are disabled. do you know which rule enforces indentation style?
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 think it's here https://github.com/stylelint/stylelint-config-standard/blob/main/index.js#L96 but I'm now unable to make any warnings appear ...
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.
Oh, I was running the command with --fix so the warnings weren't showing up 🤣 . But yeah, if I disable prettier by deleting it in our config, and then run npx stylelint "**/*.scss
, then I get warnings like
src/lib/ui/Pagination.scss
3:5 ✖ Expected indentation of 2 spaces indentation
4:5 ✖ Expected indentation of 2 spaces indentation
5:5 ✖ Expected indentation of 2 spaces indentation
7:5 ✖ Expected indentation of 2 spaces indentation
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 originally came up with Ben in a PR I did recently #47716 (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.
weeeeeeeeird, why does prettier disable that rule? for now, let's just manually fix this and i'll do a pass with the linting rules and make a PR to fix all the existing violations
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.
or maybe we should just remove the prettier plugin... the rules it's disabling/conflicting with are ones i feel like we want to keep 🙃
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 started this branch and can't remember where I left off ... but its goal is to remove prettier. It was fairly straightforward I believe https://github.com/code-dot-org/code-dot-org/tree/remove-prettier
I think I just got sidetracked with other work ... I'll make a PR for it shortly
font-family: 'Gotham 7r', sans-serif; | ||
cursor: pointer | ||
} | ||
.breadCrumbs { |
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: add an empty newline between classes
.pagination { | ||
float: right; | ||
display: inline; | ||
margin-top: 10 |
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: a couple of ;
missing in this file -- i think all of my nits should be addressed by our new linting, which was unfortunately added after you started this branch. if you merge staging into this branch, try making a change to this file and make sure the linting catches these rules for us!
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.
Interesting. I actually merged staging into this branch about four ago and have since made changes.
$hover-plus-size: 24px; | ||
|
||
.root { | ||
float: left; |
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: styles are indented 1 tab too far (same thing about linting -- make a single change and see if our linting catches this so we don't have to do it manually anymore!)
@megcrenshaw @madelynkasula PTAL. I had to do all of the linting manually? I do have recent staging merged, but I'm not sure how to get my setup to detect/fix these indentation problems automatically. |
I think you will need to remove prettier from the config, as in https://github.com/code-dot-org/code-dot-org/blob/ca5971318f23f884bf101f7cbb85afb8cac5651c/apps/stylelint.config.js#L2, and then run |
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.
🎉 🎉 🎉
@@ -127,7 +129,7 @@ export default class AnimationPickerBody extends React.Component { | |||
}; | |||
|
|||
onCategoryChange = event => { | |||
const categoryQuery = event.target.className; | |||
const categoryQuery = getCategory(event.target); |
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 lovely!
@@ -300,40 +301,11 @@ export default class AnimationPickerBody extends React.Component { | |||
} | |||
} | |||
|
|||
export const UnconnectedAnimationPickerBody = Radium(AnimationPickerBody); | |||
export const UnconnectedAnimationPickerBody = AnimationPickerBody; |
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 think you need this now
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.
Although that will require a line change in the AnimationPickerBodyTest file, but I think that's okay too
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.
@megcrenshaw I'm actually unclear on how this thing that gets imported is different from the default export above. (Maybe that's what you're getting at though - they're the same?)
If that's the case, what was the original value of having a default export (without Radium) and this separate export (with Radium) for the test? Was this component not actually using Radium to begin with?
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.
Wow, you're right, this is bizarre.
Usually, we export UnconnectedComponentName
which isn't hooked up to Radium and/or state, and we use that for testing. And then we default export ComponentName
with Radium and/or state for other components to consume.
So this is weird because the original code for UnconnectedAnimationPickerBody
is actually connected to Radium, AND the default export was actually not connected to Radium, AND the component-with-Radium was the one being tested 🤯.
So you're right, it does seem that the components consuming this component were not using Radium. And you're right that at this point the two are the same. More reason to just get rid of this confusion!
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.
Updated: 52921b5
import {PlayBehavior} from '../constants'; | ||
import * as shapes from '../shapes'; | ||
import AnimationPreview from './AnimationPreview'; | ||
import style from './animation-picker-list-item.module.scss'; | ||
|
||
import classNames from 'classnames'; | ||
|
||
const THUMBNAIL_SIZE = 105; |
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 think you can remove this line and the one below it too?
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.
@megcrenshaw These constants are still used below at L76-77 to pass the height and width for the AnimationPreview component.
These values are set here and within the module, which doesn't seem great now that you mention it. I wonder how we can have one source of truth for thumbnail size across both components.
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.
Ah, okay, I missed that. Maddie mentioned this syntax in this thread:
:export {
myCssVariable: $my-css-variable;
}
Would that work here?
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.
Ugh. Just remembered that $thumbnail-size: 105px;
while const THUMBNAIL_SIZE = 105;
I can't just export the pixel value because the other component that also uses the values (AnimationPreview) is expecting a number for these properties.
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.
@megcrenshaw (cc @madelynkasula)
This worked (0e0d782), but it did hit linting errors. I ended up doing a git commit --no-verify
to get around this, but I'd like to confirm that this is okay before merging something that might just be caught later in the pipeline any way.
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.
Two small nits, but this looks great! Nice work
this looks good to merge! great work, mike! |
Great work, Mike! Lots of good stuff in here 🥳 |
This is part of the work to stop using Radium. See #47367 for more discussion. Deprecate Radium from the Animation Picker components.
The techniques used in this work largely resemble what was done for other Radium components.
However, this feature relies on the class(es) associated with a target animation to determine if it should be included in the filtered results displayed when changing categories. Because we are now using a SCSS module, all targets have multiple classes. To address this, we can ignore all classes except the first when determining if it's a category match. (File context and Slack thread)
Links
Google Sheet: Radium usage in apps/
Testing story
Tested across Sprite Lab, Game Lab and the "Sprite Upload" feature. No regression found when comparing against production (or levelbuilder for Sprite Upload).
Deployment strategy
Follow-up work
Jira: STAR-2375: Stop using classes to determine animation categories in Animation Picker
Privacy
Security
Caching
PR Checklist: