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

start reduxing activity state #426

Merged
merged 5 commits into from
Apr 19, 2018
Merged

Conversation

brendansudol
Copy link
Contributor

@brendansudol brendansudol commented Apr 19, 2018

Overview: Ok, this is the start of wiring up our new post-pivot activity stuff to redux. I'm leaving the former poc page as is (it's now at the root page) so we have it as a reference as we're doing this (and people can still look and click on stuff). and the new stuff is at /activities. Eventually, this will look very similar / better than what's at the poc page, AND it will sync with our client data store, which we can then easily push to the backend.

More details:

In terms of the structure of the activities state, I'm following this normalized structure (https://redux.js.org/recipes/structuring-reducers/normalizing-state-shape) which will help with performance.

I don't yet love the structure / API for the UPDATE_ACTIVITY action right now, but it's a start and it works.

For the rich editor fields, we convert the EditorState object to html when syncing with our state (and from html to that EditorState on initialization); we can abstract/consolidate these conversions as we build out additional components that need this.

When reviewing, please go to /activities page and play around with the fields and inspect the redux logger console statements, too.

The next steps are adding more components within the ActivityDetailAll (similar to what I've done with ActivityDetailDescription).

I also improved input focus states and made them consistent across our various input types (input, textarea, editor)

This pull request is ready to merge when...

  • Tests have been updated (and all tests are passing)
  • This code has been reviewed by someone other than the original author
  • The experience passes a basic manual accessibility audit (keyboard nav, screenreader, text scaling) OR an exemption is documented

This feature is done when...

  • Design has approved the experience
  • Product has approved the experience

@codecov-io
Copy link

codecov-io commented Apr 19, 2018

Codecov Report

Merging #426 into master will decrease coverage by 2.6%.
The diff coverage is 32.6%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #426      +/-   ##
==========================================
- Coverage   81.47%   78.87%   -2.61%     
==========================================
  Files         120      127       +7     
  Lines        1636     1728      +92     
  Branches      136      147      +11     
==========================================
+ Hits         1333     1363      +30     
- Misses        273      331      +58     
- Partials       30       34       +4
Impacted Files Coverage Δ
web/src/routes.js 100% <ø> (ø) ⬆️
web/src/components/Collapsible.js 13.33% <ø> (ø) ⬆️
web/src/reducers/index.js 100% <ø> (ø) ⬆️
web/src/actions/activities.js 100% <100%> (ø)
web/src/containers/ActivityListEntry.js 16.66% <16.66%> (ø)
web/src/containers/ActivityDetailDescription.js 18.51% <18.51%> (ø)
web/src/containers/ActivityDetailAll.js 33.33% <33.33%> (ø)
web/src/reducers/activities.js 46.66% <46.66%> (ø)
web/src/containers/Activities.js 57.14% <57.14%> (ø)
web/src/containers/ActivityDetailGoals.js 66.66% <66.66%> (ø)
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fcf98aa...98f20d6. Read the comment docs.

@brendansudol brendansudol changed the title [WIP] start reduxing activity state start reduxing activity state Apr 19, 2018
};

const mapStateToProps = ({ activities: { byId } }, { aId, num }) => {
const activity = byId[aId];
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious why you get the activity from redux store by ID rather than taking it as a param?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, i wasn't really sold on this either; i read that it was better performance to pass down the id and look up the data object via connect, let me track down the article

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Fascinating. Really gets into the weeds of how React handles re-rendering as state changes.

toolbar={EDITOR_CONFIG}
editorState={descLong}
onEditorStateChange={this.onEditorChange('descLong')}
onBlur={this.syncEditorState('descLong')}
Copy link
Contributor

Choose a reason for hiding this comment

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

To make sure I'm clear on this: as the editor changes, update the component state so the editor stays editable; when the editor blurs, grab the HTML and sync that to redux 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.

exactly!

const reducer = (state = initialState, action) => {
switch (action.type) {
case ADD_ACTIVITY: {
const id = Math.max(...state.allIds, 0) + 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Writing this out for my own benefit... Creating an ID here is safe because when we sync to the API, we can refresh the redux state to match the "real" ID and that will cascade through the app and everything will be okay. 🤔

I'm not sure that's true, but let's fix it when it happens rather than spend any time theorizing about what might happen in the future since it can't possibly happen right now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, that was my thought process as well

altApproach: ''
});

const updateEntry = (state, action) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think using updeep here might be good? The code would look something like...

return updeep({ byId: { [id]: { [name]: value }}}, 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.

whoa - never heard of it, but i'm intrigued!!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updeep is awesome, gonna switch to this going forward -- great tip!

Copy link
Contributor

@mgwalker mgwalker left a comment

Choose a reason for hiding this comment

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

Small questions but I like it. Merge at will!

@brendansudol brendansudol merged commit 243eabb into master Apr 19, 2018
@brendansudol brendansudol deleted the bjs-start-activities-state branch April 19, 2018 20:04
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.

3 participants