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

Refactor modular pipeline expansions to instantly update UI #2225

Merged
merged 21 commits into from
Jan 23, 2025
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
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,
SajidAlamQB marked this conversation as resolved.
Show resolved Hide resolved
} 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(
SajidAlamQB marked this conversation as resolved.
Show resolved Hide resolved
(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
Loading