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

Remove Radium from Animation Picker components #47478

Merged
merged 26 commits into from
Aug 23, 2022

Conversation

mikeharv
Copy link
Contributor

@mikeharv mikeharv commented Aug 3, 2022

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:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

@mikeharv mikeharv changed the title Mike/animation picker list item module animation picker list item module Aug 3, 2022
@@ -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];
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 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.

Copy link
Contributor Author

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.

@mikeharv mikeharv marked this pull request as ready for review August 22, 2022 15:48
@mikeharv mikeharv requested a review from a team August 22, 2022 15:49
@@ -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;
Copy link
Contributor

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

Copy link
Contributor Author

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.

Comment on lines +63 to +65
hover && style.multiSelectBorder,
hover && style.hoverBorder,
selected && style.selectBorder,
Copy link
Contributor

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

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 actually reverted this today because it seemed to not be working as expected. Happy to take another look.

Copy link
Contributor

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;
Copy link
Contributor

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

Copy link
Contributor

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?

Copy link
Contributor

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?

Copy link
Contributor

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 ...

Copy link
Contributor

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   

Copy link
Contributor

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)

Copy link
Contributor

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

Copy link
Contributor

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 🙃

Copy link
Contributor

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 {
Copy link
Contributor

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
Copy link
Contributor

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!

Copy link
Contributor Author

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;
Copy link
Contributor

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!)

@mikeharv mikeharv changed the title animation picker list item module Remove Radium from Animation Picker Aug 22, 2022
@mikeharv mikeharv changed the title Remove Radium from Animation Picker Remove Radium from Animation Picker components Aug 22, 2022
@mikeharv
Copy link
Contributor Author

@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.

@megcrenshaw
Copy link
Contributor

megcrenshaw commented Aug 22, 2022

@mikeharv

@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 npx stylelint "**/*.scss" --fix from the apps directory ... But I'm currently working on a PR https://github.com/code-dot-org/code-dot-org/pull/47758/files to remove this so that you won't need to do this manually. That's the hope ...

Copy link
Contributor

@maddiedierker maddiedierker left a 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);
Copy link
Contributor

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;
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

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!

Copy link
Contributor Author

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;
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

@mikeharv mikeharv Aug 23, 2022

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.

Copy link
Contributor

@megcrenshaw megcrenshaw left a 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

@maddiedierker
Copy link
Contributor

this looks good to merge! great work, mike!

@mikeharv mikeharv merged commit 5fdf203 into staging Aug 23, 2022
@mikeharv mikeharv deleted the mike/animation-picker-list-item-module branch August 23, 2022 22:27
@megcrenshaw
Copy link
Contributor

Great work, Mike! Lots of good stuff in here 🥳

@mikeharv mikeharv restored the mike/animation-picker-list-item-module branch August 24, 2022 12:35
@mikeharv mikeharv deleted the mike/animation-picker-list-item-module branch August 24, 2022 12:37
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.

None yet

3 participants