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 15 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
9 changes: 9 additions & 0 deletions src/actions/modular-pipelines.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,12 @@ export function toggleModularPipelinesExpanded(expandedIDs) {
expandedIDs,
};
}

export const TOGGLE_ALL_MODULAR_PIPELINES_EXPANDED =
'TOGGLE_ALL_MODULAR_PIPELINES_EXPANDED';
export function toggleAllModularPipelinesExpanded(expandAllPipelines) {
return {
type: TOGGLE_ALL_MODULAR_PIPELINES_EXPANDED,
expandAllPipelines,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import {
toggleTextLabels,
toggleExpandAllPipelines,
SajidAlamQB marked this conversation as resolved.
Show resolved Hide resolved
} from '../../actions';
import { loadInitialPipelineData } from '../../actions/pipelines';
import {
toggleModularPipelinesExpanded,
SajidAlamQB marked this conversation as resolved.
Show resolved Hide resolved
toggleAllModularPipelinesExpanded,
} from '../../actions/modular-pipelines';
import IconButton from '../ui/icon-button';
import LabelIcon from '../icons/label';
import ExportIcon from '../icons/export';
Expand All @@ -24,6 +27,7 @@ import { useGeneratePathname } from '../../utils/hooks/use-generate-pathname';
* @param {Boolean} textLabels Whether text labels are displayed
*/
export const FlowchartPrimaryToolbar = ({
modularPipelineIDs,
SajidAlamQB marked this conversation as resolved.
Show resolved Hide resolved
disableLayerBtn,
onToggleExportModal,
onToggleLayers,
Expand All @@ -34,6 +38,7 @@ export const FlowchartPrimaryToolbar = ({
display,
visibleLayers,
expandedPipelines,
onToggleExpandPipelines,
onToggleExpandAllPipelines,
SajidAlamQB marked this conversation as resolved.
Show resolved Hide resolved
}) => {
const { toSetQueryParam } = useGeneratePathname();
Expand Down Expand Up @@ -103,6 +108,7 @@ export const FlowchartPrimaryToolbar = ({
};

export const mapStateToProps = (state) => ({
modularPipelineIDs: state?.modularPipeline?.ids,
SajidAlamQB marked this conversation as resolved.
Show resolved Hide resolved
disableLayerBtn: !state.layer.ids.length,
textLabels: state.textLabels,
visible: state.visible,
Expand All @@ -124,9 +130,12 @@ export const mapDispatchToProps = (dispatch) => ({
onToggleTextLabels: (value) => {
dispatch(toggleTextLabels(Boolean(value)));
},
onToggleExpandPipelines: (ids) => {
dispatch(toggleModularPipelinesExpanded(ids));
},
onToggleExpandAllPipelines: (isExpanded) => {
dispatch(toggleExpandAllPipelines(isExpanded));
dispatch(loadInitialPipelineData());
dispatch(toggleAllModularPipelinesExpanded(isExpanded));
SajidAlamQB marked this conversation as resolved.
Show resolved Hide resolved
},
});

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 All @@ -72,6 +74,7 @@ describe('PrimaryToolbar', () => {
disableLayerBtn: expect.any(Boolean),
textLabels: expect.any(Boolean),
expandedPipelines: expect.any(Boolean),
modularPipelineIDs: expect.any(Array),
visible: expect.objectContaining({
exportModal: expect.any(Boolean),
metadataModal: expect.any(Boolean),
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_ALL_MODULAR_PIPELINES_EXPANDED,
} from '../actions/modular-pipelines';

function modularPipelineReducer(modularPipelineState = {}, action) {
Expand Down Expand Up @@ -110,6 +111,37 @@ function modularPipelineReducer(modularPipelineState = {}, action) {
visible: newVisibleState,
});
}
case TOGGLE_ALL_MODULAR_PIPELINES_EXPANDED: {
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