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

Refactor of display logic in preparation for adding default dropdown behavior #42712

Merged
merged 3 commits into from Sep 29, 2021

Conversation

jmkulwik
Copy link
Contributor

@jmkulwik jmkulwik commented Sep 27, 2021

This does a few things:

  1. Move the viewAs === ViewType.Teacher to a viewAsTeacher prop
  2. Initialize const variables for state and props values anywhere with more than one reference to state/props
  3. Remove overloads of state and props names
  4. Consolidate the logic for the header so codeReviewEnabled and !viewAsTeacher are only checked once

Links

Testing story

Deployment strategy

Follow-up work

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

@jmkulwik jmkulwik changed the base branch from staging to ben/code-review/move-token-into-data-api September 27, 2021 23:21
@jmkulwik jmkulwik requested a review from a team September 27, 2021 23:46
@@ -70,6 +70,7 @@ class ReviewTab extends Component {
serverLevelId,
serverScriptId
} = getStore().getState().pageConstants;
Copy link
Contributor

Choose a reason for hiding this comment

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

may be out of scope, but would you mind moving these to be passed in as props via redux?

Copy link
Contributor

Choose a reason for hiding this comment

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

Curious about this in general -- since these are constants (ie, shouldn't change), do we still prefer they be passed in as props?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From what I've seen, getStore.getState generally only gets called for libraries that can't be connected. React components generally get values like this by being connected and passing via props. I don't know the exact reason why we don't tend to call getStore.getState from within a component, but I'd generally be surprised to find something controlling a component by anything besides props.

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 have one more follow-up in the works after the functional change. I'll plan to do this as part of that change unless someone else gets to it before me.

Copy link
Contributor

@molly-moen molly-moen left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@bencodeorg bencodeorg left a comment

Choose a reason for hiding this comment

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

So much better! 👏

}

return (
<>
Copy link
Contributor

Choose a reason for hiding this comment

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

Woo fragments!


return (
<div style={styles.reviewsContainer}>
<div style={styles.reviewHeader}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: do we need this div if header is empty? Could we put it in renderHeader() if not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My follow-up PR (in progress) moves things around a bit more. I ended up getting rid of renderHeader. So I'll leave this as-is for now as it gets cleaned up in the next one:
https://github.com/code-dot-org/code-dot-org/pull/42716/files

Copy link
Contributor

@sanchitmalhotra126 sanchitmalhotra126 left a comment

Choose a reason for hiding this comment

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

Nice!

@jmkulwik jmkulwik changed the base branch from ben/code-review/move-token-into-data-api to staging September 29, 2021 01:31
@jmkulwik jmkulwik changed the base branch from staging to ben/code-review/move-token-into-data-api September 29, 2021 01:32
Base automatically changed from ben/code-review/move-token-into-data-api to staging September 29, 2021 20:17
@jmkulwik jmkulwik merged commit 2903240 into staging Sep 29, 2021
@jmkulwik jmkulwik deleted the jessie-prefactor branch September 29, 2021 20:24
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

4 participants