Add toggle to experimental task item (https://github.com/woocommerce/woocommerce-admin/pull/7632)
* Add toggle to experimental task item This commit adds a toggle to experimental task item * Fixed onClick for expandable tasks * Add changelog * Fixed changelog # Conflicts: # packages/experimental/CHANGELOG.md * Add callback * Fixed class name * Add useEffect to experimental-list * Fixed tests * Fixed experimental-list useEffect * Add callback to Home screen task list * Fixed missing border error * Fixed wrapper classes * Fixed lint * Added missing semicolon Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
This commit is contained in:
parent
7f38f6fd0a
commit
2f1b03cc29
|
@ -2,7 +2,7 @@
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
import { __, _n, sprintf } from '@wordpress/i18n';
|
import { __, _n, sprintf } from '@wordpress/i18n';
|
||||||
import { useEffect, useRef, useState } from '@wordpress/element';
|
import { useEffect, useRef } from '@wordpress/element';
|
||||||
import { Button, Card, CardHeader } from '@wordpress/components';
|
import { Button, Card, CardHeader } from '@wordpress/components';
|
||||||
import { useSelect, useDispatch } from '@wordpress/data';
|
import { useSelect, useDispatch } from '@wordpress/data';
|
||||||
import { EllipsisMenu, Badge } from '@woocommerce/components';
|
import { EllipsisMenu, Badge } from '@woocommerce/components';
|
||||||
|
@ -86,10 +86,6 @@ export const TaskList = ( {
|
||||||
! dismissedTasks.includes( task.key )
|
! dismissedTasks.includes( task.key )
|
||||||
);
|
);
|
||||||
|
|
||||||
const [ currentTask, setCurrentTask ] = useState(
|
|
||||||
incompleteTasks[ 0 ]?.key
|
|
||||||
);
|
|
||||||
|
|
||||||
const possiblyCompleteTaskList = () => {
|
const possiblyCompleteTaskList = () => {
|
||||||
const taskListVariableName = `woocommerce_${ name }_complete`;
|
const taskListVariableName = `woocommerce_${ name }_complete`;
|
||||||
const taskListToComplete = isComplete
|
const taskListToComplete = isComplete
|
||||||
|
@ -349,15 +345,9 @@ export const TaskList = ( {
|
||||||
title={ task.title }
|
title={ task.title }
|
||||||
completed={ task.completed }
|
completed={ task.completed }
|
||||||
content={ task.content }
|
content={ task.content }
|
||||||
onClick={
|
expandable={ expandingItems && task.expandable }
|
||||||
! expandingItems || task.completed
|
expanded={ expandingItems && task.expanded }
|
||||||
? task.onClick
|
onClick={ task.onClick }
|
||||||
: () => setCurrentTask( task.key )
|
|
||||||
}
|
|
||||||
expandable={ expandingItems }
|
|
||||||
expanded={
|
|
||||||
expandingItems && currentTask === task.key
|
|
||||||
}
|
|
||||||
onDismiss={
|
onDismiss={
|
||||||
task.isDismissable
|
task.isDismissable
|
||||||
? () => dismissTask( task )
|
? () => dismissTask( task )
|
||||||
|
@ -370,9 +360,12 @@ export const TaskList = ( {
|
||||||
}
|
}
|
||||||
time={ task.time }
|
time={ task.time }
|
||||||
level={ task.level }
|
level={ task.level }
|
||||||
action={ task.onClick }
|
action={ task.action }
|
||||||
actionLabel={ task.action }
|
actionLabel={ task.actionLabel }
|
||||||
additionalInfo={ task.additionalInfo }
|
additionalInfo={ task.additionalInfo }
|
||||||
|
showActionButton={ task.showActionButton }
|
||||||
|
onExpand={ task.onExpand }
|
||||||
|
onCollapse={ task.onCollapse }
|
||||||
/>
|
/>
|
||||||
) ) }
|
) ) }
|
||||||
</ListComp>
|
</ListComp>
|
||||||
|
|
|
@ -92,6 +92,9 @@ describe( 'TaskDashboard and TaskList', () => {
|
||||||
type: 'setup',
|
type: 'setup',
|
||||||
action: 'CTA (optional)',
|
action: 'CTA (optional)',
|
||||||
content: 'This is the optional task content',
|
content: 'This is the optional task content',
|
||||||
|
additionalInfo: 'This is the task additional info',
|
||||||
|
expandable: true,
|
||||||
|
expanded: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'required',
|
key: 'required',
|
||||||
|
@ -103,7 +106,9 @@ describe( 'TaskDashboard and TaskList', () => {
|
||||||
isDismissable: false,
|
isDismissable: false,
|
||||||
type: 'setup',
|
type: 'setup',
|
||||||
action: 'CTA (required)',
|
action: 'CTA (required)',
|
||||||
|
actionLabel: 'This is the action label',
|
||||||
content: 'This is the required task content',
|
content: 'This is the required task content',
|
||||||
|
expandable: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'completed',
|
key: 'completed',
|
||||||
|
@ -730,25 +735,15 @@ describe( 'TaskDashboard and TaskList', () => {
|
||||||
},
|
},
|
||||||
] );
|
] );
|
||||||
await act( async () => {
|
await act( async () => {
|
||||||
const { container, queryByText } = render(
|
const { queryByText } = render( <TaskDashboard query={ {} } /> );
|
||||||
<TaskDashboard query={ {} } />
|
|
||||||
);
|
|
||||||
|
|
||||||
// Expect the first incomplete task to be expanded
|
// Expect the first incomplete task to be expanded
|
||||||
expect(
|
expect(
|
||||||
(
|
queryByText( 'This is the optional task content' )
|
||||||
await findByText(
|
).not.toBeNull();
|
||||||
container,
|
|
||||||
'This is the optional task content'
|
|
||||||
)
|
|
||||||
).parentElement.style.maxHeight
|
|
||||||
).not.toBe( '0' );
|
|
||||||
|
|
||||||
// Expect the second not to be.
|
// Expect the second not to be.
|
||||||
expect(
|
expect( queryByText( 'This is the action label' ) ).toBeNull();
|
||||||
queryByText( 'This is the required task content' ).parentElement
|
|
||||||
.style.maxHeight
|
|
||||||
).toBe( '0' );
|
|
||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
- Adjust task-item css class to prevent css conflicts. #7593
|
- Adjust task-item css class to prevent css conflicts. #7593
|
||||||
- Update task-item logic to only display content when expanded is true. #7611
|
- Update task-item logic to only display content when expanded is true. #7611
|
||||||
|
- Add expandable tasklist item. #7632
|
||||||
|
|
||||||
# 1.5.1
|
# 1.5.1
|
||||||
|
|
||||||
|
|
|
@ -223,6 +223,10 @@ export const ExperimentalCollapsibleList: React.FC< CollapsibleListProps > = ( {
|
||||||
'woocommerce-experimental-list'
|
'woocommerce-experimental-list'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const wrapperClasses = classnames( {
|
||||||
|
'woocommerce-experimental-list-wrapper': ! isCollapsed,
|
||||||
|
} );
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ExperimentalList { ...listProps } className={ listClasses }>
|
<ExperimentalList { ...listProps } className={ listClasses }>
|
||||||
{ [
|
{ [
|
||||||
|
@ -244,6 +248,7 @@ export const ExperimentalCollapsibleList: React.FC< CollapsibleListProps > = ( {
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
className={ wrapperClasses }
|
||||||
ref={ collapseContainerRef }
|
ref={ collapseContainerRef }
|
||||||
style={ transitionStyles }
|
style={ transitionStyles }
|
||||||
>
|
>
|
||||||
|
|
|
@ -37,3 +37,7 @@
|
||||||
transition: max-height 500ms;
|
transition: max-height 500ms;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.woocommerce-experimental-list-wrapper {
|
||||||
|
border-top: 1px solid $gray-100;
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
/**
|
/**
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
import { createElement, Fragment } from '@wordpress/element';
|
import {
|
||||||
|
createElement,
|
||||||
|
Fragment,
|
||||||
|
useEffect,
|
||||||
|
useState,
|
||||||
|
} from '@wordpress/element';
|
||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
import { Icon, check } from '@wordpress/icons';
|
import { Icon, check } from '@wordpress/icons';
|
||||||
import { Button, Tooltip } from '@wordpress/components';
|
import { Button, Tooltip } from '@wordpress/components';
|
||||||
|
@ -35,8 +40,10 @@ type TaskItemProps = {
|
||||||
title: string;
|
title: string;
|
||||||
completed: boolean;
|
completed: boolean;
|
||||||
onClick: () => void;
|
onClick: () => void;
|
||||||
|
onCollapse?: () => void;
|
||||||
onDelete?: () => void;
|
onDelete?: () => void;
|
||||||
onDismiss?: () => void;
|
onDismiss?: () => void;
|
||||||
|
onExpand?: () => void;
|
||||||
remindMeLater?: () => void;
|
remindMeLater?: () => void;
|
||||||
additionalInfo?: string;
|
additionalInfo?: string;
|
||||||
time?: string;
|
time?: string;
|
||||||
|
@ -100,7 +107,9 @@ export const TaskItem: React.FC< TaskItemProps > = ( {
|
||||||
completed,
|
completed,
|
||||||
title,
|
title,
|
||||||
onDelete,
|
onDelete,
|
||||||
|
onCollapse,
|
||||||
onDismiss,
|
onDismiss,
|
||||||
|
onExpand,
|
||||||
remindMeLater,
|
remindMeLater,
|
||||||
onClick,
|
onClick,
|
||||||
additionalInfo,
|
additionalInfo,
|
||||||
|
@ -114,9 +123,14 @@ export const TaskItem: React.FC< TaskItemProps > = ( {
|
||||||
actionLabel,
|
actionLabel,
|
||||||
...listItemProps
|
...listItemProps
|
||||||
} ) => {
|
} ) => {
|
||||||
|
const [ isTaskExpanded, setTaskExpanded ] = useState( expanded );
|
||||||
|
useEffect( () => {
|
||||||
|
setTaskExpanded( expanded );
|
||||||
|
}, [ expanded ] );
|
||||||
|
|
||||||
const className = classnames( 'woocommerce-task-list__item', {
|
const className = classnames( 'woocommerce-task-list__item', {
|
||||||
complete: completed,
|
complete: completed,
|
||||||
expanded,
|
expanded: isTaskExpanded,
|
||||||
'level-2': level === 2 && ! completed,
|
'level-2': level === 2 && ! completed,
|
||||||
'level-1': level === 1 && ! completed,
|
'level-1': level === 1 && ! completed,
|
||||||
} );
|
} );
|
||||||
|
@ -128,11 +142,25 @@ export const TaskItem: React.FC< TaskItemProps > = ( {
|
||||||
( ( onDismiss || remindMeLater ) && ! completed ) ||
|
( ( onDismiss || remindMeLater ) && ! completed ) ||
|
||||||
( onDelete && completed );
|
( onDelete && completed );
|
||||||
|
|
||||||
|
const toggleActionVisibility = () => {
|
||||||
|
setTaskExpanded( ! isTaskExpanded );
|
||||||
|
if ( isTaskExpanded && onExpand ) {
|
||||||
|
onExpand();
|
||||||
|
}
|
||||||
|
if ( ! isTaskExpanded && onCollapse ) {
|
||||||
|
onCollapse();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ListItem
|
<ListItem
|
||||||
disableGutters
|
disableGutters
|
||||||
className={ className }
|
className={ className }
|
||||||
onClick={ onClick }
|
onClick={
|
||||||
|
expandable && showActionButton
|
||||||
|
? toggleActionVisibility
|
||||||
|
: onClick
|
||||||
|
}
|
||||||
{ ...listItemProps }
|
{ ...listItemProps }
|
||||||
>
|
>
|
||||||
<OptionalTaskTooltip level={ level } completed={ completed }>
|
<OptionalTaskTooltip level={ level } completed={ completed }>
|
||||||
|
@ -159,7 +187,7 @@ export const TaskItem: React.FC< TaskItemProps > = ( {
|
||||||
</span>
|
</span>
|
||||||
<OptionalExpansionWrapper
|
<OptionalExpansionWrapper
|
||||||
expandable={ expandable }
|
expandable={ expandable }
|
||||||
expanded={ expanded }
|
expanded={ isTaskExpanded }
|
||||||
>
|
>
|
||||||
<div className="woocommerce-task-list__item-expandable-content">
|
<div className="woocommerce-task-list__item-expandable-content">
|
||||||
{ content }
|
{ content }
|
||||||
|
|
Loading…
Reference in New Issue