Skip to content

Commit 3699548

Browse files
subirjollySubir Jolly
andauthored
feat: show selected filters when searching in notebooks querybuilder (#3409)
* feat: show selected filters when searching * chore: update to float selected items * chore: update sorting per explorer * chore: add tag selector count and used shared component across the board * style: run prettier * chore: add some safety Co-authored-by: Subir Jolly <subirjolly@Subirs-MacBook-Pro.local>
1 parent 82c637c commit 3699548

File tree

5 files changed

+67
-18
lines changed

5 files changed

+67
-18
lines changed

src/flows/pipes/QueryBuilder/CardList.tsx

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import React, {FC, useCallback, useContext, useEffect, useState} from 'react'
1+
// Libraries
2+
import React, {
3+
FC,
4+
useCallback,
5+
useContext,
6+
useEffect,
7+
useMemo,
8+
useState,
9+
} from 'react'
210
import {
311
Input,
412
AlignItems,
@@ -7,15 +15,22 @@ import {
715
FlexBox,
816
} from '@influxdata/clockface'
917

18+
// Contexts
1019
import {QueryBuilderContext} from 'src/flows/pipes/QueryBuilder/context'
1120
import {PipeContext} from 'src/flows/context/pipe'
1221

22+
// Utils
1323
import {toComponentStatus} from 'src/shared/utils/toComponentStatus'
24+
25+
// Types
1426
import {RemoteDataState, BuilderAggregateFunctionType} from 'src/types'
27+
28+
// Components
1529
import SearchableDropdown from 'src/shared/components/SearchableDropdown'
30+
import TagSelectorCount from 'src/shared/components/TagSelectorCount'
31+
import WaitingText from 'src/shared/components/WaitingText'
1632
import BuilderCard from 'src/timeMachine/components/builderCard/BuilderCard'
1733
import SelectorList from 'src/timeMachine/components/SelectorList'
18-
import WaitingText from 'src/shared/components/WaitingText'
1934

2035
const DEBOUNCE_TIMEOUT = 500
2136
const debounce_array = []
@@ -44,6 +59,13 @@ const Card: FC<Props> = ({idx}) => {
4459
const [keySearches, setKeySearches] = useState([])
4560
const [valueSearches, setValueSearches] = useState([])
4661

62+
const allItems = useMemo(() => {
63+
const results = new Set(card?.values?.results)
64+
const selected = card?.values?.selected?.filter(s => !results.has(s))
65+
66+
return [...selected, ...Array.from(results)]
67+
}, [card?.values?.selected, card?.values?.results])
68+
4769
const _remove =
4870
idx !== 0 &&
4971
(() => {
@@ -87,7 +109,6 @@ const Card: FC<Props> = ({idx}) => {
87109
const valueSelect = val => {
88110
const _vals = [...card.values.selected]
89111
const index = _vals.indexOf(val)
90-
91112
if (index === -1) {
92113
_vals.push(val)
93114
} else {
@@ -173,10 +194,7 @@ const Card: FC<Props> = ({idx}) => {
173194
<WaitingText text="Loading tag values" />
174195
</BuilderCard.Empty>
175196
)
176-
} else if (
177-
card.values.loading === RemoteDataState.Done &&
178-
!card.values.results.length
179-
) {
197+
} else if (card.values.loading === RemoteDataState.Done && !allItems.length) {
180198
_values = (
181199
<BuilderCard.Empty>
182200
No values found <small>in the current time range</small>
@@ -185,7 +203,7 @@ const Card: FC<Props> = ({idx}) => {
185203
} else {
186204
_values = (
187205
<SelectorList
188-
items={card.values.results}
206+
items={allItems}
189207
selectedItems={card.values.selected}
190208
onSelectItem={valueSelect}
191209
multiSelect
@@ -245,6 +263,9 @@ const Card: FC<Props> = ({idx}) => {
245263
menuTestID="tag-selector--dropdown-menu"
246264
options={card.keys.results}
247265
/>
266+
{!!card?.values?.selected?.length && (
267+
<TagSelectorCount count={card.values.selected.length} />
268+
)}
248269
</FlexBox>
249270
<Input
250271
value={valueSearches[idx] || ''}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@import '@influxdata/clockface/dist/variables.scss';
2+
3+
.tag-selector-count {
4+
flex: 0 0 30px;
5+
height: 30px;
6+
background-color: $cf-grey-5;
7+
border-radius: 50%;
8+
text-align: center;
9+
line-height: 30px;
10+
font-weight: 900;
11+
user-select: none;
12+
color: $c-pool;
13+
font-size: 13px;
14+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React, {FC} from 'react'
2+
import './TagSelectorCount.scss'
3+
4+
interface OwnProps {
5+
count: number
6+
}
7+
8+
const TagSelectorCount: FC<OwnProps> = ({count}) => {
9+
const pluralizer = count <= 1 ? '' : 's'
10+
11+
return (
12+
<div
13+
className="tag-selector-count"
14+
title={`${count} value${pluralizer} selected`}
15+
>
16+
{count}
17+
</div>
18+
)
19+
}
20+
21+
export default TagSelectorCount

src/style/chronograf.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
@import 'src/shared/components/dropdown_auto_refresh/AutoRefreshDropdown.scss';
4646
@import 'src/shared/components/selectorList/SelectorList.scss';
4747
@import 'src/shared/components/CodeSnippet.scss';
48+
@import 'src/shared/components/TagSelectorCount.scss';
4849
@import 'src/buckets/components/Retention.scss';
4950
@import 'src/buckets/components/BucketAddDataButton.scss';
5051
@import 'src/buckets/components/NoBucketsWarning.scss';

src/timeMachine/components/TagSelector.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {
4848
BuilderAggregateFunctionType,
4949
RemoteDataState,
5050
} from 'src/types'
51+
import TagSelectorCount from 'src/shared/components/TagSelectorCount'
5152

5253
const SEARCH_DEBOUNCE_MS = 500
5354

@@ -210,17 +211,8 @@ class TagSelector extends PureComponent<Props> {
210211
private get selectedCounter(): JSX.Element {
211212
const {selectedValues} = this.props
212213

213-
const pluralizer = selectedValues.length === 1 ? '' : 's'
214-
215214
if (selectedValues.length > 0) {
216-
return (
217-
<div
218-
className="tag-selector--count"
219-
title={`${selectedValues.length} value${pluralizer} selected`}
220-
>
221-
{selectedValues.length}
222-
</div>
223-
)
215+
return <TagSelectorCount count={selectedValues.length} />
224216
}
225217
}
226218

0 commit comments

Comments
 (0)