Skip to content

perf: auto select min, max, and mean #19356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions ui/cypress/e2e/explorer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,7 @@ describe('DataExplorer', () => {
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
6 changes: 5 additions & 1 deletion ui/src/shared/utils/resourceToTemplate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,11 @@ describe('resourceToTemplate', () => {
aggregateFunctionType: 'filter',
},
],
functions: [{name: 'mean'}],
functions: [
{name: 'mean'},
{name: 'min'},
{name: 'max'},
],
aggregateWindow: {period: 'auto', fillValues: false},
},
},
Expand Down
33 changes: 13 additions & 20 deletions ui/src/timeMachine/components/FunctionModeSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import SelectorList from 'src/timeMachine/components/SelectorList'
//Actions
import {
multiSelectBuilderFunction,
singleSelectBuilderFunction,
setFunctions,
singleSelectBuilderFunction,
} from 'src/timeMachine/actions/queryBuilder'

// Utils
Expand All @@ -36,16 +36,13 @@ type Props = ReduxProps
const FunctionSelector: FunctionComponent<Props> = ({
onSetFunctions,
selectedFunctions,
onSingleSelectBuilderFunction,
onMultiSelectBuilderFunction,
onSingleSelectFunc,
onMultiSelectFunc,
isInCheckOverlay,
}) => {
const autoFunctions = AUTO_FUNCTIONS.map(f => f.name)
const [isAutoFunction, setIsAutoFunction] = useState(
!isInCheckOverlay &&
selectedFunctions.length === 1 &&
autoFunctions.includes(selectedFunctions[0])
)

const [isAutoFunction, setIsAutoFunction] = useState(!isInCheckOverlay)

const functionList = isAutoFunction
? autoFunctions
Expand All @@ -56,24 +53,20 @@ const FunctionSelector: FunctionComponent<Props> = ({
setIsAutoFunction(false)
return
}

const newFunctions = selectedFunctions.filter(f =>
autoFunctions.includes(f)
)

if (newFunctions.length === 0) {
onSetFunctions([autoFunctions[0]])
} else if (newFunctions.length > 1) {
onSetFunctions([newFunctions[0]])
onSetFunctions(['mean', 'max', 'min'])
} else {
onSetFunctions(newFunctions)
}

setIsAutoFunction(true)
}

const onSelectFunction = isAutoFunction
? onSingleSelectBuilderFunction
: onMultiSelectBuilderFunction

if (isInCheckOverlay) {
return (
<>
Expand All @@ -84,7 +77,7 @@ const FunctionSelector: FunctionComponent<Props> = ({
<SelectorList
items={functionList}
selectedItems={selectedFunctions}
onSelectItem={onSingleSelectBuilderFunction}
onSelectItem={onSingleSelectFunc}
multiSelect={false}
/>
</>
Expand Down Expand Up @@ -135,8 +128,8 @@ const FunctionSelector: FunctionComponent<Props> = ({
<SelectorList
items={functionList}
selectedItems={selectedFunctions}
onSelectItem={onSelectFunction}
multiSelect={!isAutoFunction}
onSelectItem={onMultiSelectFunc}
multiSelect={true}
/>
</>
)
Expand All @@ -152,8 +145,8 @@ const mstp = (state: AppState) => {
}

const mdtp = {
onMultiSelectBuilderFunction: multiSelectBuilderFunction,
onSingleSelectBuilderFunction: singleSelectBuilderFunction,
onMultiSelectFunc: multiSelectBuilderFunction,
onSingleSelectFunc: singleSelectBuilderFunction,
onSetFunctions: setFunctions,
}

Expand Down
23 changes: 20 additions & 3 deletions ui/src/timeMachine/constants/queryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ export const AUTO_FUNCTIONS: QueryFn[] = [
name: 'mean',
flux: (period, fillValues) => genFlux('mean', period, fillValues),
},
{
name: 'max',
flux: (period, fillValues) => genFlux('max', period, fillValues),
},
{
name: 'min',
flux: (period, fillValues) => genFlux('min', period, fillValues),
},
{
name: 'median',
flux: (period, fillValues) => genFlux('median', period, fillValues),
Expand All @@ -72,8 +80,14 @@ export const AUTO_FUNCTIONS: QueryFn[] = [
]

export const FUNCTIONS: QueryFn[] = [
AUTO_FUNCTIONS[0],
AUTO_FUNCTIONS[1],
{
name: 'mean',
flux: (period, fillValues) => genFlux('mean', period, fillValues),
},
{
name: 'median',
flux: (period, fillValues) => genFlux('median', period, fillValues),
},
{
name: 'max',
flux: (period, fillValues) => genFlux('max', period, fillValues),
Expand Down Expand Up @@ -123,7 +137,10 @@ export const FUNCTIONS: QueryFn[] = [
name: 'first',
flux: (period, fillValues) => genFlux('first', period, fillValues),
},
AUTO_FUNCTIONS[2],
{
name: 'last',
flux: (period, fillValues) => genFlux('last', period, fillValues),
},
{
name: 'unique',
flux: (period, fillValues) => genFlux('unique', period, fillValues),
Expand Down
4 changes: 3 additions & 1 deletion ui/src/timeMachine/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ import {Action} from 'src/timeMachine/actions'
import {TimeMachineTab} from 'src/types/timeMachine'
import {BuilderAggregateFunctionType} from 'src/client/generatedRoutes'

type Functions = {name: string}[]

interface QueryBuilderState {
buckets: string[]
bucketsStatus: RemoteDataState
functions: Array<[{name: string}]>
functions: Functions[]
aggregateWindow: BuilderConfigAggregateWindow
tags: Array<{
aggregateFunctionType: BuilderAggregateFunctionType
Expand Down
2 changes: 1 addition & 1 deletion ui/src/views/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function defaultBuilderConfig(): BuilderConfig {
return {
buckets: [],
tags: [{key: '_measurement', values: [], aggregateFunctionType: 'filter'}],
functions: [{name: 'mean'}],
functions: [{name: 'mean'}, {name: 'min'}, {name: 'max'}],
aggregateWindow: {period: AGG_WINDOW_AUTO, fillValues: DEFAULT_FILLVALUES},
}
}
Expand Down