diff --git a/actions/generals.js b/actions/generals.js index c730d6f33..c63ab0976 100644 --- a/actions/generals.js +++ b/actions/generals.js @@ -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, @@ -85,3 +86,8 @@ export const showListViewer = () => ({ type: SHOW_LIST_VIEWER, data : {} }); + +export const invalidIdLoaded = id => ({ + type: INVALID_ID, + data : { id: id } +}); diff --git a/components/VFBMain.js b/components/VFBMain.js index 6ebdd63a4..bfe37e536 100644 --- a/components/VFBMain.js +++ b/components/VFBMain.js @@ -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])) { diff --git a/containers/VFBMainContainer.js b/containers/VFBMainContainer.js index 2eea90c8a..506c7f065 100644 --- a/containers/VFBMainContainer.js +++ b/containers/VFBMainContainer.js @@ -9,7 +9,8 @@ import { instanceVisibilityChanged, setTermInfo, vfbGraph, - vfbCircuitBrowser + vfbCircuitBrowser, + invalidIdLoaded } from '../actions/generals'; import { connect } from "react-redux"; @@ -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); diff --git a/reducers/generals.js b/reducers/generals.js index 207cf62b5..9b00dc4d8 100644 --- a/reducers/generals.js +++ b/reducers/generals.js @@ -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; @@ -321,10 +322,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 ] + }; + } } }