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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
toggleTextLabels,
toggleExpandAllPipelines,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you should add this actions/modular-pipelines as well, it's confusing why this is here. and the other expanded ones are in the other

} from '../../actions';
import { loadInitialPipelineData } from '../../actions/pipelines';
import { toggleModularPipelinesExpanded } from '../../actions/modular-pipelines';
import IconButton from '../ui/icon-button';
import LabelIcon from '../icons/label';
import ExportIcon from '../icons/export';
Expand All @@ -24,6 +24,7 @@ import { useGeneratePathname } from '../../utils/hooks/use-generate-pathname';
* @param {Boolean} textLabels Whether text labels are displayed
*/
export const FlowchartPrimaryToolbar = ({
modularPipelineIDs,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need it anymore i think

disableLayerBtn,
onToggleExportModal,
onToggleLayers,
Expand All @@ -34,12 +35,17 @@ export const FlowchartPrimaryToolbar = ({
display,
visibleLayers,
expandedPipelines,
onToggleExpandPipelines,
onToggleExpandAllPipelines,
}) => {
const { toSetQueryParam } = useGeneratePathname();

const handleToggleExpandAllPipelines = () => {
const isExpanded = !expandedPipelines;

// Pass an empty array when collapsing all pipelines
onToggleExpandPipelines(isExpanded ? modularPipelineIDs : []);
SajidAlamQB marked this conversation as resolved.
Show resolved Hide resolved

onToggleExpandAllPipelines(isExpanded);
toSetQueryParam('expandAllPipelines', isExpanded.toString());
};
Expand Down Expand Up @@ -103,6 +109,7 @@ export const FlowchartPrimaryToolbar = ({
};

export const mapStateToProps = (state) => ({
modularPipelineIDs: state?.modularPipeline?.ids,
disableLayerBtn: !state.layer.ids.length,
textLabels: state.textLabels,
visible: state.visible,
Expand All @@ -124,9 +131,11 @@ export const mapDispatchToProps = (dispatch) => ({
onToggleTextLabels: (value) => {
dispatch(toggleTextLabels(Boolean(value)));
},
onToggleExpandPipelines: (ids) => {
dispatch(toggleModularPipelinesExpanded(ids));
},
onToggleExpandAllPipelines: (isExpanded) => {
dispatch(toggleExpandAllPipelines(isExpanded));
dispatch(loadInitialPipelineData());
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ describe('PrimaryToolbar', () => {
visible: mockState.spaceflights.visible,
display: mockState.spaceflights.display,
[callback]: mockFn,
onToggleExpandPipelines: jest.fn(),
};
const wrapper = setup.mount(<FlowchartPrimaryToolbar {...props} />);
expect(mockFn.mock.calls.length).toBe(0);
Expand All @@ -72,6 +73,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
18 changes: 16 additions & 2 deletions src/selectors/disabled.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const getNodeLayer = (state) => state.node.layer;
const getNodeModularPipelines = (state) => state.node.modularPipelines;
const getVisibleSidebarNodes = (state) => state.modularPipeline.visible;
const getSliceApply = (state) => state.slice.apply;
const modularPipelineFocusMode = (state) => state.modularPipelineFocusMode;

/**
* Return all inputs and outputs of currently visible modular pipelines
Expand Down Expand Up @@ -150,6 +151,8 @@ export const getNodeDisabled = createSelector(
getDisabledModularPipeline,
getSlicedPipeline,
getSliceApply,
modularPipelineFocusMode,
getModularPipelinesTree,
],
(
nodeIDs,
Expand All @@ -163,9 +166,21 @@ export const getNodeDisabled = createSelector(
visibleModularPipelineInputsOutputs,
disabledModularPipeline,
slicedPipeline,
isSliceApplied
isSliceApplied,
isModularPipelineFocusMode,
modularPipelinesTree
) =>
arrayToObject(nodeIDs, (id) => {
const rootChildren = modularPipelinesTree?.['__root__']?.children || [];
SajidAlamQB marked this conversation as resolved.
Show resolved Hide resolved
const isRootChild = rootChildren.some((child) => child.id === id);

// Check the node's type:
const isTaskNode = nodeType[id] === 'task';

if (!isModularPipelineFocusMode && isRootChild && isTaskNode) {
return false;
}

let isDisabledViaSlicedPipeline = false;
if (isSliceApplied && slicedPipeline.length > 0) {
isDisabledViaSlicedPipeline = !slicedPipeline.includes(id);
Expand All @@ -176,7 +191,6 @@ export const getNodeDisabled = createSelector(
!visibleModularPipelineInputsOutputs.has(id);

const isDisabledViaModularPipeline = nodesDisabledViaModularPipeline[id];

return [
nodeDisabledNode[id],
nodeDisabledTag[id],
Expand Down
Loading