From 8ddd4892ebf202c6a2c20c7cf726bc5b00d0ecfa Mon Sep 17 00:00:00 2001 From: Mohammed Abdi Date: Mon, 23 Aug 2021 10:58:12 -1000 Subject: [PATCH] redux fix repo move to public with new commits Signed-off-by: Mohammed Abdi --- .../src/components/entry-create.js | 32 ++++++++++++++----- .../src/components/tornjak-api-helpers.js | 18 ++++++++--- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/tornjak-frontend/src/components/entry-create.js b/tornjak-frontend/src/components/entry-create.js index c2c41df3..b3adf172 100644 --- a/tornjak-frontend/src/components/entry-create.js +++ b/tornjak-frontend/src/components/entry-create.js @@ -83,8 +83,6 @@ class CreateEntry extends Component { this.TornjakApi.populateEntriesUpdate(this.props.globalServerSelected, this.props.entriesListUpdateFunc, this.props.tornjakMessageFunc) this.TornjakApi.refreshSelectorsState(this.props.globalServerSelected, this.props.agentworkloadSelectorInfoFunc); this.setState({ selectedServer: this.props.globalServerSelected }); - this.prepareParentIdAgentsList(); - this.prepareSelectorsList(); } } else { // agent doesnt need to do anything @@ -101,24 +99,42 @@ class CreateEntry extends Component { if (prevProps.globalServerSelected !== this.props.globalServerSelected) { this.setState({ selectedServer: this.props.globalServerSelected }); } + if (prevProps.globalServerInfo !== this.props.globalServerInfo) { - this.prepareParentIdAgentsList(); + if (this.props.globalAgentsList !== undefined && this.props.globalEntriesList !== undefined) { + this.prepareParentIdAgentsList(); + } this.prepareSelectorsList(); } - if (prevProps.globalAgentsList !== this.props.globalAgentsList) { - this.prepareParentIdAgentsList(); + + if (prevProps.globalAgentsList !== this.props.globalAgentsList || prevProps.globalEntriesList !== this.props.globalEntriesList) { + if (this.props.globalAgentsList !== undefined && this.props.globalEntriesList !== undefined) { + this.prepareParentIdAgentsList(); + } + this.prepareSelectorsList(); } + if (prevState.parentId !== this.state.parentId) { this.prepareSelectorsList(); } } else { if (prevProps.globalServerInfo !== this.props.globalServerInfo) { - this.prepareParentIdAgentsList(); + if (this.props.globalAgentsList !== undefined && this.props.globalEntriesList !== undefined) { + this.prepareParentIdAgentsList(); + } this.prepareSelectorsList(); } - if (prevState.parentId !== this.state.parentId) { + + if (prevProps.globalAgentsList !== this.props.globalAgentsList || prevProps.globalEntriesList !== this.props.globalEntriesList) { + if (this.props.globalAgentsList !== undefined && this.props.globalEntriesList !== undefined) { + this.prepareParentIdAgentsList(); + } this.prepareSelectorsList(); } + + if (prevState.parentId !== this.state.parentId) { + this.prepareSelectorsList(); + } } } @@ -692,4 +708,4 @@ const mapStateToProps = (state) => ({ export default connect( mapStateToProps, { serverSelectedFunc, agentworkloadSelectorInfoFunc, selectorInfoFunc, agentsListUpdateFunc, entriesListUpdateFunc, tornjakMessageFunc, tornjakServerInfoUpdateFunc, serverInfoUpdateFunc } -)(CreateEntry) +)(CreateEntry) \ No newline at end of file diff --git a/tornjak-frontend/src/components/tornjak-api-helpers.js b/tornjak-frontend/src/components/tornjak-api-helpers.js index 5642753a..cb7d2129 100644 --- a/tornjak-frontend/src/components/tornjak-api-helpers.js +++ b/tornjak-frontend/src/components/tornjak-api-helpers.js @@ -173,7 +173,9 @@ class TornjakApi extends Component { populateEntriesUpdate = (serverName, entriesListUpdateFunc, tornjakMessageFunc) => { axios.get(GetApiServerUri('/manager-api/entry/list/') + serverName, {crossdomain: true}) .then(response => { - entriesListUpdateFunc(response.data["entries"]); + if(!response.data["entries"]) { + entriesListUpdateFunc([]); + } else {entriesListUpdateFunc(response.data["entries"]);} tornjakMessageFunc(response.statusText); }).catch(error => { entriesListUpdateFunc([]); @@ -184,7 +186,9 @@ class TornjakApi extends Component { populateLocalEntriesUpdate = (entriesListUpdateFunc, tornjakMessageFunc) => { axios.get(GetApiServerUri('/api/entry/list'), {crossdomain: true}) .then(response => { - entriesListUpdateFunc(response.data["entries"]); + if(!response.data["entries"]) { + entriesListUpdateFunc([]); + } else {entriesListUpdateFunc(response.data["entries"]);} tornjakMessageFunc(response.statusText); }).catch(error => { console.log(error); @@ -197,7 +201,9 @@ class TornjakApi extends Component { populateAgentsUpdate = (serverName, agentsListUpdateFunc, tornjakMessageFunc) => { axios.get(GetApiServerUri('/manager-api/agent/list/') + serverName, { crossdomain: true }) .then(response => { - agentsListUpdateFunc(response.data["agents"]); + if(!response.data["agents"]) { + agentsListUpdateFunc([]); + } else {agentsListUpdateFunc(response.data["agents"]);} tornjakMessageFunc(response.statusText); }).catch(error => { agentsListUpdateFunc([]); @@ -210,7 +216,9 @@ class TornjakApi extends Component { populateLocalAgentsUpdate = (agentsListUpdateFunc, tornjakMessageFunc) => { axios.get(GetApiServerUri('/api/agent/list'), { crossdomain: true }) .then(response => { - agentsListUpdateFunc(response.data["agents"]); + if(!response.data["agents"]) { + agentsListUpdateFunc([]); + } else {agentsListUpdateFunc(response.data["agents"]);} tornjakMessageFunc(response.statusText); }) .catch((error) => { @@ -246,4 +254,4 @@ class TornjakApi extends Component { } -export default TornjakApi; +export default TornjakApi; \ No newline at end of file