feat(autoAgg): fix slight logic errors

pull/19130/head
Deniz Kusefoglu 2020-08-05 12:24:14 -07:00
parent 01c92de2fe
commit e59c6d2ba5
2 changed files with 20 additions and 26 deletions

View File

@ -65,10 +65,8 @@ const DurationInput: FC<Props> = ({
let inputStatus = controlledStatus || ComponentStatus.Default let inputStatus = controlledStatus || ComponentStatus.Default
if (inputStatus === ComponentStatus.Default) { if (inputStatus === ComponentStatus.Default && !isValid(inputValue)) {
inputStatus = isValid(inputValue) inputStatus = ComponentStatus.Error
? ComponentStatus.Default
: ComponentStatus.Error
} }
const onChange = (i: string) => { const onChange = (i: string) => {

View File

@ -444,22 +444,20 @@ export const multiSelectBuilderFunction = (name: string) => (
getState: GetState getState: GetState
) => { ) => {
const {draftQueries, activeQueryIndex} = getActiveTimeMachine(getState()) const {draftQueries, activeQueryIndex} = getActiveTimeMachine(getState())
const functions = draftQueries[activeQueryIndex].builderConfig.functions const functions = draftQueries[activeQueryIndex].builderConfig.functions
let newFunctions: BuilderFunctionsType[] const functionNames = functions.map(f => f.name)
const clickedFunctionAlreadySelected = functionNames.includes(name)
if (functions.find(f => f.name === name)) { if (!clickedFunctionAlreadySelected) {
if (functions.length == 1) { // add clicked to selected
// at least one function must be selected dispatch(setFunctions([...functionNames, name]))
return
}
newFunctions = functions.filter(f => f.name !== name)
} else { } else {
newFunctions = [...functions, {name}] if (functions.length > 1) {
// if more than one function is selected, remove clicked from selected
dispatch(setFunctions(functionNames.filter(n => n != name)))
}
} }
dispatch(setFunctions(newFunctions.map(f => f.name)))
} }
export const singleSelectBuilderFunction = (name: string) => ( export const singleSelectBuilderFunction = (name: string) => (
@ -467,22 +465,20 @@ export const singleSelectBuilderFunction = (name: string) => (
getState: GetState getState: GetState
) => { ) => {
const {draftQueries, activeQueryIndex} = getActiveTimeMachine(getState()) const {draftQueries, activeQueryIndex} = getActiveTimeMachine(getState())
const functions = draftQueries[activeQueryIndex].builderConfig.functions const functions = draftQueries[activeQueryIndex].builderConfig.functions
let newFunctions: BuilderFunctionsType[] const functionNames = functions.map(f => f.name)
const clickedFunctionAlreadySelected = functionNames.includes(name)
if (functions.find(f => f.name === name)) { if (!clickedFunctionAlreadySelected) {
if (functions.length == 1) { // select clicked function
// at least one function must be selected dispatch(setFunctions([name]))
return
}
newFunctions = functions.filter(f => f.name !== name)
} else { } else {
newFunctions = [{name}] if (functions.length > 1) {
// if more than one function is selected, remove clicked from selected
dispatch(setFunctions(functionNames.filter(n => n != name)))
}
} }
dispatch(setFunctions(newFunctions.map(f => f.name)))
} }
export const selectTagKey = (index: number, key: string) => ( export const selectTagKey = (index: number, key: string) => (