Start queryTransitions refactor

pull/330/head
Will Piers 2016-10-31 12:44:35 -07:00
parent 99f021fab0
commit 4c2cf4da3f
8 changed files with 57 additions and 57 deletions

View File

@ -1,5 +1,5 @@
import reducer from 'chronograf/reducers/queryConfigs'; import reducer from 'chronograf/reducers/queryConfigs';
import defaultQueryConfig from 'chronograf/utils/defaultQueryConfig'; import defaultQueryConfig from 'src/utils/defaultQueryConfig';
import { import {
chooseNamespace, chooseNamespace,
chooseMeasurement, chooseMeasurement,

View File

@ -1,5 +1,5 @@
import selectStatement from 'chronograf/utils/influxql/select'; import selectStatement from 'chronograf/utils/influxql/select';
import defaultQueryConfig from 'chronograf/utils/defaultQueryConfig'; import defaultQueryConfig from 'src/utils/defaultQueryConfig';
function mergeConfig(options) { function mergeConfig(options) {
return Object.assign({}, defaultQueryConfig(123), options); return Object.assign({}, defaultQueryConfig(123), options);

View File

@ -1,4 +1,5 @@
import defaultQueryConfig from '../utils/defaultQueryConfig'; import defaultQueryConfig from 'src/utils/defaultQueryConfig';
import {chooseNamespace, chooseMeasurement, toggleField} from 'src/utils/queryTransitions';
import update from 'react-addons-update'; import update from 'react-addons-update';
import u from 'updeep'; import u from 'updeep';
@ -10,10 +11,7 @@ export default function queryConfigs(state = {}, action) {
case 'CHOOSE_NAMESPACE': { case 'CHOOSE_NAMESPACE': {
const {queryId, database, retentionPolicy} = action.payload; const {queryId, database, retentionPolicy} = action.payload;
const nextQueryConfig = update(defaultQueryConfig(queryId), {$merge: { const nextQueryConfig = chooseNamespace(defaultQueryConfig(queryId), {database, retentionPolicy});
database,
retentionPolicy,
}});
const nextState = update(state, { const nextState = update(state, {
[queryId]: {$set: nextQueryConfig}, [queryId]: {$set: nextQueryConfig},
}); });
@ -22,11 +20,7 @@ export default function queryConfigs(state = {}, action) {
case 'CHOOSE_MEASUREMENT': { case 'CHOOSE_MEASUREMENT': {
const {queryId, measurement} = action.payload; const {queryId, measurement} = action.payload;
const nextQueryConfig = update(defaultQueryConfig(queryId), {$merge: { const nextQueryConfig = chooseMeasurement(state[queryId], measurement);
database: state[queryId].database,
retentionPolicy: state[queryId].retentionPolicy,
measurement,
}});
const nextState = update(state, { const nextState = update(state, {
[queryId]: {$set: nextQueryConfig}, [queryId]: {$set: nextQueryConfig},
}); });
@ -88,30 +82,13 @@ export default function queryConfigs(state = {}, action) {
case 'TOGGLE_FIELD': { case 'TOGGLE_FIELD': {
const {queryId, fieldFunc} = action.payload; const {queryId, fieldFunc} = action.payload;
const {field/* funcs */} = fieldFunc; const nextQueryConfig = toggleField(state[queryId], fieldFunc);
const nextState = update(state, { return Object.assign({}, state, {
[queryId]: {$apply: (queryConfig) => { [queryId]: nextQueryConfig,
const isSelected = queryConfig.fields.find((f) => f.field === field);
if (isSelected) {
const nextFields = queryConfig.fields.filter((f) => f.field !== field);
if (!nextFields.length) {
const nextGroupBy = update(state[queryId].groupBy, {time: {$set: null}});
return update(queryConfig, {fields: {$set: nextFields}, groupBy: {$set: nextGroupBy}});
}
return update(queryConfig, {
fields: {$set: nextFields},
}); });
} }
return update(queryConfig, {fields: {$push: [fieldFunc]}});
}},
});
return nextState;
}
case 'APPLY_FUNCS_TO_FIELD': { case 'APPLY_FUNCS_TO_FIELD': {
const {queryId, fieldFunc} = action.payload; const {queryId, fieldFunc} = action.payload;
const {field, funcs} = fieldFunc; const {field, funcs} = fieldFunc;

View File

@ -96,25 +96,24 @@ export const DataSection = React.createClass({
query: Object.assign({}, oldState.query, { query: Object.assign({}, oldState.query, {
fields: oldState.query.fields.concat({field, funcs}), fields: oldState.query.fields.concat({field, funcs}),
}), }),
}) });
return update(queryConfig, {fields: {$push: [fieldFunc]}});
}); });
}, },
handleGroupByTime(time) { // handleGroupByTime(time) {
}, // },
handleApplyFuncsToField(fieldFunc) { // handleApplyFuncsToField(fieldFunc) {
}, // },
handleChooseTag(tag) { // handleChooseTag(tag) {
}, // },
handleToggleTagAcceptance() { // handleToggleTagAcceptance() {
}, // },
handleGroupByTag(tagKey) { // handleGroupByTag(tagKey) {
}, // },
handleClickTab(tab) { handleClickTab(tab) {
this.setState({activeTab: tab}); this.setState({activeTab: tab});

View File

@ -1,11 +1,6 @@
import React, {PropTypes} from 'react'; import React, {PropTypes} from 'react';
import DataSection from '../components/DataSection'; import DataSection from '../components/DataSection';
const DATA_SECTION = 'data';
const VALUES_SECTION = 'values';
const MESSAGE_SECTION = 'message';
const ALERTS_SECTION = 'alerts';
export const KapacitorRulePage = React.createClass({ export const KapacitorRulePage = React.createClass({
propTypes: { propTypes: {
source: PropTypes.shape({ source: PropTypes.shape({
@ -16,12 +11,6 @@ export const KapacitorRulePage = React.createClass({
addFlashMessage: PropTypes.func, addFlashMessage: PropTypes.func,
}, },
getInitialState() {
return {
activeSection: DATA_SECTION,
};
},
render() { render() {
return ( return (
<div className="kapacitor-rule-page"> <div className="kapacitor-rule-page">
@ -88,7 +77,7 @@ export const KapacitorRulePage = React.createClass({
// hit kapacitor config endpoint and filter sections by the "enabled" property // hit kapacitor config endpoint and filter sections by the "enabled" property
const alertOptions = ['Slack', 'VictorOps'].map((destination) => { const alertOptions = ['Slack', 'VictorOps'].map((destination) => {
return <option key={destination}>send to {destination}</option>; return <option key={destination}>send to {destination}</option>;
}) });
return ( return (
<div className="kapacitor-rule-section"> <div className="kapacitor-rule-section">
<h3>Alerts</h3> <h3>Alerts</h3>

View File

@ -1,5 +1,5 @@
import uuid from 'node-uuid'; import uuid from 'node-uuid';
import defaultQueryConfig from 'src/chronograf/utils/defaultQueryConfig'; import defaultQueryConfig from 'src/utils/defaultQueryConfig';
export default function getInitialState() { export default function getInitialState() {
const panelID = uuid.v4(); // for the default Panel const panelID = uuid.v4(); // for the default Panel

View File

@ -0,0 +1,35 @@
import defaultQueryConfig from './defaultQueryConfig';
export function chooseNamespace(query, namespace) {
return Object.assign({}, query, namespace);
}
export function chooseMeasurement(query, measurement) {
return Object.assign({}, defaultQueryConfig(query.id), {
database: query.database,
retentionPolicy: query.retentionPolicy,
measurement,
});
}
export function toggleField(query, {field, funcs}) {
const isSelected = query.fields.find((f) => f.field === field);
if (isSelected) {
const nextFields = query.fields.filter((f) => f.field !== field);
if (!nextFields.length) {
const nextGroupBy = Object.assign({}, query.groupBy, {time: null});
return Object.assign({}, query, {
fields: nextFields,
groupBy: nextGroupBy,
});
}
return Object.assign({}, query, {
fields: nextFields,
});
}
return Object.assign({}, query, {
fields: query.fields.concat({field, funcs}),
});
}