-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ui): improve single stat computation
The method we used to compute a single stat / gauge value previously had a few issues: - If the latest value was part of a numeric column but was null/NaN/not defined, the single stat computation would fail and a user would see an error message "Could not display single stat because your values are non-numeric" - If there were multiple latest values, an arbitrary selection would be made This commit updates the single stat computation to find the latest *defined* numeric values. If multiple latest valid numeric values are found, we will either: - Display an error message if using the compuation within a single stat visualization - Display nothing if using the computation within a within a line + single stat visualization (i.e. display the line vis only) The behavior is similar if no latest numeric value is found. This commit also updates the single stat computation to use the @influxdata/vis `Table` format as an intermediate/parsed representation of a Flux CSV response. This unlocks the possibility for performance gains in our CSV parsing. See #13852. Closes #13824
- Loading branch information
Showing
15 changed files
with
307 additions
and
499 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Libraries | ||
import React, {useMemo, FunctionComponent} from 'react' | ||
import {Table} from '@influxdata/vis' | ||
|
||
// Components | ||
import EmptyGraphMessage from 'src/shared/components/EmptyGraphMessage' | ||
|
||
// Utils | ||
import {latestValues as getLatestValues} from 'src/shared/utils/latestValues' | ||
|
||
interface Props { | ||
table: Table | ||
children: (latestValue: number) => JSX.Element | ||
|
||
// If `quiet` is set and a single latest value can't be found, this component | ||
// will display nothing instead of an empty graph error message | ||
quiet?: boolean | ||
} | ||
|
||
const LatestValueTransform: FunctionComponent<Props> = ({ | ||
table, | ||
quiet = false, | ||
children, | ||
}) => { | ||
const latestValues = useMemo(() => getLatestValues(table), [table]) | ||
|
||
if (latestValues.length !== 1 && quiet) { | ||
return null | ||
} | ||
|
||
if (latestValues.length === 0) { | ||
return <EmptyGraphMessage message="No latest value found" /> | ||
} | ||
|
||
if (latestValues.length > 1) { | ||
return <EmptyGraphMessage message="Multiple latest values found" /> | ||
} | ||
|
||
return children(latestValues[0]) | ||
} | ||
|
||
export default LatestValueTransform |
Oops, something went wrong.