Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Redux actions to return an empty list for list functions and entry create robustness #19

Merged
merged 1 commit into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions tornjak-frontend/src/components/entry-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
}
}

Expand Down Expand Up @@ -692,4 +708,4 @@ const mapStateToProps = (state) => ({
export default connect(
mapStateToProps,
{ serverSelectedFunc, agentworkloadSelectorInfoFunc, selectorInfoFunc, agentsListUpdateFunc, entriesListUpdateFunc, tornjakMessageFunc, tornjakServerInfoUpdateFunc, serverInfoUpdateFunc }
)(CreateEntry)
)(CreateEntry)
18 changes: 13 additions & 5 deletions tornjak-frontend/src/components/tornjak-api-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
Expand All @@ -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);
Expand All @@ -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([]);
Expand All @@ -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) => {
Expand Down Expand Up @@ -246,4 +254,4 @@ class TornjakApi extends Component {

}

export default TornjakApi;
export default TornjakApi;