Skip to content

Commit

Permalink
Merge pull request #1137 from VirtualFlyBrain/feature/1016
Browse files Browse the repository at this point in the history
#1016 invalid id handler in redux state
  • Loading branch information
Robbie1977 authored Jun 21, 2021
2 parents 4b2f1fb + 8e930dc commit 94bd1ca
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 6 deletions.
6 changes: 6 additions & 0 deletions actions/generals.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const INSTANCE_SELECTED = 'INSTANCE_SELECTION';
export const INSTANCE_DELETED = 'INSTANCE_DELETED';
export const INSTANCE_VISIBILITY_CHANGED = 'INSTANCE_VISIBILITY_CHANGED';
export const SHOW_LIST_VIEWER = 'SHOW_LIST_VIEWER';
export const INVALID_ID = 'INVALID_ID';

export const vfbError = errorMessage => ({
type: VFB_ERROR,
Expand Down Expand Up @@ -85,3 +86,8 @@ export const showListViewer = () => ({
type: SHOW_LIST_VIEWER,
data : {}
});

export const invalidIdLoaded = id => ({
type: INVALID_ID,
data : { id: id }
});
3 changes: 2 additions & 1 deletion components/VFBMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ class VFBMain extends React.Component {
meta = Instances.getInstance(variableIds[singleId] + '.' + variableIds[singleId] + '_meta');
} catch (e) {
console.log('Instance for ' + variableIds[singleId] + '.' + variableIds[singleId] + '_meta' + ' does not exist in the current model');
this.vfbLoadBuffer.splice($.inArray(variableIds[singleId], window.vfbLoadBuffer), 1);
this.props.invalidIdLoaded(variableIds[singleId])
// this.vfbLoadBuffer.splice($.inArray(variableIds[singleId], window.vfbLoadBuffer), 1);
continue;
}
if (this.hasVisualType(variableIds[singleId])) {
Expand Down
6 changes: 4 additions & 2 deletions containers/VFBMainContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
instanceVisibilityChanged,
setTermInfo,
vfbGraph,
vfbCircuitBrowser
vfbCircuitBrowser,
invalidIdLoaded
} from '../actions/generals';
import { connect } from "react-redux";

Expand All @@ -25,7 +26,8 @@ const mapDispatchToProps = dispatch => ({
instanceSelected : instance => dispatch(instanceSelected(instance)),
instanceDeleted : (type, instanceID) => dispatch(instanceDeleted(type, instanceID)),
instanceVisibilityChanged : instance => dispatch(instanceVisibilityChanged(instance)),
setTermInfo: (instance, visible) => dispatch (setTermInfo(instance, visible))
setTermInfo: (instance, visible) => dispatch (setTermInfo(instance, visible)),
invalidIdLoaded: id => dispatch(invalidIdLoaded(id))
});

export default connect(mapStateToProps, mapDispatchToProps)(VFBMain);
66 changes: 63 additions & 3 deletions reducers/generals.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
UPDATE_CIRCUIT_QUERY,
INSTANCE_SELECTED,
INSTANCE_VISIBILITY_CHANGED,
VFB_LOAD_TERM_INFO
VFB_LOAD_TERM_INFO,
INVALID_ID
} from '../actions/generals';

const componentsMap = require('../components/configuration/VFBLoader/VFBLoaderConfiguration').componentsMap;
Expand Down Expand Up @@ -323,10 +324,69 @@ function generalReducer (state, action) {
instanceOnFocus : action.data.instance
}
case SHOW_LIST_VIEWER:
ui.layers.listViewerInfoVisible = true;
ui.layers.listViewerInfoVisible = true;
return {
...state,
ui : ui
}
}
case INVALID_ID:
var loading = false;
var stepsToLoad = 0;
var stepsLoaded = 0;
var idsLoaded = state.idsLoaded;
var newMap = { ...state.idsMap };

if (newMap[action.data.id] !== undefined){
idsLoaded++;
delete newMap[action.data.id];
}

for (let singleId in newMap) {
var instanceLoaded = true;
if (Object.keys(newMap[singleId].components).length === 0) {
stepsToLoad++;
loading = true;
instanceLoaded = false;
}

for (let singleComponent in newMap[singleId].components) {
if (newMap[singleId].components[singleComponent].loaded) {
stepsToLoad++;
stepsLoaded++;
} else {
stepsToLoad++;
loading = true;
instanceLoaded = false;
}
}

if (instanceLoaded) {
idsLoaded++;
delete newMap[action.data.id];
}
}

if (loading) {
return {
...state,
idsMap: newMap,
loading: loading,
idsLoaded: idsLoaded,
stepsToLoad: stepsToLoad,
stepsLoaded: stepsLoaded
};
} else {
return {
...state,
idsToLoad: 0,
idsLoaded: 0,
stepsToLoad: 0,
stepsLoaded: 0,
idsMap: newMap,
loading: loading,
instanceOnFocus : Instances[action.data.id] != null ? Instances[action.data.id] : {},
idsList : !state.idsList.includes(action.data.id) ? [ ...state.idsList, action.data.id ] : [ ...state.idsList ]
};
}
}
}

0 comments on commit 94bd1ca

Please sign in to comment.