feat: change columns for active queries (#4676)

This commit is contained in:
Yury Molodov 2023-07-21 02:18:47 +02:00 committed by GitHub
parent c400acbd18
commit ee0bf07d92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 25 deletions

View file

@ -14,7 +14,7 @@ import PreviewIcons from "./components/Main/Icons/PreviewIcons";
import WithTemplate from "./pages/WithTemplate"; import WithTemplate from "./pages/WithTemplate";
import Relabel from "./pages/Relabel"; import Relabel from "./pages/Relabel";
import ExploreLogs from "./pages/ExploreLogs/ExploreLogs"; import ExploreLogs from "./pages/ExploreLogs/ExploreLogs";
import from "./pages/ActiveQueries"; import ActiveQueries from "./pages/ActiveQueries";
const App: FC = () => { const App: FC = () => {
const [loadedTheme, setLoadedTheme] = useState(false); const [loadedTheme, setLoadedTheme] = useState(false);

View file

@ -11,6 +11,8 @@ import classNames from "classnames";
import Button from "../../components/Main/Button/Button"; import Button from "../../components/Main/Button/Button";
import { RefreshIcon } from "../../components/Main/Icons"; import { RefreshIcon } from "../../components/Main/Icons";
import "./style.scss"; import "./style.scss";
import { DATE_TIME_FORMAT } from "../../constants/date";
import { roundStep } from "../../utils/time";
const ActiveQueries: FC = () => { const ActiveQueries: FC = () => {
const { isMobile } = useDeviceDetect(); const { isMobile } = useDeviceDetect();
@ -18,29 +20,31 @@ const ActiveQueries: FC = () => {
const { data, lastUpdated, isLoading, error, fetchData } = useFetchActiveQueries(); const { data, lastUpdated, isLoading, error, fetchData } = useFetchActiveQueries();
const activeQueries = useMemo(() => data.map(({ duration, ...item }: ActiveQueriesType) => ({ const activeQueries = useMemo(() => data.map((item: ActiveQueriesType) => {
duration, const from = dayjs(item.start).tz().format(DATE_TIME_FORMAT);
data: JSON.stringify(item, null, 2), const to = dayjs(item.end).tz().format(DATE_TIME_FORMAT);
from: dayjs(item.start).tz().format("MMM DD, YYYY \nHH:mm:ss.SSS"), return {
to: dayjs(item.end).tz().format("MMM DD, YYYY \nHH:mm:ss.SSS"), duration: item.duration,
...item, remote_addr: item.remote_addr,
})), [data, timezone]); query: item.query,
args: `${from} to ${to}, step=${roundStep(item.step)}`,
data: JSON.stringify(item, null, 2),
} as ActiveQueriesType;
}), [data, timezone]);
const columns = useMemo(() => { const columns = useMemo(() => {
if (!activeQueries?.length) return []; if (!activeQueries?.length) return [];
const hideColumns = ["end", "start", "data"]; const keys = Object.keys(activeQueries[0]) as (keyof ActiveQueriesType)[];
const keys = new Set<string>();
for (const item of activeQueries) { const titles: Partial<Record<keyof ActiveQueriesType, string>> = {
for (const key in item) { remote_addr: "client address",
keys.add(key); };
} const hideColumns = ["data"];
}
return Array.from(keys) return keys.filter((col) => !hideColumns.includes(col)).map((key) => ({
.filter((col) => !hideColumns.includes(col)) key: key,
.map((key) => ({ title: titles[key] || key,
key: key as keyof ActiveQueriesType, }));
title: key,
}));
}, [activeQueries]); }, [activeQueries]);
const handleRefresh = async () => { const handleRefresh = async () => {
@ -76,7 +80,7 @@ const ActiveQueries: FC = () => {
<Table <Table
rows={activeQueries} rows={activeQueries}
columns={columns} columns={columns}
defaultOrderBy={"from"} defaultOrderBy={"duration"}
copyToClipboard={"data"} copyToClipboard={"data"}
paginationOffset={{ startIndex: 0, endIndex: Infinity }} paginationOffset={{ startIndex: 0, endIndex: Infinity }}
/> />

View file

@ -147,7 +147,6 @@ export interface ActiveQueriesType {
query: string; query: string;
remote_addr: string; remote_addr: string;
step: number; step: number;
from?: string; args?: string;
to?: string;
data?: string; data?: string;
} }

View file

@ -30,7 +30,7 @@ const shortDurations = supportedDurations.map(d => d.short);
export const roundToMilliseconds = (num: number): number => Math.round(num*1000)/1000; export const roundToMilliseconds = (num: number): number => Math.round(num*1000)/1000;
const roundStep = (step: number) => { export const roundStep = (step: number) => {
let result = roundToMilliseconds(step); let result = roundToMilliseconds(step);
const integerStep = Math.round(step); const integerStep = Math.round(step);