Skip to content

Commit f803422

Browse files
VasiliyTruev.trushin
andauthored
add interval query param SH-231 (#1532)
Co-authored-by: v.trushin <[email protected]>
1 parent 618cc4b commit f803422

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

statshouse-ui/src/api/query.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export type ApiQueryGet =
4040
[GET_PARAMS.avoidCache]?: string;
4141
[GET_PARAMS.excessPoints]?: typeof GET_BOOLEAN.true;
4242
[GET_PARAMS.priority]?: string;
43+
[GET_PARAMS.metricLive]?: string;
4344
// [GetParams.metricFromEnd]?:string;
4445
// [GetParams.metricFromRow]?:string;
4546
// [GetParams.metricToRow]?:string;

statshouse-ui/src/api/table.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export type ApiTableGet = {
3636
[GET_PARAMS.metricFromEnd]?: string;
3737
[GET_PARAMS.metricFromRow]?: string;
3838
[GET_PARAMS.metricToRow]?: string;
39+
[GET_PARAMS.metricLive]?: string;
3940
};
4041

4142
export type GetTableResp = {

statshouse-ui/src/store2/plotDataStore/loadPlotData.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { MetricMeta, tagsArrToObject } from '../metricsMetaStore';
1919
export function getLoadPlotUrlParams(
2020
plotKey: PlotKey,
2121
params: QueryParams,
22+
interval?: number,
2223
fetchBadges: boolean = false,
2324
priority?: number
2425
): ApiQueryGet | null {
@@ -63,17 +64,21 @@ export function getLoadPlotUrlParams(
6364
if (priority) {
6465
urlParams[GET_PARAMS.priority] = priority.toString();
6566
}
67+
if (interval) {
68+
urlParams[GET_PARAMS.metricLive] = interval?.toString();
69+
}
6670

6771
return urlParams;
6872
}
6973

7074
export async function loadPlotData(
7175
plotKey: PlotKey,
7276
params: QueryParams,
77+
interval?: number,
7378
fetchBadges: boolean = false,
7479
priority?: number
7580
): Promise<ProduceUpdate<StatsHouseStore> | null> {
76-
const urlParams = getLoadPlotUrlParams(plotKey, params, fetchBadges, priority);
81+
const urlParams = getLoadPlotUrlParams(plotKey, params, interval, fetchBadges, priority);
7782
const plot = params.plots[plotKey];
7883
if (!urlParams || !plot) {
7984
return null;

statshouse-ui/src/store2/plotDataStore/plotsDataStore.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,14 @@ export const plotsDataStore: StoreSlice<StatsHouseStore, PlotsDataStore> = (setS
216216
const loadBadges = fetchBadges && !getState().plotsData[plotKey]?.loadBadges;
217217
let update = changePlotParam || changeTime || changeNowTime || changeTimeShifts || changeVariable || loadBadges;
218218
prepareEnd();
219+
219220
if (update) {
220221
const queryEnd = queryStart(plotKey);
221-
loadPlotData(plotKey, getState().params, fetchBadges, priority)
222+
223+
const { status, interval } = useLiveModeStore.getState();
224+
const intervalParam = status ? interval : undefined;
225+
226+
loadPlotData(plotKey, getState().params, intervalParam, fetchBadges, priority)
222227
.then((updatePlotData) => {
223228
if (updatePlotData) {
224229
setState(updatePlotData);

statshouse-ui/src/store2/plotEventsDataStore/plotEventsDataStore.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { uniqueArray } from 'common/helpers';
1818
import { formatByMetricType, getMetricType } from 'common/formatByMetricType';
1919
import { debug } from 'common/debug';
2020
import { fmtInputDateTime, formatLegendValue } from 'view/utils2';
21+
import { useLiveModeStore } from '../liveModeStore';
2122

2223
type EventDataChunk = GetTableResp & { to: number; from: number; fromEnd: boolean };
2324

@@ -69,7 +70,12 @@ export const plotEventsDataStore: StoreSlice<StatsHouseStore, PlotEventsDataStor
6970
prevEvent?.nextAbortController?.abort();
7071
}
7172
const controller = new AbortController();
72-
const apiParams = getLoadTableUrlParams(plotKey, prevState.params, key, fromEnd);
73+
74+
const { status, interval } = useLiveModeStore.getState();
75+
const intervalParam = status ? interval : undefined;
76+
77+
const apiParams = getLoadTableUrlParams(plotKey, prevState.params, intervalParam, key, fromEnd);
78+
7379
if (apiParams) {
7480
setState((state) => {
7581
const plotEventsData = state.plotsEventsData[plotKey];
@@ -210,6 +216,7 @@ export const plotEventsDataStore: StoreSlice<StatsHouseStore, PlotEventsDataStor
210216
export function getLoadTableUrlParams(
211217
plotKey: PlotKey,
212218
params: QueryParams,
219+
interval?: number,
213220
key?: string,
214221
fromEnd: boolean = false,
215222
limit: number = 1000
@@ -253,6 +260,10 @@ export function getLoadTableUrlParams(
253260
// urlParams.push(...encodeVariableConfig(allParams));
254261
// }
255262

263+
if (interval) {
264+
urlParams[GET_PARAMS.metricLive] = interval?.toString();
265+
}
266+
256267
return urlParams;
257268
}
258269

0 commit comments

Comments
 (0)