Merge pull request #3740 from influxdata/flux/delete-funcnode-and-yield
Delete func node and yield in builderpull/3742/head
commit
3797fd97b8
|
@ -75,7 +75,6 @@ class ExpressionNode extends PureComponent<Props, State> {
|
||||||
if (func.name === 'filter') {
|
if (func.name === 'filter') {
|
||||||
isAfterFilter = true
|
isAfterFilter = true
|
||||||
}
|
}
|
||||||
|
|
||||||
const isYieldable = isAfterFilter && isAfterRange
|
const isYieldable = isAfterFilter && isAfterRange
|
||||||
|
|
||||||
const funcNode = (
|
const funcNode = (
|
||||||
|
|
|
@ -2,6 +2,7 @@ import React, {PureComponent, MouseEvent} from 'react'
|
||||||
import classnames from 'classnames'
|
import classnames from 'classnames'
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
|
|
||||||
|
import {getDeep} from 'src/utils/wrappers'
|
||||||
import BodyDelete from 'src/flux/components/BodyDelete'
|
import BodyDelete from 'src/flux/components/BodyDelete'
|
||||||
import FuncArgs from 'src/flux/components/FuncArgs'
|
import FuncArgs from 'src/flux/components/FuncArgs'
|
||||||
import FuncArgsPreview from 'src/flux/components/FuncArgsPreview'
|
import FuncArgsPreview from 'src/flux/components/FuncArgsPreview'
|
||||||
|
@ -13,6 +14,7 @@ import {
|
||||||
Func,
|
Func,
|
||||||
} from 'src/types/flux'
|
} from 'src/types/flux'
|
||||||
import {ErrorHandling} from 'src/shared/decorators/errors'
|
import {ErrorHandling} from 'src/shared/decorators/errors'
|
||||||
|
|
||||||
import {Service} from 'src/types'
|
import {Service} from 'src/types'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
@ -166,9 +168,31 @@ export default class FuncNode extends PureComponent<Props, State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleDelete = (): void => {
|
private handleDelete = (): void => {
|
||||||
const {func, bodyID, declarationID} = this.props
|
const {
|
||||||
|
func,
|
||||||
|
funcs,
|
||||||
|
index,
|
||||||
|
bodyID,
|
||||||
|
declarationID,
|
||||||
|
isYielding,
|
||||||
|
isYieldedInScript,
|
||||||
|
onToggleYieldWithLast,
|
||||||
|
} = this.props
|
||||||
|
|
||||||
this.props.onDelete({funcID: func.id, bodyID, declarationID})
|
let yieldFuncNodeID: string
|
||||||
|
|
||||||
|
if (isYieldedInScript) {
|
||||||
|
yieldFuncNodeID = getDeep<string>(funcs, `${index + 1}.id`, '')
|
||||||
|
} else if (isYielding) {
|
||||||
|
onToggleYieldWithLast(index)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.props.onDelete({
|
||||||
|
funcID: func.id,
|
||||||
|
yieldNodeID: yieldFuncNodeID,
|
||||||
|
bodyID,
|
||||||
|
declarationID,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleToggleEdit = (e: MouseEvent<HTMLElement>): void => {
|
private handleToggleEdit = (e: MouseEvent<HTMLElement>): void => {
|
||||||
|
|
|
@ -522,7 +522,7 @@ export class FluxPage extends PureComponent<Props, State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleDeleteFuncNode = (ids: DeleteFuncNodeArgs): void => {
|
private handleDeleteFuncNode = (ids: DeleteFuncNodeArgs): void => {
|
||||||
const {funcID, declarationID = '', bodyID} = ids
|
const {funcID, declarationID = '', bodyID, yieldNodeID = ''} = ids
|
||||||
|
|
||||||
const script = this.state.body
|
const script = this.state.body
|
||||||
.map((body, bodyIndex) => {
|
.map((body, bodyIndex) => {
|
||||||
|
@ -541,12 +541,17 @@ export class FluxPage extends PureComponent<Props, State> {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const functions = declaration.funcs.filter(f => f.id !== funcID)
|
const functions = declaration.funcs.filter(
|
||||||
|
f => f.id !== funcID && f.id !== yieldNodeID
|
||||||
|
)
|
||||||
|
|
||||||
const s = this.funcsToSource(functions)
|
const s = this.funcsToSource(functions)
|
||||||
return `${declaration.name} = ${this.formatLastSource(s, isLast)}`
|
return `${declaration.name} = ${this.formatLastSource(s, isLast)}`
|
||||||
}
|
}
|
||||||
|
|
||||||
const funcs = body.funcs.filter(f => f.id !== funcID)
|
const funcs = body.funcs.filter(
|
||||||
|
f => f.id !== funcID && f.id !== yieldNodeID
|
||||||
|
)
|
||||||
const source = this.funcsToSource(funcs)
|
const source = this.funcsToSource(funcs)
|
||||||
return this.formatLastSource(source, isLast)
|
return this.formatLastSource(source, isLast)
|
||||||
})
|
})
|
||||||
|
|
|
@ -45,6 +45,7 @@ export interface DeleteFuncNodeArgs {
|
||||||
funcID: string
|
funcID: string
|
||||||
bodyID: string
|
bodyID: string
|
||||||
declarationID?: string
|
declarationID?: string
|
||||||
|
yieldNodeID?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface InputArg {
|
export interface InputArg {
|
||||||
|
|
Loading…
Reference in New Issue