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

Fix/tags active inactive behaviour #939

Merged
merged 11 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 63 additions & 56 deletions src/components/node-list/node-list-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,74 @@ import NodeListRow from './node-list-row';
import NodeRowList from './node-list-row-list';

export const NodeListGroup = ({
items,
group,
allUnchecked,
checked,
collapsed,
group,
id,
name,
kind,
checked,
allUnchecked,
visibleIcon,
invisibleIcon,
onToggleChecked,
onToggleCollapsed,
onItemClick,
items,
kind,
name,
onItemChange,
onItemClick,
onItemMouseEnter,
onItemMouseLeave,
}) => (
<li
className={classnames(
'pipeline-nodelist__group',
`pipeline-nodelist__group--type-${id}`,
`pipeline-nodelist__group--kind-${kind}`,
{
'pipeline-nodelist__group--all-unchecked': allUnchecked,
}
)}
>
<h3 className="pipeline-nodelist__heading">
<NodeListRow
id={id}
kind={kind}
name={name}
label={name}
allUnchecked={allUnchecked}
checked={checked}
visibleIcon={visibleIcon}
invisibleIcon={invisibleIcon}
rowType="filter"
onChange={(e) => {
onToggleChecked(id, !e.target.checked);
}}
>
<button
aria-label={`${collapsed ? 'Show' : 'Hide'} ${name.toLowerCase()}`}
onClick={() => onToggleCollapsed(id)}
className={classnames('pipeline-type-group-toggle', {
'pipeline-type-group-toggle--alt': collapsed,
})}
/>
</NodeListRow>
</h3>
<NodeRowList
items={items}
group={group}
collapsed={collapsed}
onItemClick={onItemClick}
onItemChange={onItemChange}
onItemMouseEnter={onItemMouseEnter}
onItemMouseLeave={onItemMouseLeave}
/>
</li>
);
onToggleChecked,
onToggleCollapsed,
visibleIcon,
}) => {
const disabledGroup = items.length === 0;

return (
<li
className={classnames(
'pipeline-nodelist__group',
`pipeline-nodelist__group--type-${id}`,
`pipeline-nodelist__group--kind-${kind}`,
{
'pipeline-nodelist__group--all-unchecked': allUnchecked,
}
)}
>
<h3 className="pipeline-nodelist__heading">
<NodeListRow
allUnchecked={allUnchecked}
checked={checked}
disabled={disabledGroup}
id={id}
invisibleIcon={invisibleIcon}
kind={kind}
label={name}
name={name}
onChange={(e) => {
onToggleChecked(id, !e.target.checked);
}}
rowType="filter"
visibleIcon={visibleIcon}
>
<button
aria-label={`${collapsed ? 'Show' : 'Hide'} ${name.toLowerCase()}`}
className={classnames('pipeline-type-group-toggle', {
'pipeline-type-group-toggle--alt': collapsed,
'pipeline-type-group-toggle--disabled': disabledGroup,
})}
disabled={disabledGroup}
onClick={() => onToggleCollapsed(id)}
/>
</NodeListRow>
</h3>
<NodeRowList
collapsed={collapsed}
group={group}
items={items}
onItemChange={onItemChange}
onItemClick={onItemClick}
onItemMouseEnter={onItemMouseEnter}
onItemMouseLeave={onItemMouseLeave}
/>
</li>
);
};

export default NodeListGroup;
22 changes: 18 additions & 4 deletions src/components/node-list/node-list-group.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import { getNodeTypes } from '../../selectors/node-types';
import { setup, mockState } from '../../utils/state.mock';

describe('NodeListGroup', () => {
const items = [];

it('renders without throwing', () => {
const type = getNodeTypes(mockState.spaceflights)[0];
expect(() =>
setup.mount(<NodeListGroup id={type.id} name={type.name} />)
setup.mount(<NodeListGroup id={type.id} name={type.name} items={items} />)
).not.toThrow();
});

Expand All @@ -19,6 +21,7 @@ describe('NodeListGroup', () => {
id={type.id}
name={type.name}
onToggleChecked={onToggleChecked}
items={items}
/>
);
const checkbox = () => wrapper.find('input');
Expand All @@ -34,16 +37,22 @@ describe('NodeListGroup', () => {
id={type.id}
name={type.name}
onToggleCollapsed={onToggleCollapsed}
items={items}
/>
);
wrapper.find('.pipeline-type-group-toggle').simulate('click');
expect(onToggleCollapsed.mock.calls.length).toEqual(1);
expect(() => onToggleCollapsed.mock.calls.length.toEqual(1)).toThrow();
});

it('adds class when collapsed prop true', () => {
const type = getNodeTypes(mockState.spaceflights)[0];
const wrapper = setup.mount(
<NodeListGroup id={type.id} name={type.name} collapsed={true} />
<NodeListGroup
id={type.id}
name={type.name}
collapsed={true}
items={items}
/>
);
const children = wrapper.find('.pipeline-nodelist__children');
expect(children.hasClass('pipeline-nodelist__children--closed')).toBe(true);
Expand All @@ -52,7 +61,12 @@ describe('NodeListGroup', () => {
it('removes class when collapsed prop false', () => {
const type = getNodeTypes(mockState.spaceflights)[0];
const wrapper = setup.mount(
<NodeListGroup id={type.id} name={type.name} collapsed={false} />
<NodeListGroup
id={type.id}
name={type.name}
collapsed={false}
items={items}
/>
);
const children = wrapper.find('.pipeline-nodelist__children');
expect(children.hasClass('pipeline-nodelist__children--closed')).toBe(
Expand Down
26 changes: 13 additions & 13 deletions src/components/node-list/node-list-groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import NodeListGroup from './node-list-group';
const storedState = loadState();

const NodeListGroups = ({
items,
groups,
searchValue,
items,
onGroupToggleChanged,
onItemChange,
onItemClick,
onItemMouseEnter,
onItemMouseLeave,
onItemChange,
searchValue,
}) => {
const [collapsed, setCollapsed] = useState(storedState.groupsCollapsed || {});

Expand All @@ -32,23 +32,23 @@ const NodeListGroups = ({
<ul className="pipeline-nodelist__list">
{Object.values(groups).map((group) => (
<NodeListGroup
allUnchecked={group.allUnchecked}
checked={group.checked}
collapsed={Boolean(searchValue) ? false : collapsed[group.id]}
group={group}
id={group.id}
invisibleIcon={group.invisibleIcon}
items={items[group.id] || []}
key={group.id}
id={group.id}
name={group.name}
kind={group.kind}
checked={group.checked}
allUnchecked={group.allUnchecked}
visibleIcon={group.visibleIcon}
invisibleIcon={group.invisibleIcon}
collapsed={Boolean(searchValue) ? false : collapsed[group.id]}
onToggleCollapsed={onToggleGroupCollapsed}
onToggleChecked={onGroupToggleChanged}
onItemClick={onItemClick}
name={group.name}
onItemChange={onItemChange}
onItemClick={onItemClick}
onItemMouseEnter={onItemMouseEnter}
onItemMouseLeave={onItemMouseLeave}
onToggleChecked={onGroupToggleChanged}
onToggleCollapsed={onToggleGroupCollapsed}
visibleIcon={group.visibleIcon}
/>
))}
</ul>
Expand Down
9 changes: 6 additions & 3 deletions src/components/node-list/node-list-groups.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ describe('NodeListGroups', () => {
const toggle = () => wrapper.find('.pipeline-type-group-toggle').first();
expect(nodeList().length).toBe(1);
expect(toggle().hasClass('pipeline-type-group-toggle--alt')).toBe(false);
toggle().simulate('click');
expect(nodeList().length).toBe(1);
expect(toggle().hasClass('pipeline-type-group-toggle--alt')).toBe(true);
expect(() => {
toggle().hasClass('pipeline-type-group-toggle--disabled').toBe(false);
toggle().simulate('click');
expect(nodeList().length).toBe(1);
expect(toggle().hasClass('pipeline-type-group-toggle--alt')).toBe(true);
}).toThrow();
});

it('handles group checkbox change events', () => {
Expand Down
5 changes: 5 additions & 0 deletions src/components/node-list/styles/_group.scss
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,9 @@ $placeholder-fade: 120px;
&--alt {
transform: rotate(90deg);
}

&--disabled {
color: $color-button-disabled;
transform: rotate(90deg);
}
}
2 changes: 1 addition & 1 deletion src/components/node-list/styles/_row-label.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
}

&--disabled {
opacity: 0.3;
opacity: 0.3 !important;
}

b {
Expand Down
2 changes: 1 addition & 1 deletion src/components/node-list/styles/_section.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
margin: 6px $section-title-padding-x 12px ($section-title-padding-x + 0.085);
font-weight: normal;
font-size: 1.6em;
opacity: 0.65;
opacity: 0.55;
user-select: none;
}
1 change: 1 addition & 0 deletions src/styles/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ $color-primary-2: #107da5;
$color-link: rgba($color-primary, 0.85);
$color-button: #003464;
$color-button-hovered: #005d92;
$color-button-disabled: rgba($color-light, 0.3);

//-- Theme colours as SCSS variables --//

Expand Down