Skip to content

Commit

Permalink
Refactor modular pipeline expansions to instantly update UI (#2225)
Browse files Browse the repository at this point in the history
* Update flowchart-primary-toolbar.js

Signed-off-by: Sajid Alam <[email protected]>

* Update disabled.js

Signed-off-by: Sajid Alam <[email protected]>

* Update flowchart-primary-toolbar.js

Signed-off-by: Sajid Alam <[email protected]>

* use toggleModularPipelineExpanded action

Signed-off-by: Sajid Alam <[email protected]>

* fix test

Signed-off-by: Sajid Alam <[email protected]>

* Update disabled.js

Signed-off-by: Sajid Alam <[email protected]>

* Update flowchart-primary-toolbar.js

Signed-off-by: Sajid Alam <[email protected]>

* add check for modularpipelinefocus

Signed-off-by: Sajid Alam <[email protected]>

* exclude root from modularPipelineIDs

Signed-off-by: Sajid Alam <[email protected]>

* Update flowchart-primary-toolbar.test.js

Signed-off-by: Sajid Alam <[email protected]>

* revert disabled

Signed-off-by: Sajid Alam <[email protected]>

* Add new reducer to hanlde update state for when toggle expanding all pipelines

Signed-off-by: Huong Nguyen <[email protected]>

* rename and clean up code

Signed-off-by: Sajid Alam <[email protected]>

* changes based on review

Signed-off-by: Sajid Alam <[email protected]>

* fix test

Signed-off-by: Sajid Alam <[email protected]>

* undo rename

Signed-off-by: Sajid Alam <[email protected]>

* Update RELEASE.md

Signed-off-by: Sajid Alam <[email protected]>

---------

Signed-off-by: Sajid Alam <[email protected]>
Signed-off-by: Huong Nguyen <[email protected]>
Co-authored-by: Huong Nguyen <[email protected]>
Co-authored-by: rashidakanchwala <[email protected]>
  • Loading branch information
3 people authored Jan 23, 2025
1 parent e418ecd commit 214ee8f
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Please follow the established format:
## Bug fixes and other changes

- Fix kedro viz `--load-file` to run from any directory without requiring a Kedro project. (#2206)
- Improved modular pipeline expand/collapse logic for better state synchronisation. (#2225)

# Release 10.1.0

Expand Down
2 changes: 1 addition & 1 deletion src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function toggleLayers(visible) {
export const TOGGLE_EXPAND_ALL_PIPELINES = 'TOGGLE_EXPAND_ALL_PIPELINES';

/**
* Toggle whether to expand all modular pipelines or collapse
* Toggle whether to expand all modular pipelines or collapse with boolean.
* @param {Boolean} shouldExpandAllPipelines
*/
export function toggleExpandAllPipelines(shouldExpandAllPipelines) {
Expand Down
14 changes: 14 additions & 0 deletions src/actions/modular-pipelines.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,17 @@ export function toggleModularPipelinesExpanded(expandedIDs) {
expandedIDs,
};
}

export const TOGGLE_MODULAR_PIPELINES_VISIBILITY_STATE =
'TOGGLE_MODULAR_PIPELINES_VISIBILITY_STATE';

/**
* Toggles the visibility state for all modular pipelines (expand or collapse all).
* @param {Boolean} expandAllPipelines - Whether to expand (true) or collapse (false) all pipelines.
*/
export function toggleModularPipelinesVisibilityState(expandAllPipelines) {
return {
type: TOGGLE_MODULAR_PIPELINES_VISIBILITY_STATE,
expandAllPipelines,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
toggleTextLabels,
toggleExpandAllPipelines,
} from '../../actions';
import { loadInitialPipelineData } from '../../actions/pipelines';
import { toggleModularPipelinesVisibilityState } from '../../actions/modular-pipelines';
import IconButton from '../ui/icon-button';
import LabelIcon from '../icons/label';
import ExportIcon from '../icons/export';
Expand Down Expand Up @@ -126,7 +126,7 @@ export const mapDispatchToProps = (dispatch) => ({
},
onToggleExpandAllPipelines: (isExpanded) => {
dispatch(toggleExpandAllPipelines(isExpanded));
dispatch(loadInitialPipelineData());
dispatch(toggleModularPipelinesVisibilityState(isExpanded));
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ describe('PrimaryToolbar', () => {
visible: mockState.spaceflights.visible,
display: mockState.spaceflights.display,
[callback]: mockFn,
modularPipelineIDs: ['pipeline1', '__root__'],
onToggleExpandPipelines: jest.fn(),
};
const wrapper = setup.mount(<FlowchartPrimaryToolbar {...props} />);
expect(mockFn.mock.calls.length).toBe(0);
Expand Down
32 changes: 32 additions & 0 deletions src/reducers/modular-pipelines.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
TOGGLE_MODULAR_PIPELINES_EXPANDED,
TOGGLE_SINGLE_MODULAR_PIPELINE_EXPANDED,
TOGGLE_MODULAR_PIPELINE_DISABLED,
TOGGLE_MODULAR_PIPELINES_VISIBILITY_STATE,
} from '../actions/modular-pipelines';

function modularPipelineReducer(modularPipelineState = {}, action) {
Expand Down Expand Up @@ -110,6 +111,37 @@ function modularPipelineReducer(modularPipelineState = {}, action) {
visible: newVisibleState,
});
}
case TOGGLE_MODULAR_PIPELINES_VISIBILITY_STATE: {
let newVisibleState = {};

// Determine which IDs should be expanded based on the action
const expandedIDs = action.expandAllPipelines
? modularPipelineState.ids
: [];

if (action.expandAllPipelines) {
// If expanding all pipelines, set visibility for each pipeline and its children
modularPipelineState.ids.forEach((modularPipelineID) => {
newVisibleState[modularPipelineID] = false;
modularPipelineState.tree[modularPipelineID].children.forEach(
(child) => (newVisibleState[child.id] = true)
);
});
} else {
// If not expanding all, only set visibility for the children of the root pipeline
if (modularPipelineState.tree['__root__']) {
for (const child of modularPipelineState.tree['__root__'].children ||
[]) {
newVisibleState[child.id] = true;
}
}
}

return updateState({
expanded: expandedIDs,
visible: newVisibleState,
});
}

default:
return modularPipelineState;
Expand Down

0 comments on commit 214ee8f

Please sign in to comment.