Merge pull request #13734 from influxdata/remove-builderConfig

Sanitize query builderConfigs before exporting dashboards
pull/13741/head
Deniz Kusefoglu 2019-05-01 12:33:24 -07:00 committed by GitHub
commit 79f4e2b57e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 9 deletions

View File

@ -304,17 +304,13 @@ describe('resourceToTemplate', () => {
queries: [
{
text: 'v.bucket',
editMode: 'builder',
editMode: 'advanced',
name: 'View Query',
builderConfig: {
buckets: ['bb8'],
buckets: [],
tags: [
{
key: '_measurement',
values: ['cpu'],
},
{
key: '_field',
values: [],
},
],

View File

@ -1,5 +1,9 @@
import _ from 'lodash'
import {getDeep} from 'src/utils/wrappers'
import {defaultBuilderConfig} from 'src/shared/utils/view'
import {viewableLabels} from 'src/labels/selectors'
import {Task, Label, Dashboard, Cell, View} from 'src/types'
import {
TemplateType,
@ -7,7 +11,7 @@ import {
ITemplate,
IVariable as Variable,
} from '@influxdata/influx'
import {viewableLabels} from 'src/labels/selectors'
import {DashboardQuery, QueryEditMode} from 'src/types/dashboards'
const CURRENT_TEMPLATE_VERSION = '1'
@ -113,12 +117,27 @@ export const taskToTemplate = (
}
const viewToIncluded = (view: View) => {
const viewAttributes = _.pick(view, ['properties', 'name'])
let properties = view.properties
if ('queries' in properties) {
const sanitizedQueries = properties.queries.map((q: DashboardQuery) => {
return {
...q,
editMode: QueryEditMode.Advanced,
builderConfig: defaultBuilderConfig(),
}
})
properties = {
...properties,
queries: sanitizedQueries,
}
}
return {
type: TemplateType.View,
id: view.id,
attributes: viewAttributes,
attributes: {name: view.name, properties},
}
}