-
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 did account for missing data. If the latest value in a response 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". This commit updates the single stat computation to find the latest *defined* numeric values. If no 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) If multiple latest values are found, we make an arbitrary selection (same as previous behavior). The goal is to eventually expose UI elements to the user so they can make this selection themselves. 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
372 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,40 @@ | ||
// 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 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 === 0 && quiet) { | ||
return null | ||
} | ||
|
||
if (latestValues.length === 0) { | ||
return <EmptyGraphMessage message="No latest value found" /> | ||
} | ||
|
||
const latestValue = latestValues[0] | ||
|
||
return children(latestValue) | ||
} | ||
|
||
export default LatestValueTransform |
Oops, something went wrong.