Skip to content

Commit

Permalink
make expandAllPipelines outside of flags
Browse files Browse the repository at this point in the history
Signed-off-by: ravi-kumar-pilla <[email protected]>
  • Loading branch information
ravi-kumar-pilla committed May 14, 2024
1 parent 894e0a2 commit 499460c
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 13 deletions.
13 changes: 13 additions & 0 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ export function toggleLayers(visible) {
};
}

export const TOGGLE_EXPAND_ALL_PIPELINES = 'TOGGLE_EXPAND_ALL_PIPELINES';

/**
* Toggle whether to expand all modular pipelines or collapse all
* @param {Boolean} shouldExpandAllPipelines
*/
export function toggleExpandAllPipelines(shouldExpandAllPipelines) {
return {
type: TOGGLE_EXPAND_ALL_PIPELINES,
shouldExpandAllPipelines,
};
}

export const TOGGLE_EXPORT_MODAL = 'TOGGLE_EXPORT_MODAL';

/**
Expand Down
10 changes: 5 additions & 5 deletions src/actions/pipelines.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function loadInitialPipelineData() {
// obtain the status of expandAllPipelines to decide whether it needs to overwrite the
// list of visible nodes
const expandAllPipelines =
state.display.expandAllPipelines || state.flags.expandAllPipelines;
state.display.expandAllPipelines || state.expandAllPipelines;
let newState = await loadJsonData(url).then((data) =>
preparePipelineState(data, true, expandAllPipelines)
);
Expand All @@ -122,7 +122,7 @@ export function loadInitialPipelineData() {
*/
export function loadPipelineData(pipelineID) {
return async function (dispatch, getState) {
const { dataSource, pipeline, display, flags } = getState();
const { dataSource, pipeline, display, expandAllPipelines } = getState();

if (pipelineID && pipelineID === pipeline.active) {
return;
Expand All @@ -136,10 +136,10 @@ export function loadPipelineData(pipelineID) {
active: pipelineID,
});

const expandAllPipelines =
display.expandAllPipelines || flags.expandAllPipelines;
const shouldExpandAllPipelines =
display.expandAllPipelines || expandAllPipelines;
const newState = await loadJsonData(url).then((data) =>
preparePipelineState(data, false, expandAllPipelines)
preparePipelineState(data, false, shouldExpandAllPipelines)
);

// Set active pipeline here rather than dispatching two separate actions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
toggleLayers,
toggleSidebar,
toggleTextLabels,
changeFlag,
toggleExpandAllPipelines,
} from '../../actions';
import { loadInitialPipelineData } from '../../actions/pipelines';
import IconButton from '../ui/icon-button';
Expand Down Expand Up @@ -110,7 +110,7 @@ export const mapStateToProps = (state) => ({
textLabels: state.textLabels,
visible: state.visible,
visibleLayers: Boolean(getVisibleLayerIDs(state).length),
expandedPipelines: state.flags.expandAllPipelines,
expandedPipelines: state.expandAllPipelines,
});

export const mapDispatchToProps = (dispatch) => ({
Expand All @@ -127,7 +127,7 @@ export const mapDispatchToProps = (dispatch) => ({
dispatch(toggleTextLabels(Boolean(value)));
},
onToggleExpandAllPipelines: (isExpanded) => {
dispatch(changeFlag('expandAllPipelines', isExpanded));
dispatch(toggleExpandAllPipelines(isExpanded));
dispatch(loadInitialPipelineData());
},
});
Expand Down
4 changes: 2 additions & 2 deletions src/components/flowchart-wrapper/flowchart-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ export const FlowChartWrapper = ({
disabledKeys && toSetQueryParam(params.types, mappedDisabledNodes);
}
},
flags: (value) => {
expandAllPipelines: (value) => {
if (!searchParams.has(params.expandAll)) {
toSetQueryParam(params.expandAll, value.expandAllPipelines);
toSetQueryParam(params.expandAll, value);
}
},
};
Expand Down
6 changes: 6 additions & 0 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
TOGGLE_THEME,
UPDATE_CHART_SIZE,
UPDATE_ZOOM,
TOGGLE_EXPAND_ALL_PIPELINES,
} from '../actions';
import { TOGGLE_PARAMETERS_HOVERED } from '../actions';

Expand Down Expand Up @@ -95,6 +96,11 @@ const combinedReducer = combineReducers({
TOGGLE_HOVERED_FOCUS_MODE,
'hoveredFocusMode'
),
expandAllPipelines: createReducer(
false,
TOGGLE_EXPAND_ALL_PIPELINES,
'shouldExpandAllPipelines'
),
});

const rootReducer = (state, action) =>
Expand Down
13 changes: 10 additions & 3 deletions src/store/initial-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import {
*/
export const createInitialState = () => ({
chartSize: {},
flags: { ...Flags.defaults(), expandAllPipelines: false },
flags: { ...Flags.defaults() },
textLabels: true,
theme: 'dark',
expandAllPipelines: false,
isPrettyName: settings.isPrettyName.default,
showFeatureHints: settings.showFeatureHints.default,
ignoreLargeWarning: false,
Expand Down Expand Up @@ -67,6 +68,7 @@ const parseUrlParameters = () => {
nodeTagInUrl: search.get(params.tags)
? search.get(params.tags).split(',')
: [],
expandAllPipelinesInUrl: search.get(params.expandAll),
};
};

Expand All @@ -86,6 +88,7 @@ const applyUrlParametersToState = (state, urlParams) => {
nodeNameFromUrl,
nodeTypeInUrl,
nodeTagInUrl,
expandAllPipelinesInUrl,
} = urlParams;

let newState = { ...state };
Expand Down Expand Up @@ -127,6 +130,10 @@ const applyUrlParametersToState = (state, urlParams) => {
});
}

if (expandAllPipelinesInUrl) {
newState.expandAllPipelines = JSON.parse(expandAllPipelinesInUrl);
}

return newState;
};

Expand All @@ -142,7 +149,7 @@ export const mergeLocalStorage = (state) => {
localStorageRunsMetadata
);
Object.keys(localStorageState).forEach((key) => {
if (!state[key]) {
if (!(key in state)) {
delete localStorageState[key];
}
});
Expand Down Expand Up @@ -214,7 +221,7 @@ const getInitialState = (props = {}) => {

const expandAllPipelines =
nonPipelineState.display.expandAllPipelines ||
nonPipelineState.flags.expandAllPipelines;
nonPipelineState.expandAllPipelines;

const pipelineState = preparePipelineState(
props.data,
Expand Down
1 change: 1 addition & 0 deletions src/store/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const saveStateToLocalStorage = (state) => {
isPrettyName: state.isPrettyName,
showFeatureHints: state.showFeatureHints,
flags: state.flags,
expandAllPipelines: state.expandAllPipelines,
});

// Store Run's metadata to localstorage
Expand Down

0 comments on commit 499460c

Please sign in to comment.