Skip to content

Commit

Permalink
Refactoring displayRows, etc
Browse files Browse the repository at this point in the history
- Docs: Added / updated code comments
- Misc: Minor refactoring
  • Loading branch information
joeflack4 committed Oct 23, 2024
1 parent 50f50c7 commit 3532a68
Show file tree
Hide file tree
Showing 4 changed files with 227 additions and 185 deletions.
4 changes: 2 additions & 2 deletions frontend/src/components/CsetComparisonPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,8 @@ function getCollapseIconAndName(
let direction;
if (
(graphOptions.expandAll &&
graphOptions.specificPaths[row.rowPath] !== 'collapse'
) || graphOptions.specificPaths[row.rowPath] === 'expand'
graphOptions.expandStateByPath[row.rowPath] !== 'collapse'
) || graphOptions.expandStateByPath[row.rowPath] === 'expand'
) {
Component = RemoveCircleOutline;
direction = 'collapse';
Expand Down
32 changes: 20 additions & 12 deletions frontend/src/state/AppState.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ export function graphOptionsReducer(state, action) {
if (!validValues.includes(action.direction)) {
console.error(`Invalid direction for TOGGLE_NODE_EXPANDED: ${action.direction}`);
}
let specificPaths = {...graphOptions.specificPaths};
let current = specificPaths[rowPath];
let expandStateByPath = {...graphOptions.expandStateByPath};
let current = expandStateByPath[rowPath];
if (typeof(current) === 'undefined') {
// if no current expand/collapse for path, set it
specificPaths[rowPath] = action.direction;
expandStateByPath[rowPath] = action.direction;
} else {
// path has current state -- should be opposite of action.direction
// so just delete it (to unexpand/uncollapse)
Expand All @@ -194,9 +194,9 @@ export function graphOptionsReducer(state, action) {
if (current === action.direction) {
console.error(`Trying to ${action.direction} ${rowPath} but is already`);
}
delete specificPaths[rowPath];
delete expandStateByPath[rowPath];
}
graphOptions = { ...graphOptions, specificPaths};
graphOptions = { ...graphOptions, expandStateByPath};
break;
}
case 'TOGGLE_OPTION':
Expand All @@ -206,7 +206,7 @@ export function graphOptionsReducer(state, action) {
break;
case 'TOGGLE_EXPAND_ALL':
graphOptions = {...graphOptions, expandAll:!graphOptions.expandAll};
graphOptions.specificPaths = {};
graphOptions.expandStateByPath = {};
// just start over when expandAll flips
// could have two sets of specificPaths, one for expandAll, one for not
break;
Expand All @@ -231,10 +231,19 @@ if (process.env.NODE_ENV !== 'production') {
// window.appStateW = {}; // playwright complaining that window isn't defined
let appStateW = {};

/* makeProvider()
Makes provider to manage both a regular reducer and a storage provider.
I think the idea was to put update logic into reducers and try to have storage providers.
just emulate localStorage (whether for localStorage, sessionStorage, or querystring).
Returns:
Provider, useReducerWithStorage
Side effects:
- Updates global `resetFuncs` obj w/ the `resetFunc` for the given `stateName`.
*/
function makeProvider({stateName, reducer, initialSettings, storageProviderGetter, jsonify=false, }) {
// makes provider to manage both a regular reducer and a storage provider
// I think the idea was to put update logic into reducers and try to have storage providers
// just emulate localStorage (whether for localStorage, sessionStorage, or querystring)
/*
const regularReducer = (state, action) => {
const newState = reducer(state, action);
Expand Down Expand Up @@ -273,9 +282,8 @@ function makeProvider({stateName, reducer, initialSettings, storageProviderGette
storageProvider.setItem(stateName, newState);
}, [stateName, state]);
*/

const resetFunc = () => dispatch({type: 'reset', resetValue: initialSettings});
resetFuncs[stateName] = resetFunc;

resetFuncs[stateName] = () => dispatch({type: 'reset', resetValue: initialSettings});

return (
// <Context.Provider value={[storageProvider.getItem(stateName) ?? initialSettings, dispatch]}>
Expand Down
Loading

0 comments on commit 3532a68

Please sign in to comment.