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

Add and use Checklist components, remove blocks #26618

Merged
merged 19 commits into from
Aug 15, 2018
Merged

Conversation

sirreal
Copy link
Member

@sirreal sirreal commented Aug 10, 2018

Adds Components from #26216
Uses components for WooCommerce Store checklist
Uses components for ChecklistShow
Removes blocks (discourage block usage)

The goal here is to keep the clear improvements from #26216 outlined in #26015:

  • simple components
  • declarative WooCommerce Store checklist
  • avoid mixing state with structure in connect

And drop the bits that may not move clearly in the direction we'd like to take:

  • Connected Task block
  • Task block/component confusion

This should be a good first step in the incremental improvements around checklists. After this, the Woo checklist should not need work, and we can focus on work around the site onboarding checklists.

Implementing ideas from #26015
Closes #26030 (supersedes)
Closes #26216 (supersedes)
Closes #25958

Testing

No functional or visual changes. Testing instructions adapted from #26216 (will add pings if this is considered a good direction).

Checklists may be used in 4 places. The functionality should remain unchanged for all of them:

Functionality:

  • Task counts
  • Task ordering (completed at the top)
  • Checklist collapsing
  • Clicking the event actions
  • Reporting of event completion

Checklists in use to test:

  • Checklist banners (simple sites at /stats/day/SITE) (@taggon / @fditrapani)
  • Jetpack checklist (Jetpack sites at /plans/my-plan/SITE) (@Automattic/luna)
  • Store checklist (Store installed, visit Store dashboard at /store/SITE) (@timmyc)
  • Devdocs https://calypso.live/devdocs/design/checklist?branch=add/checklist-components (@sirreal)
  • Devdocs playground (@sirreal):
    Drop the following in https://calypso.live/devdocs/playground?branch=add/checklist-components
    <Checklist inferCompletedCount>
    	<ChecklistTask
    		onClick={ () => console.log('Do this?') }
    		onDismiss={ () => console.log('Dismissing…') }
    		title="Reticulate splines"
    		buttonText="Reticulate!"
    		buttonPrimary
    		completedTitle="Splines are reticulated 👍"
    		description="Make sure that all the splines are reticulated."
    		duration="1 minute"
    		completed
    	/>
    	<ChecklistTask
    		onClick={ () => console.log('Do this?')  }
    		onDismiss={ () => console.log('Dismiss yak shaving.') }
    		title="Shave yaks!"
    		buttonText="Buzzzz"
    		buttonPrimary
    		completedTitle="Yaks shaved."
    		description="Make sure you shave the yaks so you can get on with your life."
    		duration="10,000 minutes"
    	/>
    </Checklist>

@matticbot
Copy link
Contributor

@sirreal sirreal self-assigned this Aug 10, 2018
@sirreal sirreal force-pushed the add/checklist-components branch 3 times, most recently from 8016cf9 to 67280c4 Compare August 10, 2018 15:36
@sirreal sirreal requested a review from ockham August 10, 2018 15:38
@sirreal sirreal added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] In Progress labels Aug 10, 2018
@sirreal
Copy link
Member Author

sirreal commented Aug 10, 2018

Interesting impact on build. I'm not sure what's happened, it seems that a shared chunk has now but put into two other chunks. cc: @jsnajdr

http://iscalypsofastyet.com/branch?branch=add/checklist-components

Commit: 67280c452927b427a4ac78e37af9720a3da447d8
Author: sirreal
At: 2018-08-10T15:35:47Z
Message: Separate state/structure in banner
Delta:
chunk               stat_size             parsed_size           gzip_size
build               +0 B                  -17 B     (-0.0%)     -6 B     (-0.0%)
checklist           +30104 B  (+108.4%)   +20078 B  (+115.0%)   +3881 B  (+81.5%)
checklist~plans     -30775 B  (deleted)   -19494 B  (deleted)   -4728 B  (deleted)
plans               +29682 B  (+23.5%)    +19661 B  (+34.3%)    +3708 B  (+27.2%)
stats               -1429 B   (-0.3%)     -357 B    (-0.2%)     -99 B    (-0.2%)
Full output
Commit: 67280c452927b427a4ac78e37af9720a3da447d8
Author: sirreal
At: 2018-08-10T15:35:47Z
Message: Separate state/structure in banner
Delta:
chunk                                                                                                          stat_size             parsed_size             gzip_size
account                                                                                                             +0 B                    +0 B                  -1 B    (-0.0%)
async-load-blocks-inline-help-popover                                                                               +0 B                    +0 B                  -1 B    (-0.0%)
async-load-design                                                                                                +7222 B    (+2.0%)      +4624 B    (+2.0%)     +983 B    (+2.4%)
async-load-design-blocks                                                                                         -5928 B    (-0.4%)      -3490 B    (-0.5%)     -799 B    (-0.5%)
async-load-design-playground                                                                                     +2349 B    (+0.8%)      +1167 B    (+0.6%)     +212 B    (+0.6%)
async-load-design-typography                                                                                        +0 B                    +0 B                  +1 B    (+0.1%)
async-load-design~async-load-design-gutenberg-components~async-load-design-playground                            -1055 B    (-0.7%)        -33 B    (-0.0%)      -80 B    (-0.4%)
async-load-docs-selectors                                                                                           +0 B                    +0 B                  +1 B    (+0.1%)
async-load-extensions-woocommerce-app-store-stats-listview                                                          +0 B                    +0 B                  +2 B    (+0.0%)
async-load-featured-image                                                                                           +0 B                    +0 B                  -1 B    (-0.1%)
async-load-my-sites-current-site-domain-warnings                                                                    +0 B                    +0 B                  +1 B    (+0.1%)
async-load-post-editor-editor-discussion                                                                            +0 B                    +0 B                  +1 B    (+0.1%)
async-load-reader-conversations-stream                                                                              +0 B                    +0 B                  +4 B    (+0.2%)
async-load-reader-following-manage                                                                                  +0 B                    +0 B                  +1 B    (+0.0%)
async-load-reader-tag-stream-main                                                                                   +0 B                    +0 B                  +1 B    (+0.0%)
async-load-reader-team-main                                                                                         +0 B                    +0 B                  +1 B    (+0.4%)
build                                                                                                               +0 B                   -17 B    (-0.0%)       -6 B    (-0.0%)
checklist                                                                                                       +30104 B  (+108.4%)     +20078 B  (+115.0%)    +3881 B   (+81.5%)
checklist~plans                                                                                                 -30775 B  (deleted)     -19494 B  (deleted)    -4728 B  (deleted)
checkout                                                                                                            +0 B                    +0 B                  +1 B    (+0.0%)
checkout~customize~plugins~purchases~settings~theme~themes                                                          +0 B                    +0 B                  +1 B    (+0.0%)
checkout~purchases                                                                                                  +0 B                    +0 B                  +1 B    (+0.0%)
devdocs                                                                                                             +0 B                    +0 B                  +4 B    (+0.0%)
google-my-business                                                                                                  +0 B                    +0 B                  -1 B    (-0.0%)
help                                                                                                                +0 B                    +0 B                  -1 B    (-0.0%)
manifest                                                                                                            +0 B                   -47 B    (-0.3%)      -33 B    (-0.6%)
plans                                                                                                           +29682 B   (+23.5%)     +19661 B   (+34.3%)    +3708 B   (+27.2%)
plugins                                                                                                             +0 B                    +0 B                  +1 B    (+0.0%)
post-editor                                                                                                         +0 B                    +0 B                  -1 B    (-0.0%)
purchases                                                                                                           +0 B                    +0 B                  +1 B    (+0.0%)
reader                                                                                                              +0 B                    +0 B                  +5 B    (+0.0%)
settings-writing                                                                                                    +0 B                    +0 B                  -1 B    (-0.0%)
stats                                                                                                            -1429 B    (-0.3%)       -357 B    (-0.2%)      -99 B    (-0.2%)
vendors~async-load-components-web-preview-component                                                                 +0 B                    +0 B                  +1 B    (+0.0%)
vendors~async-load-design-blocks                                                                                    +0 B                    +0 B                  +1 B    (+0.0%)
vendors~async-load-design-blocks~post-editor~wp-job-manager~zoninator                                               +0 B                    +0 B                  +1 B    (+0.0%)
vendors~async-load-design~async-load-design-blocks~async-load-design-gutenberg-components~async-load~a48a2cd6       +0 B                    +0 B                  -1 B    (-0.0%)
vendors~async-load-design~async-load-design-playground~google-my-business~woocommerce                               +0 B                    +0 B                  -1 B    (-0.0%)
vendors~async-load-lib-happychat-connection                                                                         +0 B                    +0 B                  +1 B    (+0.0%)
vendors~async-load-notifications                                                                                    +0 B                    +0 B                  -1 B    (-0.0%)
vendors~async-load-post-editor-media-modal~media~post-editor                                                        +0 B                    +0 B                  -1 B    (-0.0%)
vendors~async-load-reader-following-manage~async-load-reader-search-stream                                          +0 B                    +0 B                  +2 B    (+0.0%)
vendors~security                                                                                                    +0 B                    +0 B                  -1 B    (-0.0%)
vendors~settings-writing                                                                                            +0 B                    +0 B                  +1 B    (+0.0%)
woocommerce                                                                                                      -1006 B    (-0.0%)        +58 B    (+0.0%)     -168 B    (-0.1%)

@sirreal sirreal added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Aug 10, 2018
<div
className={ classNames( 'checklist', {
'is-expanded': ! this.state.hideCompleted,
'hide-completed': this.state.hideCompleted,
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, reading these CSS classes like this, they seem kinda redundant...?

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, however that's not been introduced here. I took a quick look and cleanup is more involved than I'd like to include in this PR. Let's leave it for now.

&.is-completed {
order: 0;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

onClick={ onDismiss }
aria-pressed={
/* eslint-disable-next-line no-nested-ternary */
onDismiss ? ( completed ? 'true' : 'false' ) : undefined
Copy link
Contributor

@ockham ockham Aug 13, 2018

Choose a reason for hiding this comment

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

See https://github.com/Automattic/wp-calypso/pull/26216/files#r208360821 😬

One thing you could consider is inlining the entire <ToggleContainer />, which might make things actually more readable:

{ onDismiss
	? <Focusable
		onClick={ onDismiss }
		aria-pressed={ !! completed } // Do we really need the bool strings ('true'/'false') here?
	/>
	: <div />
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Applied your suggestion in 540e0bd. I'm a bit indifferent as to the clearer approach so we can leave whatever you think is best.

Do we really need the bool strings ('true'/'false') here?

I believe this is the correct way to do it. It is how official docs show it: https://reactjs.org/docs/accessibility.html#wai-aria

Note that these are "true"/"false" strings in the DOM, a bit different from some other boolean-like DOM attributes, e.g. disabled.

const completed = reduce(
tasks,
( count, { id, completed: taskComplete } ) =>
taskComplete || get( taskStatuses, [ id, 'completed' ] ) ? count + 1 : count,
Copy link
Contributor

Choose a reason for hiding this comment

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

Worth turning

( { id, completed } ) => ! completed && ! get( this.props.taskStatuses, [ id, 'completed' ] )

into a method since we're using it in multiple places?

Copy link
Member Author

Choose a reason for hiding this comment

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

This only exists in one place in the banner now, so we can leave it. The banner, ideally, will be implemented in another way eventually.

The other usage was removed by 479f892, after I realized since we're not using connected Tasks anymore, we can always infer checklist completion based on children as they should have a completed prop.

Copy link
Contributor

Choose a reason for hiding this comment

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

The other usage was removed by 479f892, after I realized since we're not using connected Tasks anymore, we can always infer checklist completion based on children as they should have a completed prop.

This is very awesome!


`Checklist` and `Task` are components used to render checklists.

If your checklist tasks use checklist state from Redux, you can use `Task` from `blocks/checklist/tasks` to pull state by the `id` prop.
Copy link
Contributor

Choose a reason for hiding this comment

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

No more Task block, is there?

### `inferCompletedCount { bool } - default: false`

If `Task` children will have a provided `complete` prop, the `Checklist` will count the completed
tasks. This will not work when using connected tasks (see `blocks/checklist/task`).
Copy link
Contributor

Choose a reason for hiding this comment

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

No more connected tasks 🙂

Copy link
Contributor

@ockham ockham left a comment

Choose a reason for hiding this comment

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

The 'Do It' buttons don't seem to work for the Jetpack checklist 🙁

@ockham
Copy link
Contributor

ockham commented Aug 13, 2018

'Do It' buttons still don't work:

image

@sirreal sirreal force-pushed the add/checklist-components branch 2 times, most recently from 36b772d to ac2957d Compare August 13, 2018 19:58

renderPlaceholder() {
return (
<div className={ classNames( 'checklist', 'is-expanded', 'is-placeholder' ) }>
Copy link
Member Author

Choose a reason for hiding this comment

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

No need for classNames here to generate static class. However, the visibility toggle doesn't work on the placeholder, but it could. Let's leave this as it will be useful then, and handle that in a follow-up PR.

@sirreal
Copy link
Member Author

sirreal commented Aug 13, 2018

Sorry for the premature review request @ockham. I've ironed out the kinks and applied suggestions. This is ready for another look, thanks! 🙇

@sirreal sirreal removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Aug 13, 2018
@sirreal sirreal force-pushed the add/checklist-components branch from d1ee316 to 2244a56 Compare August 15, 2018 15:17
@sirreal
Copy link
Member Author

sirreal commented Aug 15, 2018

Rebased

@sirreal sirreal added [Status] Needs e2e Testing [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. [Status] Needs e2e Testing labels Aug 15, 2018
@sirreal sirreal merged commit 3bcfb52 into master Aug 15, 2018
@sirreal sirreal deleted the add/checklist-components branch August 15, 2018 16:53
siteId,
siteSlug,
tasks: tasksFromServer ? mergeObjectIntoArrayById( tasks, tasksFromServer ) : null,
Copy link
Contributor

@taggon taggon Aug 16, 2018

Choose a reason for hiding this comment

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

Sorry for this but we can't just delete the line of code since the response from the server-side can contain extra information besides whether a task completes or not. Let me give you an example. The URL of the very first post can be changed based on themes. So the server-side finds and returns its URL then this mergeObjectIntoArrayById applies the new URL to the corresponding task. Here's a link to the server-side code: 1efb3-pb

You don't need to do anything. I will handle this problem in my PR: #26721

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for mentioning that @taggon. Let's try to find a solution that works for your use case and aligns with the ideas outlined in #26015

Copy link
Contributor

Choose a reason for hiding this comment

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

Ugh, I missed that in my review. Sry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants