Skip to content

Commit 1e7a26e

Browse files
authored
feat: force measurement selection for data explorer (#4523)
1 parent 80ebb78 commit 1e7a26e

File tree

5 files changed

+58
-35
lines changed

5 files changed

+58
-35
lines changed

src/timeMachine/actions/queryBuilderThunks.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import {
5353
setFunctions,
5454
} from 'src/timeMachine/actions/queryBuilder'
5555
import {setBuckets} from 'src/buckets/actions/creators'
56+
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
5657

5758
// Constants
5859
import {AGG_WINDOW_AUTO} from 'src/timeMachine/constants/queryBuilder'
@@ -321,10 +322,15 @@ export const selectTagValue = (index: number, value: string) => (
321322
currentTag.key === '_field'
322323
) {
323324
newValues = [value]
325+
} else if (isFlagEnabled('newQueryBuilder') && index === 0) {
326+
newValues = [value]
324327
} else {
325328
newValues = [...values, value]
326329
}
327330

331+
if (newValues.length === 0 && index === 0) {
332+
dispatch(removeTagSelector(index + 1))
333+
}
328334
dispatch(setBuilderTagValuesSelection(index, newValues))
329335

330336
// don't add a new tag filter if we're grouping

src/timeMachine/components/SelectorList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Libraries
2-
import React, {SFC} from 'react'
2+
import React, {FC} from 'react'
33

44
// Components
55
import {List, ComponentSize} from '@influxdata/clockface'
@@ -14,7 +14,7 @@ interface Props {
1414
wrapText?: boolean
1515
}
1616

17-
const SelectorList: SFC<Props> = props => {
17+
const SelectorList: FC<Props> = props => {
1818
const {
1919
items,
2020
selectedItems,

src/timeMachine/components/SubmitQueryButton.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,14 @@ const mstp = (state: AppState) => {
150150
const queryStatus = getActiveTimeMachine(state).queryResults.status
151151

152152
const activeQueryText = getActiveQuery(state).text
153-
const submitButtonDisabled = activeQueryText === ''
153+
const tags = getActiveQuery(state).builderConfig?.tags ?? []
154+
const activeQuery = getActiveQuery(state)
155+
const measurementTag = tags?.[0]
156+
const submitButtonDisabled =
157+
activeQueryText === '' ||
158+
(activeQuery.editMode === 'builder' &&
159+
measurementTag &&
160+
measurementTag.values.length === 0)
154161
const allVars = getAllVariables(state)
155162
const orgID = getOrg(state).id
156163

src/timeMachine/components/TagSelector.tsx

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
selectTagKey,
2727
selectTagValue,
2828
} from 'src/timeMachine/actions/queryBuilderThunks'
29+
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
2930

3031
import {
3132
setBuilderAggregateFunctionType,
@@ -85,9 +86,29 @@ class TagSelector extends PureComponent<Props> {
8586
)
8687
}
8788

89+
private get isCompliant() {
90+
const {
91+
index,
92+
selectedKey,
93+
selectedValues,
94+
aggregateFunctionType,
95+
} = this.props
96+
97+
return (
98+
isFlagEnabled('newQueryBuilder') &&
99+
index === 0 &&
100+
selectedKey === '_measurement' &&
101+
aggregateFunctionType !== 'group' &&
102+
selectedValues.length <= 1
103+
)
104+
}
105+
88106
private get header() {
89107
const {aggregateFunctionType, index, isInCheckOverlay} = this.props
90108

109+
if (this.isCompliant) {
110+
return null
111+
}
91112
return (
92113
<BuilderCard.DropdownHeader
93114
options={['filter', 'group']}
@@ -133,6 +154,7 @@ class TagSelector extends PureComponent<Props> {
133154
: `Search ${selectedKey} tag values`
134155
return (
135156
<>
157+
{this.isCompliant && <BuilderCard.Header title="Measurement" />}
136158
<BuilderCard.Menu testID={`tag-selector--container ${index}`}>
137159
{aggregateFunctionType !== 'group' && (
138160
<FlexBox
@@ -141,19 +163,21 @@ class TagSelector extends PureComponent<Props> {
141163
margin={ComponentSize.Small}
142164
>
143165
<ErrorBoundary>
144-
<SearchableDropdown
145-
searchTerm={keysSearchTerm}
146-
emptyText="No Tags Found"
147-
searchPlaceholder="Search keys..."
148-
buttonStatus={toComponentStatus(keysStatus)}
149-
selectedOption={selectedKey}
150-
onSelect={this.handleSelectTag}
151-
onChangeSearchTerm={this.handleKeysSearch}
152-
testID="tag-selector--dropdown"
153-
buttonTestID="tag-selector--dropdown-button"
154-
menuTestID="tag-selector--dropdown-menu"
155-
options={keys}
156-
/>
166+
{!this.isCompliant && (
167+
<SearchableDropdown
168+
searchTerm={keysSearchTerm}
169+
emptyText="No Tags Found"
170+
searchPlaceholder="Search keys..."
171+
buttonStatus={toComponentStatus(keysStatus)}
172+
selectedOption={selectedKey}
173+
onSelect={this.handleSelectTag}
174+
onChangeSearchTerm={this.handleKeysSearch}
175+
testID="tag-selector--dropdown"
176+
buttonTestID="tag-selector--dropdown-button"
177+
menuTestID="tag-selector--dropdown-menu"
178+
options={keys}
179+
/>
180+
)}
157181
</ErrorBoundary>
158182
{this.selectedCounter}
159183
</FlexBox>
@@ -206,7 +230,7 @@ class TagSelector extends PureComponent<Props> {
206230
items={values}
207231
selectedItems={selectedValues}
208232
onSelectItem={this.handleSelectValue}
209-
multiSelect={!this.props.isInCheckOverlay}
233+
multiSelect={!this.props.isInCheckOverlay || this.isCompliant}
210234
/>
211235
)
212236
}

src/timeMachine/components/TimeMachine.tsx

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Libraries
22
import React, {useState, FunctionComponent} from 'react'
3-
import {connect} from 'react-redux'
3+
import {useSelector} from 'react-redux'
44
import classnames from 'classnames'
55

66
// Components
@@ -14,20 +14,12 @@ import ViewOptions from 'src/timeMachine/components/ViewOptions'
1414
import {getActiveTimeMachine} from 'src/timeMachine/selectors'
1515

1616
// Types
17-
import {AppState, TimeMachineTab} from 'src/types'
1817
import ErrorBoundary from 'src/shared/components/ErrorBoundary'
1918

2019
const INITIAL_RESIZER_HANDLE = 0.4
2120

22-
interface StateProps {
23-
activeTab: TimeMachineTab
24-
isViewingVisOptions: boolean
25-
}
26-
27-
const TimeMachine: FunctionComponent<StateProps> = ({
28-
activeTab,
29-
isViewingVisOptions,
30-
}) => {
21+
const TimeMachine: FunctionComponent = () => {
22+
const {activeTab, isViewingVisOptions} = useSelector(getActiveTimeMachine)
3123
const [dragPosition, setDragPosition] = useState([INITIAL_RESIZER_HANDLE])
3224

3325
const containerClassName = classnames('time-machine', {
@@ -73,10 +65,4 @@ const TimeMachine: FunctionComponent<StateProps> = ({
7365
)
7466
}
7567

76-
const mstp = (state: AppState) => {
77-
const {activeTab, isViewingVisOptions} = getActiveTimeMachine(state)
78-
79-
return {activeTab, isViewingVisOptions}
80-
}
81-
82-
export default connect<StateProps>(mstp)(TimeMachine)
68+
export default TimeMachine

0 commit comments

Comments
 (0)