Skip to content

Commit

Permalink
fix(ui): updated default positioning for adding aggregate funcs when …
Browse files Browse the repository at this point in the history
…toggling from query builder (#17028)

fix(ui): updated default positioning for adding aggregate funcs when toggling from query builder
  • Loading branch information
asalem1 authored Mar 3, 2020
1 parent fca4e13 commit 2e348eb
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
### Features

### Bug Fixes

1. [17039](https://github.com/influxdata/influxdb/pull/17039): Fixed issue where tasks are exported for notification rules
1. [17042](https://github.com/influxdata/influxdb/pull/17042): Fixed issue where tasks are not exported when exporting by org id
1. [17070](https://github.com/influxdata/influxdb/pull/17070): Fixed issue where tasks with imports in query break in pkger
1. [17028](https://github.com/influxdata/influxdb/pull/17028): Fixed issue where selecting an aggregate function in the script editor was not adding the function to a new line

## v2.0.0-beta.5 [2020-02-27]

Expand Down
9 changes: 9 additions & 0 deletions ui/cypress/e2e/explorer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,15 @@ describe('DataExplorer', () => {
cy.getByTestID('switch-to-script-editor')
.should('be.visible')
.click()
cy.getByTestID('flux-function aggregate.rate').click()
// check to see if import is defaulted to the top
cy.get('.view-line')
.first()
.contains('import')
// check to see if new aggregate rate is at the bottom
cy.get('.view-line')
.last()
.contains('aggregate.')
cy.getByTestID('flux-editor').should('exist')
cy.getByTestID('flux-editor').within(() => {
cy.get('textarea').type('yoyoyoyoyo', {force: true})
Expand Down
26 changes: 20 additions & 6 deletions ui/src/timeMachine/components/TimeMachineFluxEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,28 @@ const TimeMachineFluxEditor: FC<Props> = ({

const handleInsertFluxFunction = (func: FluxToolbarFunction): void => {
const p = editorInstance.getPosition()
// sets the range based on the current position
let range = new window.monaco.Range(
p.lineNumber,
p.column,
p.lineNumber,
p.column
)
// edge case for when user toggles to the script editor
// this defaults the cursor to the initial position (top-left, 1:1 position)
if (p.lineNumber === 1 && p.column === 1) {
const [currentRange] = editorInstance.getVisibleRanges()
// adds the function to the end of the query
range = new window.monaco.Range(
currentRange.endLineNumber + 1,
p.column,
currentRange.endLineNumber + 1,
p.column
)
}
const edits = [
{
range: new window.monaco.Range(
p.lineNumber,
p.column,
p.lineNumber,
p.column
),
range,
text: formatFunctionForInsert(func.name, func.example),
},
]
Expand Down
27 changes: 27 additions & 0 deletions ui/src/timeMachine/utils/insertFunction.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {
generateImport,
formatFunctionForInsert,
} from 'src/timeMachine/utils/insertFunction'

describe('insertFunction', () => {
test('generateImport', () => {
const emptyImport = generateImport('', '')
expect(emptyImport).toEqual(false)
const func = 'aggregateWindow'
const script = `from(bucket: "b0")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement == "m0")`
const actual = generateImport(func, script)
expect(actual).toEqual(`import "${func}"`)
})

test('formatFunctionForInsert', () => {
const fluxFunc = 'funky'
const union = 'union'
const requiresNewLine = formatFunctionForInsert(union, fluxFunc)
expect(requiresNewLine).toEqual(`\n${fluxFunc}`)
const to = 'to'
const fluxNewLine = formatFunctionForInsert(to, fluxFunc)
expect(fluxNewLine).toEqual(`\n |> ${fluxFunc}`)
})
})
2 changes: 1 addition & 1 deletion ui/src/timeMachine/utils/insertFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const formatFunctionForInsert = (
return `\n${fluxFunction}`
}

return ` |> ${fluxFunction}`
return `\n |> ${fluxFunction}`
}

export const generateImport = (
Expand Down

0 comments on commit 2e348eb

Please sign in to comment.