Skip to content

Commit 0e3a447

Browse files
feat(schemaBrowser): add "Flux Sync" toggle button (#5502)
* feat: add heading and flux sync toggle button * style: add icon and style to flux sync toggle label * chore: move `SchemaBrowserHeading` into a separate file * feat: add fluxSync to flux query builder context * refactor: update class name to `schema-browser-heading` * chore: add memo to SchemaBrowserHeading and add paramter to toggleFluxSync func * chore: remove comment * chore: javascript syntax
1 parent dcbdb1e commit 0e3a447

File tree

5 files changed

+114
-10
lines changed

5 files changed

+114
-10
lines changed

src/dataExplorer/components/Schema.scss

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@
2424
}
2525
}
2626

27+
.schema-browser-heading {
28+
padding-bottom: $cf-space-2xs;
29+
30+
.schema-browser-heading--text {
31+
font-size: 16px;
32+
font-weight: $cf-font-weight--bold;
33+
}
34+
35+
.flux-sync--label {
36+
padding-left: $cf-space-2xs;
37+
38+
.selector-title {
39+
padding-bottom: 0;
40+
}
41+
}
42+
}
43+
2744
.container-side-bar,
2845
.container-side-bar--fields,
2946
.container-side-bar--tag-keys,
@@ -35,14 +52,18 @@
3552

3653
.selector-title {
3754
padding-bottom: $cf-space-2xs;
38-
}
3955

40-
.selector-title--icon {
41-
padding-left: $cf-space-2xs;
42-
}
56+
.selector-title--question-mark {
57+
padding-left: $cf-space-2xs;
58+
}
59+
60+
.selector-title--question-mark .cf-question-mark-tooltip {
61+
background-color: $cf-grey-35;
62+
}
4363

44-
.selector-title--icon .cf-question-mark-tooltip {
45-
background-color: $cf-grey-35;
64+
.selector-title--icon {
65+
padding-right: 2px;
66+
}
4667
}
4768

4869
.field-selector,

src/dataExplorer/components/Schema.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import BucketSelector from 'src/dataExplorer/components/BucketSelector'
88
import MeasurementSelector from 'src/dataExplorer/components/MeasurementSelector'
99
import FieldSelector from 'src/dataExplorer/components/FieldSelector'
1010
import TagSelector from 'src/dataExplorer/components/TagSelector'
11+
import SchemaBrowserHeading from 'src/dataExplorer/components/SchemaBrowserHeading'
1112

1213
// Context
1314
import {
@@ -80,6 +81,7 @@ const Schema: FC = () => {
8081
<div className="scroll--container">
8182
<DapperScrollbars>
8283
<div className="schema-browser" data-testid="schema-browser">
84+
<SchemaBrowserHeading />
8385
<BucketSelector />
8486
<div className="container-side-bar">
8587
<MeasurementSelector />
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import React, {FC, useContext, useMemo} from 'react'
2+
3+
// Components
4+
import {
5+
FlexBox,
6+
InputLabel,
7+
SlideToggle,
8+
JustifyContent,
9+
IconFont,
10+
} from '@influxdata/clockface'
11+
import SelectorTitle from 'src/dataExplorer/components/SelectorTitle'
12+
13+
// Context
14+
import {FluxQueryBuilderContext} from 'src/dataExplorer/context/fluxQueryBuilder'
15+
16+
const FLUX_SYNC_TOOLTIP = `Flux Sync autopopulates the script editor to help you \
17+
start a query. You can turn this feature on and off, but typing within this \
18+
section will disable synchronization.`
19+
20+
const SchemaBrowserHeading: FC = () => {
21+
const {fluxSync, toggleFluxSync} = useContext(FluxQueryBuilderContext)
22+
23+
const handleFluxSyncToggle = () => {
24+
toggleFluxSync(!fluxSync)
25+
}
26+
27+
return useMemo(
28+
() => (
29+
<FlexBox
30+
className="schema-browser-heading"
31+
justifyContent={JustifyContent.SpaceBetween}
32+
>
33+
<div className="schema-browser-heading--text">Schema Browser</div>
34+
<FlexBox className="flux-sync">
35+
<SlideToggle
36+
className="flux-sync--toggle"
37+
active={fluxSync}
38+
onChange={handleFluxSyncToggle}
39+
testID="flux-sync--toggle"
40+
/>
41+
<InputLabel className="flux-sync--label">
42+
<SelectorTitle
43+
title="Flux Sync"
44+
info={FLUX_SYNC_TOOLTIP}
45+
icon={IconFont.Switch_New}
46+
/>
47+
</InputLabel>
48+
</FlexBox>
49+
</FlexBox>
50+
),
51+
[fluxSync]
52+
)
53+
}
54+
55+
export default SchemaBrowserHeading

src/dataExplorer/components/SelectorTitle.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
import React, {FC} from 'react'
22

33
// Componnents
4-
import {FlexBox, QuestionMarkTooltip} from '@influxdata/clockface'
4+
import {
5+
FlexBox,
6+
QuestionMarkTooltip,
7+
Icon,
8+
IconFont,
9+
} from '@influxdata/clockface'
510

611
// Styles
712
import './Schema.scss'
813

914
interface TitleProps {
1015
title: string
11-
info?: string // TODO: markdon? since there might be link
16+
info?: string
17+
icon?: IconFont
1218
}
1319

14-
const SelectorTitle: FC<TitleProps> = ({title, info = ''}) => {
20+
const SelectorTitle: FC<TitleProps> = ({title, info = '', icon = null}) => {
1521
return (
1622
<FlexBox className="selector-title">
23+
{icon && <Icon glyph={icon} className="selector-title--icon" />}
1724
<div>{title}</div>
1825
{info && (
19-
<div className="selector-title--icon">
26+
<div className="selector-title--question-mark">
2027
<QuestionMarkTooltip
2128
tooltipContents={info}
2229
diameter={14}

src/dataExplorer/context/fluxQueryBuilder.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ const debouncer = (action: NOOP): void => {
3838
}
3939

4040
interface FluxQueryBuilderContextType {
41+
// Flux Sync
42+
fluxSync: boolean
43+
toggleFluxSync: (synced: boolean) => void
44+
4145
// Schema
4246
selectedBucket: Bucket
4347
selectedMeasurement: string
@@ -50,6 +54,10 @@ interface FluxQueryBuilderContextType {
5054
}
5155

5256
const DEFAULT_CONTEXT: FluxQueryBuilderContextType = {
57+
// Flux Sync
58+
fluxSync: true,
59+
toggleFluxSync: _s => {},
60+
5361
// Schema
5462
selectedBucket: null,
5563
selectedMeasurement: '',
@@ -85,6 +93,10 @@ export const FluxQueryBuilderProvider: FC = ({children}) => {
8593
}
8694
}, [selection.bucket])
8795

96+
const handleToggleFluxSync = (synced: boolean): void => {
97+
setSelection({composition: {synced}})
98+
}
99+
88100
const handleSelectBucket = (bucket: Bucket): void => {
89101
setSelection({bucket, measurement: ''})
90102

@@ -155,6 +167,10 @@ export const FluxQueryBuilderProvider: FC = ({children}) => {
155167
() => (
156168
<FluxQueryBuilderContext.Provider
157169
value={{
170+
// Flux Sync
171+
fluxSync: selection.composition?.synced,
172+
toggleFluxSync: handleToggleFluxSync,
173+
158174
// Schema
159175
selectedBucket: selection.bucket,
160176
selectedMeasurement: selection.measurement,
@@ -170,6 +186,9 @@ export const FluxQueryBuilderProvider: FC = ({children}) => {
170186
</FluxQueryBuilderContext.Provider>
171187
),
172188
[
189+
// Flux Sync
190+
selection.composition?.synced,
191+
173192
// Schema
174193
selection.bucket,
175194
selection.measurement,

0 commit comments

Comments
 (0)