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
  • Loading branch information
asalem1 committed Feb 27, 2020
1 parent 4f2076a commit 38e8289
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
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
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 38e8289

Please sign in to comment.