Skip to content

Commit

Permalink
Update database list behavior when server added or deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
danesparza committed Oct 20, 2017
1 parent 972ad3d commit 1a8e6c5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
21 changes: 20 additions & 1 deletion src/components/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Navbar from './NavBar';

// Utils
import SettingsAPI from '../utils/SettingsAPI';
import InfluxAPI from '../utils/InfluxAPI';

// Stores
import SettingsStore from '../stores/SettingsStore';
Expand Down Expand Up @@ -115,12 +116,22 @@ class Settings extends Component {
parser.href = this.state.AddServerUrl;

let port = parser.port || 8086;
let protocol = parser.protocol || "http:";

let serverUrl = `${parser.protocol}//${parser.hostname}:${port}`;
let serverUrl = `${protocol}//${parser.hostname}:${port}`;

// Add the server
console.log("Adding server..." + this.state.AddServerName);
SettingsAPI.addServer(this.state.AddServerName, serverUrl);

// If we have a current server:
if(SettingsStore.haveCurrentServer()){
// Get the current server:
let currentServer = SettingsStore.getCurrentServer();

// Reset the database list:
InfluxAPI.getDatabaseList(currentServer.url);
}

// Clear the add server fields:
this.setState(
Expand All @@ -137,6 +148,14 @@ class Settings extends Component {
_onRemoveServerClick = (name) => {
console.log("Removing server..." + name);
SettingsAPI.removeServer(name);

if(SettingsStore.haveCurrentServer()){
// Get the current server:
let currentServer = SettingsStore.getCurrentServer();

// Reset the database list:
InfluxAPI.getDatabaseList(currentServer.url);
}
}

// Data changed:
Expand Down
17 changes: 16 additions & 1 deletion src/stores/SettingsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@ class SettingsStore extends Store {
return this.serverList;
}

// Returns 'true' if we have a current server
// Returns 'true' if we don't have a current server
needCurrentServer() {
return isEmpty(this.getCurrentServer());
}

// Returns 'true' if we have a current server
haveCurrentServer() {
return isEmpty(this.getCurrentServer()) === false;
}

// Get the database list
getDatabaseList() {
return this.currentServerDBList;
Expand Down Expand Up @@ -84,6 +89,16 @@ class SettingsStore extends Store {
this.serverList = action.servers;
console.log(action);

// If this list is now blank, we should reset
// current database
// list of databases
// current server
if(this.serverList.length < 1){
this.currentDatabase = "";
this.currentServerDBList = [];
this.currentServer = {};
}

this.__emitChange();
break;

Expand Down
2 changes: 1 addition & 1 deletion src/utils/InfluxAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class InfluxAPI {
// Gets the list of databases for the given server
getDatabaseList(serverurl) {

if(serverurl === "")
if(!serverurl)
{
console.log("Can't execute query: server is blank");
return;
Expand Down

0 comments on commit 1a8e6c5

Please sign in to comment.