Change influxql and FieldList fields to value instead of name

pull/10616/head
Andrew Watkins 2017-10-17 13:31:17 -07:00
parent 77b3487bd2
commit 9b1cc1d436
4 changed files with 40 additions and 33 deletions

View File

@ -30,7 +30,7 @@ describe('buildInfluxQLQuery', () => {
config = mergeConfig({ config = mergeConfig({
database: 'db1', database: 'db1',
measurement: 'm1', measurement: 'm1',
fields: [{name: 'f1', type: 'field'}], fields: [{value: 'f1', type: 'field'}],
}) })
}) })
@ -47,7 +47,7 @@ describe('buildInfluxQLQuery', () => {
database: 'db1', database: 'db1',
measurement: 'm1', measurement: 'm1',
retentionPolicy: 'rp1', retentionPolicy: 'rp1',
fields: [{name: 'f1', type: 'field'}], fields: [{value: 'f1', type: 'field'}],
}) })
timeBounds = {lower: 'now() - 1hr'} timeBounds = {lower: 'now() - 1hr'}
}) })
@ -71,7 +71,7 @@ describe('buildInfluxQLQuery', () => {
database: 'db1', database: 'db1',
measurement: 'm1', measurement: 'm1',
retentionPolicy: 'rp1', retentionPolicy: 'rp1',
fields: [{name: '*', type: 'field'}], fields: [{value: '*', type: 'field'}],
}) })
}) })
@ -90,10 +90,10 @@ describe('buildInfluxQLQuery', () => {
retentionPolicy: 'rp1', retentionPolicy: 'rp1',
fields: [ fields: [
{ {
name: 'min', value: 'min',
type: 'func', type: 'func',
alias: 'min_value', alias: 'min_value',
args: [{name: 'value', type: 'field'}], args: [{value: 'value', type: 'field'}],
}, },
], ],
groupBy: {time: '10m', tags: []}, groupBy: {time: '10m', tags: []},
@ -117,10 +117,10 @@ describe('buildInfluxQLQuery', () => {
retentionPolicy: 'rp1', retentionPolicy: 'rp1',
fields: [ fields: [
{ {
name: 'min', value: 'min',
type: 'func', type: 'func',
alias: 'min_value', alias: 'min_value',
args: [{name: 'value', type: 'field'}], args: [{value: 'value', type: 'field'}],
}, },
], ],
groupBy: {time: null, tags: ['t1', 't2']}, groupBy: {time: null, tags: ['t1', 't2']},
@ -140,7 +140,7 @@ describe('buildInfluxQLQuery', () => {
database: 'db1', database: 'db1',
retentionPolicy: 'rp1', retentionPolicy: 'rp1',
measurement: 'm0', measurement: 'm0',
fields: [{name: 'value', type: 'field'}], fields: [{value: 'value', type: 'field'}],
}) })
timeBounds = { timeBounds = {
lower: "'2015-07-23T15:52:24.447Z'", lower: "'2015-07-23T15:52:24.447Z'",
@ -161,7 +161,14 @@ describe('buildInfluxQLQuery', () => {
database: 'db1', database: 'db1',
retentionPolicy: 'rp1', retentionPolicy: 'rp1',
measurement: 'm0', measurement: 'm0',
fields: [{name: 'min', type: 'func', alias: 'min_value', args: [{name: 'value', type: 'field'}]}], fields: [
{
value: 'min',
type: 'func',
alias: 'min_value',
args: [{value: 'value', type: 'field'}],
},
],
groupBy: {time: '10m', tags: ['t1', 't2']}, groupBy: {time: '10m', tags: ['t1', 't2']},
fill: NULL_STRING, fill: NULL_STRING,
}) })
@ -181,7 +188,7 @@ describe('buildInfluxQLQuery', () => {
database: 'db1', database: 'db1',
retentionPolicy: 'rp1', retentionPolicy: 'rp1',
measurement: 'm0', measurement: 'm0',
fields: [{name: 'f0', type: 'field'}, {name: 'f1', type: 'field'}], fields: [{value: 'f0', type: 'field'}, {value: 'f1', type: 'field'}],
}) })
timeBounds = {upper: "'2015-02-24T00:00:00Z'"} timeBounds = {upper: "'2015-02-24T00:00:00Z'"}
}) })
@ -203,7 +210,7 @@ describe('buildInfluxQLQuery', () => {
database: 'db1', database: 'db1',
measurement: 'm0', measurement: 'm0',
retentionPolicy: 'rp1', retentionPolicy: 'rp1',
fields: [{name: 'f0', type: 'field'}], fields: [{value: 'f0', type: 'field'}],
tags: { tags: {
k1: ['v1', 'v3', 'v4'], k1: ['v1', 'v3', 'v4'],
k2: ['v2'], k2: ['v2'],
@ -228,10 +235,10 @@ describe('buildInfluxQLQuery', () => {
measurement: 'm0', measurement: 'm0',
fields: [ fields: [
{ {
name: 'min', value: 'min',
type: 'func', type: 'func',
alias: 'min_value', alias: 'min_value',
args: [{name: 'value', type: 'field'}], args: [{value: 'value', type: 'field'}],
}, },
], ],
groupBy: {time: '10m', tags: []}, groupBy: {time: '10m', tags: []},
@ -253,10 +260,10 @@ describe('buildInfluxQLQuery', () => {
measurement: 'm0', measurement: 'm0',
fields: [ fields: [
{ {
name: 'min', value: 'min',
type: 'func', type: 'func',
alias: 'min_value', alias: 'min_value',
args: [{name: 'value', type: 'field'}], args: [{value: 'value', type: 'field'}],
}, },
], ],
groupBy: {time: '10m', tags: []}, groupBy: {time: '10m', tags: []},
@ -275,10 +282,10 @@ describe('buildInfluxQLQuery', () => {
measurement: 'm0', measurement: 'm0',
fields: [ fields: [
{ {
name: 'min', value: 'min',
type: 'func', type: 'func',
alias: 'min_value', alias: 'min_value',
args: [{name: 'value', type: 'field'}], args: [{value: 'value', type: 'field'}],
}, },
], ],
groupBy: {time: '10m', tags: []}, groupBy: {time: '10m', tags: []},
@ -297,10 +304,10 @@ describe('buildInfluxQLQuery', () => {
measurement: 'm0', measurement: 'm0',
fields: [ fields: [
{ {
name: 'min', value: 'min',
type: 'func', type: 'func',
alias: 'min_value', alias: 'min_value',
args: [{name: 'value', type: 'field'}], args: [{value: 'value', type: 'field'}],
}, },
], ],
groupBy: {time: '10m', tags: ['t1', 't2']}, groupBy: {time: '10m', tags: ['t1', 't2']},
@ -321,7 +328,7 @@ describe('buildInfluxQLQuery', () => {
database: 'db1', database: 'db1',
measurement: 'm1', measurement: 'm1',
retentionPolicy: 'rp1', retentionPolicy: 'rp1',
fields: [{name: 'f1', type: 'field'}], fields: [{value: 'f1', type: 'field'}],
groupBy: {time: '10m', tags: []}, groupBy: {time: '10m', tags: []},
}) })
}) })

View File

@ -26,16 +26,16 @@ class FieldListItem extends Component {
handleToggleField = () => { handleToggleField = () => {
const {onToggleField} = this.props const {onToggleField} = this.props
const name = this._getFieldName() const value = this._getFieldName()
onToggleField({name, type: 'field'}) onToggleField({value, type: 'field'})
this.close() this.close()
} }
handleApplyFunctions = selectedFuncs => { handleApplyFunctions = selectedFuncs => {
const {onApplyFuncsToField} = this.props const {onApplyFuncsToField} = this.props
const fieldName = this._getFieldName() const fieldName = this._getFieldName()
const field = {name: fieldName, type: 'field'} const field = {value: fieldName, type: 'field'}
onApplyFuncsToField({ onApplyFuncsToField({
field, field,
@ -44,8 +44,8 @@ class FieldListItem extends Component {
this.close() this.close()
} }
_makeFunc = name => ({ _makeFunc = value => ({
name, value,
type: 'func', type: 'func',
}) })
@ -54,7 +54,7 @@ class FieldListItem extends Component {
const fieldFunc = _.head(fieldFuncs) const fieldFunc = _.head(fieldFuncs)
return _.get(fieldFunc, 'type') === 'field' return _.get(fieldFunc, 'type') === 'field'
? _.get(fieldFunc, 'name') ? _.get(fieldFunc, 'value')
: firstFieldName(_.get(fieldFunc, 'args')) : firstFieldName(_.get(fieldFunc, 'args'))
} }
@ -121,12 +121,12 @@ FieldListItem.propTypes = {
fieldFuncs: arrayOf( fieldFuncs: arrayOf(
shape({ shape({
type: string.isRequired, type: string.isRequired,
name: string.isRequired, value: string.isRequired,
alias: string, alias: string,
args: arrayOf( args: arrayOf(
shape({ shape({
type: string.isRequired, type: string.isRequired,
name: string.isRequired, value: string.isRequired,
}) })
), ),
}) })

View File

@ -122,7 +122,7 @@ class FieldList extends Component {
} }
this.setState({ this.setState({
fields: fieldSets[measurement].map(f => ({name: f, type: 'field'})), fields: fieldSets[measurement].map(f => ({value: f, type: 'field'})),
}) })
}) })
} }
@ -167,11 +167,11 @@ class FieldList extends Component {
<FancyScrollbar> <FancyScrollbar>
{this.state.fields.map((fieldFunc, i) => { {this.state.fields.map((fieldFunc, i) => {
const selectedFields = getFieldsWithName( const selectedFields = getFieldsWithName(
fieldFunc.name, fieldFunc.value,
fields fields
) )
const funcs = getFuncsByFieldName(fieldFunc.name, fields) const funcs = getFuncsByFieldName(fieldFunc.value, fields)
const fieldFuncs = selectedFields.length const fieldFuncs = selectedFields.length
? selectedFields ? selectedFields
: [fieldFunc] : [fieldFunc]

View File

@ -72,12 +72,12 @@ function _buildFields(fieldFuncs) {
.map(f => { .map(f => {
switch (f.type) { switch (f.type) {
case 'field': { case 'field': {
return f.name === '*' ? '*' : `"${f.name}"` return f.value === '*' ? '*' : `"${f.value}"`
} }
case 'func': { case 'func': {
const args = _buildFields(f.args) const args = _buildFields(f.args)
const alias = f.alias ? ` AS "${f.alias}"` : '' const alias = f.alias ? ` AS "${f.alias}"` : ''
return `${f.name}(${args})${alias}` return `${f.value}(${args})${alias}`
} }
} }
}) })