Skip to content

Commit

Permalink
split node-list-row into row and filter-row
Browse files Browse the repository at this point in the history
Signed-off-by: Huong Nguyen <huongg1409@gmail>
  • Loading branch information
Huong Nguyen committed Oct 17, 2024
1 parent 39c8db8 commit ca8b72c
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 7 deletions.
83 changes: 83 additions & 0 deletions src/components/node-list/filter-row.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import React from 'react';
import classnames from 'classnames';
import { replaceAngleBracketMatches } from '../../utils';
import VisibleIcon from '../icons/visible';
import InvisibleIcon from '../icons/invisible';
import { NodeListRowToggle } from '../node-list-row-toggle/node-list-row-toggle';

// The exact fixed height of a row as measured by getBoundingClientRect()
export const nodeListRowHeight = 32;
export const FilterRow = ({
allUnchecked,
checked,
children,
container: Container = 'div',
count,
id,
invisibleIcon = InvisibleIcon,
kind,
label,
name,
onChange,
onClick,
onMouseEnter,
onMouseLeave,
visible,
visibleIcon = VisibleIcon,
}) => {
const VisibilityIcon = checked ? visibleIcon : invisibleIcon;

return (
<Container
className={classnames(
'node-list-row kedro',
`node-list-row--kind-${kind}`,
{
'node-list-row--visible': visible,
'node-list-row--unchecked': !checked,
}
)}
title={name}
onMouseEnter={visible ? onMouseEnter : null}
onMouseLeave={visible ? onMouseLeave : null}
>
<button
className={classnames(
'node-list-row__text',
`node-list-row__text--kind-${kind}`
)}
// data-test={`nodelist-${icon}-${children ? null : name}`}
onClick={onClick}
onFocus={onMouseEnter}
onBlur={onMouseLeave}
title={children ? null : name}
>
<span
className={classnames(
'node-list-row__label',
`node-list-row__label--kind-${kind}`
)}
dangerouslySetInnerHTML={{
__html: replaceAngleBracketMatches(label),
}}
/>
</button>
<span onClick={onClick} className={'node-list-row__count'}>
{count}
</span>
{VisibilityIcon && (
<NodeListRowToggle
allUnchecked={allUnchecked}
className={'node-list-row__icon'}
IconComponent={VisibilityIcon}
id={id}
isChecked={checked}
kind={kind}
name={name}
onChange={onChange}
/>
)}
{children}
</Container>
);
};
6 changes: 3 additions & 3 deletions src/components/node-list/node-list-group.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import classnames from 'classnames';
import { NodeListRow } from './node-list-row';
import { FilterRow } from './filter-row';
import NodeRowList from './node-list-row-list';

export const NodeListGroup = ({
Expand Down Expand Up @@ -35,7 +35,7 @@ export const NodeListGroup = ({
)}
>
<h3 className="pipeline-nodelist__heading">
<NodeListRow
<FilterRow
allUnchecked={allUnchecked}
checked={checked}
disabled={disabledGroup}
Expand All @@ -59,7 +59,7 @@ export const NodeListGroup = ({
disabled={disabledGroup}
onClick={() => onToggleCollapsed(id)}
/>
</NodeListRow>
</FilterRow>
</h3>
<NodeRowList
collapsed={collapsed}
Expand Down
4 changes: 2 additions & 2 deletions src/components/node-list/node-list-row-list.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import modifiers from '../../utils/modifiers';
import { NodeListRow, nodeListRowHeight } from './node-list-row';
import { FilterRow, nodeListRowHeight } from './filter-row';
import LazyList from '../lazy-list';

const NodeRowList = ({
Expand Down Expand Up @@ -51,7 +51,7 @@ const NodeRowList = ({
style={lowerStyle}
/>
{items.slice(start, end).map((item) => (
<NodeListRow
<FilterRow
container="li"
key={item.id}
id={item.id}
Expand Down
4 changes: 2 additions & 2 deletions src/components/node-list/node-list-tree-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import ChevronRightIcon from '@mui/icons-material/ChevronRight';
import { TreeItem } from '@mui/x-tree-view';
import { NodeListRow } from './node-list-row';
import { Row } from './row';

const arrowIconColor = '#8e8e90';

Expand All @@ -24,7 +24,7 @@ const NodeListTreeItem = ({
collapseIcon={<ExpandMoreIcon style={{ color: arrowIconColor }} />}
expandIcon={<ChevronRightIcon style={{ color: arrowIconColor }} />}
label={
<NodeListRow
<Row
container="div"
key={data.id}
id={data.id}
Expand Down
3 changes: 3 additions & 0 deletions src/components/node-list/node-list-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const TreeListProvider = ({
onItemChange,
onItemMouseEnter,
onItemMouseLeave,
onToggleHoveredFocusMode,
onItemClick,
onNodeToggleExpanded,
focusMode,
Expand Down Expand Up @@ -161,6 +162,7 @@ const TreeListProvider = ({
onItemMouseEnter={onItemMouseEnter}
onItemMouseLeave={onItemMouseLeave}
onItemChange={onItemChange}
onToggleHoveredFocusMode={onToggleHoveredFocusMode}
onItemClick={onItemClick}
key={uniqueId(node.id)}
isSlicingPipelineApplied={isSlicingPipelineApplied}
Expand Down Expand Up @@ -231,6 +233,7 @@ const TreeListProvider = ({
onItemMouseEnter={onItemMouseEnter}
onItemMouseLeave={onItemMouseLeave}
onItemChange={onItemChange}
onToggleHoveredFocusMode={onToggleHoveredFocusMode}
onItemClick={onItemClick}
key={uniqueId(node.id)}
isSlicingPipelineApplied={isSlicingPipelineApplied}
Expand Down
2 changes: 2 additions & 0 deletions src/components/node-list/node-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const NodeList = ({
onItemClick,
onItemMouseEnter,
onItemMouseLeave,
onToggleHoveredFocusMode,
onItemChange,
onModularPipelineToggleExpanded,
focusMode,
Expand Down Expand Up @@ -65,6 +66,7 @@ const NodeList = ({
onItemClick={onItemClick}
onItemMouseEnter={onItemMouseEnter}
onItemMouseLeave={onItemMouseLeave}
onToggleHoveredFocusMode={onToggleHoveredFocusMode}
onItemChange={onItemChange}
onNodeToggleExpanded={onModularPipelineToggleExpanded}
focusMode={focusMode}
Expand Down
143 changes: 143 additions & 0 deletions src/components/node-list/row.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import React from 'react';
import classnames from 'classnames';
import { replaceAngleBracketMatches } from '../../utils';
import NodeIcon from '../icons/node-icon';
import VisibleIcon from '../icons/visible';
import InvisibleIcon from '../icons/invisible';
import FocusModeIcon from '../icons/focus-mode';
import { NodeListRowToggle } from '../node-list-row-toggle/node-list-row-toggle';

// The exact fixed height of a row as measured by getBoundingClientRect()
export const nodeListRowHeight = 32;

export const Row = ({
active,
allUnchecked,
checked,
children,
container: Container = 'div',
disabled,
faded,
focused,
focusModeIcon = FocusModeIcon,
highlight,
icon,
id,
invisibleIcon = InvisibleIcon,
isSlicingPipelineApplied,
kind,
label,
name,
onChange,
onClick,
onMouseEnter,
onMouseLeave,
onToggleHoveredFocusMode,
rowType,
selected,
type,
visible,
visibleIcon = VisibleIcon,
}) => {
const isModularPipeline = type === 'modularPipeline';
const FocusIcon = isModularPipeline ? focusModeIcon : null;
const isChecked = isModularPipeline ? checked || focused : checked;
const VisibilityIcon = isChecked ? visibleIcon : invisibleIcon;
const isButton = onClick && kind !== 'filter';
const TextButton = isButton ? 'button' : 'div';

return (
<Container
className={classnames(
'node-list-row kedro',
`node-list-row--kind-${kind}`,
{
'node-list-row--visible': visible,
'node-list-row--active': active,
'node-list-row--selected':
selected || (!isSlicingPipelineApplied && highlight),
'node-list-row--disabled': disabled,
'node-list-row--unchecked': !isChecked,
'node-list-row--overwrite': !(active || selected),
}
)}
title={name}
onMouseEnter={visible ? onMouseEnter : null}
onMouseLeave={visible ? onMouseLeave : null}
>
<NodeIcon
className={classnames(
'node-list-row__type-icon',
'node-list-row__icon',
{
'node-list-row__type-icon--faded': faded,
'node-list-row__type-icon--disabled': disabled,
// 'node-list-row__type-icon--nested': !children,
'node-list-row__type-icon--active': active,
'node-list-row__type-icon--selected': selected,
}
)}
icon={icon}
/>
<TextButton
className={classnames(
'node-list-row__text',
`node-list-row__text--kind-${kind}`,
`node-list-row__text--${rowType}`
)}
// data-test={`nodelist-${icon}-${children ? null : name}`}
onClick={onClick}
onFocus={onMouseEnter}
onBlur={onMouseLeave}
title={name}
>
<span
className={classnames(
'node-list-row__label',
`node-list-row__label--kind-${kind}`,
{
'node-list-row__label--faded': faded,
'node-list-row__label--disabled': disabled,
}
)}
dangerouslySetInnerHTML={{
__html: replaceAngleBracketMatches(label),
}}
/>
</TextButton>
{VisibilityIcon && (
<NodeListRowToggle
allUnchecked={allUnchecked}
className={'node-list-row__icon'}
disabled={isModularPipeline ? focused : disabled}
focusChecked={isModularPipeline ? false : focused}
IconComponent={VisibilityIcon}
id={id}
isChecked={isChecked}
kind={kind}
name={name}
onChange={onChange}
selected={selected}
/>
)}
{FocusIcon && (
<NodeListRowToggle
allUnchecked={allUnchecked}
className={'node-list-row__icon'}
disabled={disabled}
focusChecked={focused}
IconComponent={FocusIcon}
id={`${id}-focus`}
isChecked={isChecked}
kind={kind}
name={name}
onChange={onChange}
onToggleHoveredFocusMode={onToggleHoveredFocusMode}
selected={selected}
dataIconType="focus"
/>
)}
{children}
</Container>
);
};

0 comments on commit ca8b72c

Please sign in to comment.