Skip to content

Commit 7f227d6

Browse files
authored
feat: integrate selection with fieldsAsCols (#6218)
1 parent 411dcb1 commit 7f227d6

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

src/dataExplorer/components/FieldsAsColumns.tsx

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
1-
import React, {FC, useState} from 'react'
1+
import React, {FC, useCallback, useContext} from 'react'
22

33
// Components
44
import {ToggleWithLabelTooltip} from 'src/dataExplorer/components/ToggleWithLabelTooltip'
5+
import {PersistanceContext} from 'src/dataExplorer/context/persistance'
6+
import {event} from 'src/cloud/utils/reporting'
57

68
// Styles
79
import './Sidebar.scss'
810

9-
const FIELDS_AS_COLUMNS_TOOLTIP = `test`
10-
1111
const FieldsAsColumns: FC = () => {
12-
const [fieldsAsColumns, setFieldsAsColumns] = useState(false)
12+
const {selection, setSelection} = useContext(PersistanceContext)
13+
14+
const handleToggle = useCallback(() => {
15+
const value = !selection?.resultOptions?.fieldsAsColumn
16+
event('set fields as columns: ', {value: `${value}`})
17+
setSelection({
18+
resultOptions: {
19+
...selection.resultOptions,
20+
fieldsAsColumn: value,
21+
},
22+
})
23+
}, [selection.resultOptions, setSelection])
1324

1425
return (
1526
<ToggleWithLabelTooltip
1627
label="Fields as Columns"
17-
active={fieldsAsColumns}
18-
onChange={() => setFieldsAsColumns(current => !current)}
19-
tooltipContents={FIELDS_AS_COLUMNS_TOOLTIP}
28+
active={!!selection?.resultOptions?.fieldsAsColumn}
29+
onChange={handleToggle}
30+
tooltipContents={
31+
<>
32+
<code>schema.fieldsAsCols()</code> is a special application of{' '}
33+
<code>pivot()</code> that pivots input data on <code>_field</code> and{' '}
34+
<code>_time</code> columns to align fields within each input table
35+
that have the same timestamp.
36+
</>
37+
}
2038
/>
2139
)
2240
}

0 commit comments

Comments
 (0)