diff --git a/ui/src/data_explorer/actions/view/index.js b/ui/src/data_explorer/actions/view/index.js
index 0fcdc17a9..f79fc537a 100644
--- a/ui/src/data_explorer/actions/view/index.js
+++ b/ui/src/data_explorer/actions/view/index.js
@@ -4,8 +4,8 @@ export function createPanel() {
return {
type: 'CREATE_PANEL',
payload: {
- panelId: uuid.v4(), // for the default Panel
- queryId: uuid.v4(), // for the default Query
+ panelID: uuid.v4(), // for the default Panel
+ queryID: uuid.v4(), // for the default Query
},
};
}
@@ -159,3 +159,12 @@ export function updateRawQuery(queryID, text) {
},
};
}
+
+export function activatePanel(panelID) {
+ return {
+ type: 'ACTIVATE_PANEL',
+ payload: {
+ panelID,
+ },
+ };
+}
diff --git a/ui/src/data_explorer/components/PanelBuilder.js b/ui/src/data_explorer/components/PanelBuilder.js
index b827971f5..e5b789070 100644
--- a/ui/src/data_explorer/components/PanelBuilder.js
+++ b/ui/src/data_explorer/components/PanelBuilder.js
@@ -9,6 +9,7 @@ const PanelBuilder = React.createClass({
propTypes: {
width: string,
actions: PropTypes.shape({
+ activatePanel: func.isRequired,
createPanel: func.isRequired,
deleteQuery: func.isRequired,
addQuery: func.isRequired,
@@ -23,25 +24,23 @@ const PanelBuilder = React.createClass({
toggleTagAcceptance: func.isRequired,
deletePanel: func.isRequired,
}).isRequired,
- setActivePanel: func.isRequired,
setActiveQuery: func.isRequired,
activePanelID: string,
activeQueryID: string,
},
- handleCreateExploer() {
+ handleCreateExplorer() {
this.props.actions.createPanel();
},
render() {
- const {width, actions, setActivePanel, setActiveQuery, activePanelID, activeQueryID} = this.props;
+ const {width, actions, setActiveQuery, activePanelID, activeQueryID} = this.props;
return (
-
Create Graph
+
Create Graph
@@ -70,14 +66,13 @@ const DataExplorer = React.createClass({
@@ -87,8 +82,11 @@ const DataExplorer = React.createClass({
});
function mapStateToProps(state) {
+ const {timeRange, dataExplorerUI} = state;
+
return {
- timeRange: state.timeRange,
+ timeRange,
+ activePanel: dataExplorerUI.activePanel,
};
}
diff --git a/ui/src/data_explorer/reducers/dataExplorerUI.js b/ui/src/data_explorer/reducers/dataExplorerUI.js
new file mode 100644
index 000000000..2140a9eba
--- /dev/null
+++ b/ui/src/data_explorer/reducers/dataExplorerUI.js
@@ -0,0 +1,11 @@
+export default function dataExplorerUI(state = {}, action) {
+ switch (action.type) {
+ case 'ACTIVATE_PANEL':
+ case 'CREATE_PANEL': {
+ const {panelID} = action.payload;
+ return {...state, activePanel: panelID};
+ }
+ }
+
+ return state;
+}
diff --git a/ui/src/data_explorer/reducers/index.js b/ui/src/data_explorer/reducers/index.js
index e0e44fe1b..4e4483f3b 100644
--- a/ui/src/data_explorer/reducers/index.js
+++ b/ui/src/data_explorer/reducers/index.js
@@ -1,9 +1,11 @@
import queryConfigs from './queryConfigs';
import panels from './panels';
import timeRange from './timeRange';
+import dataExplorerUI from './dataExplorerUI';
export {
queryConfigs,
panels,
timeRange,
+ dataExplorerUI,
};
diff --git a/ui/src/data_explorer/reducers/panels.js b/ui/src/data_explorer/reducers/panels.js
index 00f550009..e04c58581 100644
--- a/ui/src/data_explorer/reducers/panels.js
+++ b/ui/src/data_explorer/reducers/panels.js
@@ -3,15 +3,11 @@ import update from 'react-addons-update';
export default function panels(state = {}, action) {
switch (action.type) {
case 'CREATE_PANEL': {
- const {panelId, queryId} = action.payload;
- const panel = {
- id: panelId,
- queryIds: [queryId],
+ const {panelID, queryID} = action.payload;
+ return {
+ ...state,
+ [panelID]: {id: panelID, queryIds: [queryID]},
};
-
- return update(state, {
- [panelId]: {$set: panel},
- });
}
case 'RENAME_PANEL': {
@@ -50,5 +46,6 @@ export default function panels(state = {}, action) {
});
}
}
+
return state;
}
diff --git a/ui/src/data_explorer/reducers/queryConfigs.js b/ui/src/data_explorer/reducers/queryConfigs.js
index 7b0bcc865..82c14d0ec 100644
--- a/ui/src/data_explorer/reducers/queryConfigs.js
+++ b/ui/src/data_explorer/reducers/queryConfigs.js
@@ -49,9 +49,9 @@ export default function queryConfigs(state = {}, action) {
case 'CREATE_PANEL':
case 'ADD_KAPACITOR_QUERY':
case 'ADD_QUERY': {
- const {queryId, options} = action.payload;
+ const {queryID, options} = action.payload;
const nextState = Object.assign({}, state, {
- [queryId]: Object.assign({}, defaultQueryConfig(queryId), options),
+ [queryID]: Object.assign({}, defaultQueryConfig(queryID), options),
});
return nextState;
diff --git a/ui/src/localStorage.js b/ui/src/localStorage.js
index 1f26a3e9e..2ab359365 100644
--- a/ui/src/localStorage.js
+++ b/ui/src/localStorage.js
@@ -19,9 +19,14 @@ export const loadLocalStorage = () => {
}
};
-export const saveToLocalStorage = ({panels, queryConfigs, timeRange}) => {
+export const saveToLocalStorage = ({panels, queryConfigs, timeRange, dataExplorerUI}) => {
try {
- window.localStorage.setItem('state', JSON.stringify({panels, queryConfigs, timeRange}));
+ window.localStorage.setItem('state', JSON.stringify({
+ panels,
+ queryConfigs,
+ timeRange,
+ dataExplorerUI,
+ }));
} catch (err) {
console.error('Unable to save data explorer: ', JSON.parse(err)); // eslint-disable-line no-console
}
diff --git a/ui/src/store/configureStore.js b/ui/src/store/configureStore.js
index 1b7b3ec2b..286e96e47 100644
--- a/ui/src/store/configureStore.js
+++ b/ui/src/store/configureStore.js
@@ -2,14 +2,14 @@ import {createStore, applyMiddleware, compose} from 'redux';
import {combineReducers} from 'redux';
import thunkMiddleware from 'redux-thunk';
import makeQueryExecuter from 'src/shared/middleware/queryExecuter';
-import * as chronografReducers from 'src/data_explorer/reducers';
+import * as dataExplorerReducers from 'src/data_explorer/reducers';
import * as sharedReducers from 'src/shared/reducers';
import rulesReducer from 'src/kapacitor/reducers/rules';
import persistStateEnhancer from './persistStateEnhancer';
const rootReducer = combineReducers({
...sharedReducers,
- ...chronografReducers,
+ ...dataExplorerReducers,
rules: rulesReducer,
});
diff --git a/ui/src/store/persistStateEnhancer.js b/ui/src/store/persistStateEnhancer.js
index 8ad9c4a06..9c788fcac 100644
--- a/ui/src/store/persistStateEnhancer.js
+++ b/ui/src/store/persistStateEnhancer.js
@@ -13,11 +13,11 @@ import {saveToLocalStorage} from '../localStorage';
export default function persistState() {
return (next) => (reducer, initialState, enhancer) => {
const store = next(reducer, initialState, enhancer);
- const debounceMs = 1000;
+ const throttleMs = 1000;
- store.subscribe(_.debounce(() => {
+ store.subscribe(_.throttle(() => {
saveToLocalStorage({...store.getState()});
- }, debounceMs));
+ }, throttleMs));
return store;
};