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

Move the Expand all modular pipelines toggle from the settings panel #1858

Merged
merged 14 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
36 changes: 11 additions & 25 deletions cypress/tests/ui/toolbar/global-toolbar.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,38 +146,24 @@ describe('Global Toolbar', () => {
});
});

it('verifies that users can expand all modular pipelines on first load. #TC-7', () => {
it('verifies that users can expand all modular pipelines directly from the toolbar. #TC-7', () => {
const modularPipelineChildNodeText = 'Create Derived Features';

// Alias
cy.get('[data-test="pipeline-toggle-input-expandAllPipelines"]').as(
'isExpandAllPipelinesCheckBox'
);
// Alias for better readability
cy.get('[data-test="expand-all-pipelines-toggle"]').as('expandAllPipelinesToggle');

// Assert before action
cy.get('@isExpandAllPipelinesCheckBox').should('not.be.checked');
cy.get('.pipeline-node__text').should(
'not.contain',
modularPipelineChildNodeText
);
cy.get('[role="treeitem"]')
.should('have.attr', 'aria-expanded')
.should('eq', 'false');
cy.get('@expandAllPipelinesToggle').should('not.be.checked');
cy.get('.pipeline-node__text').should('not.contain', modularPipelineChildNodeText);
cy.get('[role="treeitem"]').should('have.attr', 'aria-expanded', 'false');

// Action
cy.get('@isExpandAllPipelinesCheckBox').check({ force: true });
cy.get('[data-test="Apply changes and close in Settings Modal"]').click({
force: true,
});
// Action - toggling the expand all pipelines directly from the toolbar
cy.get('@expandAllPipelinesToggle').click();

// Assert after action
cy.get('[role="treeitem"]', { timeout: 5000 })
.should('have.attr', 'aria-expanded')
.should('eq', 'true');
cy.get('.pipeline-node__text').should(
'contain',
modularPipelineChildNodeText
);
cy.get('[role="treeitem"]')
.should('have.attr', 'aria-expanded', 'true');
cy.get('.pipeline-node__text').should('contain', modularPipelineChildNodeText);
});
});
});
1 change: 1 addition & 0 deletions src/components/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ App.propTypes = {
labelBtn: PropTypes.bool,
layerBtn: PropTypes.bool,
exportBtn: PropTypes.bool,
pipelineBtn: PropTypes.bool,
sidebar: PropTypes.bool,
}),
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,15 @@
text-align: right;
width: 100%;
}

.version-reminder-and-run-details-button-wrapper {
SajidAlamQB marked this conversation as resolved.
Show resolved Hide resolved
align-items: baseline;
display: flex;
justify-content: space-between;
width: 100%;
margin-top: 50px;

.button:first-of-type {
margin-right: 20px;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ import {
toggleLayers,
toggleSidebar,
toggleTextLabels,
changeFlag,
} from '../../actions';
import { loadInitialPipelineData } from '../../actions/pipelines';
import IconButton from '../ui/icon-button';
import LabelIcon from '../icons/label';
import ExportIcon from '../icons/export';
import LayersIcon from '../icons/layers';
import PrimaryToolbar from '../primary-toolbar';
import { getVisibleLayerIDs } from '../../selectors/disabled';
import ExpandPipelinesIcon from '../icons/expand-pipelines';
import CollapsePipelinesIcon from '../icons/collapse-pipelines';
import { useGeneratePathname } from '../../utils/hooks/use-generate-pathname';

/**
* Main controls for filtering the chart data
Expand All @@ -28,54 +33,84 @@ export const FlowchartPrimaryToolbar = ({
textLabels,
visible,
visibleLayers,
}) => (
<>
<PrimaryToolbar
displaySidebar={displaySidebar}
onToggleSidebar={onToggleSidebar}
visible={visible}
>
<IconButton
active={textLabels}
ariaLabel={`${textLabels ? 'Hide' : 'Show'} text labels`}
className={'pipeline-menu-button--labels'}
dataTest={'btnToggleLabels'}
icon={LabelIcon}
labelText={`${textLabels ? 'Hide' : 'Show'} text labels`}
onClick={() => onToggleTextLabels(!textLabels)}
visible={visible.labelBtn}
/>
<IconButton
active={visibleLayers}
ariaLabel={`Turn data layers ${visibleLayers ? 'off' : 'on'}`}
className={'pipeline-menu-button--layers'}
dataHeapEvent={`visible.layers.${visibleLayers}`}
dataTest={'btnToggleLayers'}
disabled={disableLayerBtn}
icon={LayersIcon}
labelText={`${visibleLayers ? 'Hide' : 'Show'} layers`}
onClick={() => onToggleLayers(!visibleLayers)}
visible={visible.layerBtn}
/>
<IconButton
ariaLabel="Export graph as SVG or PNG"
className={'pipeline-menu-button--export'}
dataTest={'btnExportGraph'}
icon={ExportIcon}
labelText="Export visualisation"
onClick={() => onToggleExportModal(true)}
visible={visible.exportBtn}
/>
</PrimaryToolbar>
</>
);
expandedPipelines,
onToggleExpandAllPipelines,
}) => {
const { toSetQueryParam } = useGeneratePathname();

const handleToggleExpandAllPipelines = () => {
const isExpanded = !expandedPipelines;
onToggleExpandAllPipelines(isExpanded);
toSetQueryParam('expandAllPipelines', isExpanded.toString());
};

return (
<>
<PrimaryToolbar
displaySidebar={displaySidebar}
onToggleSidebar={onToggleSidebar}
visible={visible}
>
<IconButton
active={textLabels}
ariaLabel={`${textLabels ? 'Hide' : 'Show'} text labels`}
className={'pipeline-menu-button--labels'}
dataTest={'btnToggleLabels'}
icon={LabelIcon}
labelText={`${textLabels ? 'Hide' : 'Show'} text labels`}
onClick={() => onToggleTextLabels(!textLabels)}
visible={visible.labelBtn}
/>
<IconButton
active={visibleLayers}
ariaLabel={`Turn data layers ${visibleLayers ? 'off' : 'on'}`}
className={'pipeline-menu-button--layers'}
dataHeapEvent={`visible.layers.${visibleLayers}`}
dataTest={'btnToggleLayers'}
disabled={disableLayerBtn}
icon={LayersIcon}
labelText={`${visibleLayers ? 'Hide' : 'Show'} layers`}
onClick={() => onToggleLayers(!visibleLayers)}
visible={visible.layerBtn}
/>
<IconButton
active={expandedPipelines}
ariaLabel={
expandedPipelines
? 'Collapse all modular pipelines'
: 'Expand all modular pipelines'
}
className={'pipeline-menu-button--pipeline'}
dataTest={'btnTogglePipeline'}
icon={expandedPipelines ? CollapsePipelinesIcon : ExpandPipelinesIcon}
labelText={
expandedPipelines ? 'Collapse pipelines' : 'Expand pipelines'
}
data-test={'expand-all-pipelines-toggle'}
onClick={handleToggleExpandAllPipelines}
visible={visible.pipelineBtn}
/>
<IconButton
ariaLabel="Export graph as SVG or PNG"
className={'pipeline-menu-button--export'}
dataTest={'btnExportGraph'}
icon={ExportIcon}
labelText="Export visualisation"
onClick={() => onToggleExportModal(true)}
visible={visible.exportBtn}
/>
</PrimaryToolbar>
</>
);
};

export const mapStateToProps = (state) => ({
disableLayerBtn: !state.layer.ids.length,
displaySidebar: state.display.sidebar,
textLabels: state.textLabels,
visible: state.visible,
visibleLayers: Boolean(getVisibleLayerIDs(state).length),
expandedPipelines: state.flags.expandAllPipelines,
});

export const mapDispatchToProps = (dispatch) => ({
Expand All @@ -91,6 +126,10 @@ export const mapDispatchToProps = (dispatch) => ({
onToggleTextLabels: (value) => {
dispatch(toggleTextLabels(Boolean(value)));
},
onToggleExpandAllPipelines: (isExpanded) => {
dispatch(changeFlag('expandAllPipelines', isExpanded));
dispatch(loadInitialPipelineData());
jitu5 marked this conversation as resolved.
Show resolved Hide resolved
SajidAlamQB marked this conversation as resolved.
Show resolved Hide resolved
},
});

export default connect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@ import ConnectedFlowchartPrimaryToolbar, {
} from './flowchart-primary-toolbar';
import { mockState, setup } from '../../utils/state.mock';

jest.mock('../../utils/hooks/use-generate-pathname', () => ({
useGeneratePathname: () => ({
toSetQueryParam: jest.fn(),
}),
}));

describe('PrimaryToolbar', () => {
it('renders without crashing', () => {
const wrapper = setup.mount(<ConnectedFlowchartPrimaryToolbar />);
expect(wrapper.find('.pipeline-icon-toolbar__button').length).toBe(4);
expect(wrapper.find('.pipeline-icon-toolbar__button').length).toBe(5);
});

it('hides all buttons (except menu button) when visible prop is false for each of them', () => {
const visible = {
labelBtn: false,
layerBtn: false,
exportBtn: false,
pipelineBtn: false,
};
const wrapper = setup.mount(<ConnectedFlowchartPrimaryToolbar />, {
visible,
Expand All @@ -31,14 +38,15 @@ describe('PrimaryToolbar', () => {
const wrapper = setup.mount(<ConnectedFlowchartPrimaryToolbar />, {
visible,
});
expect(wrapper.find('.pipeline-icon-toolbar__button').length).toBe(3);
expect(wrapper.find('.pipeline-icon-toolbar__button').length).toBe(4);
SajidAlamQB marked this conversation as resolved.
Show resolved Hide resolved
});

const functionCalls = [
['.pipeline-menu-button--menu', 'onToggleSidebar'],
['.pipeline-menu-button--labels', 'onToggleTextLabels'],
['.pipeline-menu-button--export', 'onToggleExportModal'],
['.pipeline-menu-button--layers', 'onToggleLayers'],
['.pipeline-menu-button--pipeline', 'onToggleExpandAllPipelines'],
];

test.each(functionCalls)(
Expand Down Expand Up @@ -70,6 +78,7 @@ describe('PrimaryToolbar', () => {
settingsModal: expect.any(Boolean),
labelBtn: expect.any(Boolean),
layerBtn: expect.any(Boolean),
pipelineBtn: expect.any(Boolean),
sidebar: expect.any(Boolean),
}),
visibleLayers: expect.any(Boolean),
Expand Down Expand Up @@ -113,5 +122,15 @@ describe('PrimaryToolbar', () => {
type: 'TOGGLE_TEXT_LABELS',
});
});

it('onToggleExpandAllPipelines', () => {
const dispatch = jest.fn();
mapDispatchToProps(dispatch).onToggleExpandAllPipelines(true);
expect(dispatch.mock.calls[0][0]).toEqual({
name: 'expandAllPipelines',
type: 'CHANGE_FLAG',
value: true,
});
});
});
});
4 changes: 4 additions & 0 deletions src/components/global-toolbar/global-toolbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
}
}

.pipeline-menu-button--pipeline svg {
opacity: 0.7;
}

.pipeline-global-routes-toolbar a.active .pipeline-menu-button--link {
background-color: var(--color-global-toolbar-active-btn);
border-right: 1px solid var(--color-border-line);
Expand Down
1 change: 1 addition & 0 deletions src/components/global-toolbar/global-toolbar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe('GlobalToolbar', () => {
miniMapBtn: true,
modularPipelineFocusMode: null,
metadataModal: false,
pipelineBtn: true,
settingsModal: false,
shareableUrlModal: false,
sidebar: true,
Expand Down
9 changes: 9 additions & 0 deletions src/components/icons/collapse-pipelines.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';

const CollapsePipelinesIcon = ({ className }) => (
<svg className={className} viewBox="0 0 18 18">
<path d="M7.6923 10.3077V17.5H5.73079V12.2692H0.5V10.3077H7.6923ZM12.2692 0.5V5.73079H17.5V7.6923H10.3077V0.5H12.2692Z" />
</svg>
);

export default CollapsePipelinesIcon;
9 changes: 9 additions & 0 deletions src/components/icons/expand-pipelines.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';

const ExpandPipelinesIcon = ({ className }) => (
<svg className={className} viewBox="0 0 18 18">
<path d="M0.5 17.5V10.3077H2.46151V15.5385H7.6923V17.5H0.5ZM15.5385 7.6923V2.46151H10.3077V0.5H17.5V7.6923H15.5385Z" />
</svg>
);

export default ExpandPipelinesIcon;
Loading