import { FC, ReactNode, useState } from "react"; import { Table, Alert, Box, SegmentedControl, ScrollArea, Group, Stack, Text, Anchor, } from "@mantine/core"; import { IconAlertTriangle, IconInfoCircle } from "@tabler/icons-react"; import { InstantQueryResult, InstantSample, RangeSamples, } from "../../api/responseTypes/query"; import SeriesName from "./SeriesName"; import classes from "./DataTable.module.css"; import dayjs from "dayjs"; import timezone from "dayjs/plugin/timezone"; import { formatTimestamp } from "../../lib/formatTime"; import HistogramChart from "./HistogramChart"; import { Histogram } from "../../types/types"; import { bucketRangeString } from "./HistogramHelpers"; import { useSettings } from "../../state/settingsSlice"; dayjs.extend(timezone); const maxFormattableSeries = 10; const maxDisplayableSeries = 100; const limitSeries = ( series: S[], limit: boolean ): S[] => { if (limit && series.length > maxDisplayableSeries) { return series.slice(0, maxDisplayableSeries); } return series; }; export interface DataTableProps { data: InstantQueryResult; limitResults: boolean; setLimitResults: (limit: boolean) => void; } const DataTable: FC = ({ data, limitResults, setLimitResults, }) => { const [scale, setScale] = useState("exponential"); const { useLocalTime } = useSettings(); const { result, resultType } = data; const doFormat = result.length <= maxFormattableSeries; return ( {limitResults && ["vector", "matrix"].includes(resultType) && result.length > maxDisplayableSeries && ( } title="Showing limited results" > Fetched {data.result.length} metrics, only displaying first{" "} {maxDisplayableSeries} for performance reasons. setLimitResults(false)}> Show all results )} {!doFormat && ( } > Showing more than {maxFormattableSeries} series, turning off label formatting to improve rendering performance. )} {resultType === "vector" ? ( limitSeries(result, limitResults).map((s, idx) => ( {s.value && s.value[1]} {s.histogram && ( Count: {s.histogram[1].count} Sum: {s.histogram[1].sum} x-axis scale: {histogramTable(s.histogram[1])} )} )) ) : resultType === "matrix" ? ( limitSeries(result, limitResults).map((s, idx) => ( {s.values && s.values.map((v, idx) => (
{v[1]}{" "} @ {v[0]}
))}
)) ) : resultType === "scalar" ? ( Scalar value {result[1]} ) : resultType === "string" ? ( String value {result[1]} ) : ( } > Invalid result value type )}
); }; const histogramTable = (h: Histogram): ReactNode => ( Bucket range Count {h.buckets?.map((b, i) => ( {bucketRangeString(b)} {b[3]} ))}
); export default DataTable;