Skip to content

Commit 730202c

Browse files
authored
feat: limiting down to a single measurement (#4286)
1 parent 96c20c3 commit 730202c

File tree

1 file changed

+59
-34
lines changed

1 file changed

+59
-34
lines changed

src/flows/pipes/QueryBuilder/CardList.tsx

Lines changed: 59 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {PipeContext} from 'src/flows/context/pipe'
2121

2222
// Utils
2323
import {toComponentStatus} from 'src/shared/utils/toComponentStatus'
24+
import {isFlagEnabled} from 'src/shared/utils/featureFlag'
2425

2526
// Types
2627
import {RemoteDataState, BuilderAggregateFunctionType} from 'src/types'
@@ -114,16 +115,35 @@ const Card: FC<Props> = ({idx}) => {
114115
})
115116
}
116117

118+
const isCompliant =
119+
isFlagEnabled('newQueryBuilder') &&
120+
idx === 0 &&
121+
(card.keys.selected.length === 0 ||
122+
(card.keys.selected.length === 1 &&
123+
card.keys.selected[0] === '_measurement')) &&
124+
card.aggregateFunctionType !== 'group' &&
125+
card.values.selected.length <= 1
126+
117127
const valueSelect = val => {
118-
const _vals = [...card.values.selected]
128+
let _vals = [...card.values.selected]
119129
const index = _vals.indexOf(val)
130+
120131
if (index === -1) {
121132
event('Query Builder Value Selected')
122-
_vals.push(val)
133+
if (isCompliant) {
134+
_vals = [val]
135+
} else {
136+
_vals.push(val)
137+
}
123138
} else {
124139
event('Query Builder Value Unselected')
125-
_vals.splice(index, 1)
140+
if (isCompliant) {
141+
_vals = []
142+
} else {
143+
_vals.splice(index, 1)
144+
}
126145
}
146+
127147
update(idx, {
128148
values: {
129149
...card.values,
@@ -216,7 +236,7 @@ const Card: FC<Props> = ({idx}) => {
216236
items={allItems}
217237
selectedItems={card.values.selected}
218238
onSelectItem={valueSelect}
219-
multiSelect
239+
multiSelect={!isCompliant}
220240
/>
221241
)
222242
}
@@ -248,37 +268,42 @@ const Card: FC<Props> = ({idx}) => {
248268

249269
return (
250270
<BuilderCard>
251-
<BuilderCard.DropdownHeader
252-
options={['filter', 'group'].map(s => s.toUpperCase())}
253-
selectedOption={card.aggregateFunctionType.toUpperCase()}
254-
onDelete={_remove}
255-
onSelect={_update}
256-
/>
271+
{!isCompliant && (
272+
<BuilderCard.DropdownHeader
273+
options={['filter', 'group'].map(s => s.toUpperCase())}
274+
selectedOption={card.aggregateFunctionType.toUpperCase()}
275+
onDelete={_remove}
276+
onSelect={_update}
277+
/>
278+
)}
279+
{isCompliant && <BuilderCard.Header title="Measurement" />}
257280
<BuilderCard.Menu>
258-
<FlexBox
259-
direction={FlexDirection.Row}
260-
alignItems={AlignItems.Center}
261-
margin={ComponentSize.Small}
262-
>
263-
<ErrorBoundary>
264-
<SearchableDropdown
265-
searchTerm={keySearches[idx] || ''}
266-
emptyText="No Tags Found"
267-
searchPlaceholder="Search keys..."
268-
selectedOption={card.keys.selected[0]}
269-
onSelect={keySelect}
270-
buttonStatus={toComponentStatus(card.keys.loading)}
271-
onChangeSearchTerm={keySearch}
272-
testID="tag-selector--dropdown"
273-
buttonTestID="tag-selector--dropdown-button"
274-
menuTestID="tag-selector--dropdown-menu"
275-
options={card.keys.results}
276-
/>
277-
</ErrorBoundary>
278-
{!!card?.values?.selected?.length && (
279-
<TagSelectorCount count={card.values.selected.length} />
280-
)}
281-
</FlexBox>
281+
{!isCompliant && (
282+
<FlexBox
283+
direction={FlexDirection.Row}
284+
alignItems={AlignItems.Center}
285+
margin={ComponentSize.Small}
286+
>
287+
<ErrorBoundary>
288+
<SearchableDropdown
289+
searchTerm={keySearches[idx] || ''}
290+
emptyText="No Tags Found"
291+
searchPlaceholder="Search keys..."
292+
selectedOption={card.keys.selected[0]}
293+
onSelect={keySelect}
294+
buttonStatus={toComponentStatus(card.keys.loading)}
295+
onChangeSearchTerm={keySearch}
296+
testID="tag-selector--dropdown"
297+
buttonTestID="tag-selector--dropdown-button"
298+
menuTestID="tag-selector--dropdown-menu"
299+
options={card.keys.results}
300+
/>
301+
</ErrorBoundary>
302+
{!!card?.values?.selected?.length && (
303+
<TagSelectorCount count={card.values.selected.length} />
304+
)}
305+
</FlexBox>
306+
)}
282307
<Input
283308
value={valueSearches[idx] || ''}
284309
placeholder={`Search ${card.keys.selected[0]} tag values`}

0 commit comments

Comments
 (0)