Skip to content

Commit f28d8f2

Browse files
committed
StatsHouse UI: fix encode remove params
1 parent 5e661bb commit f28d8f2

File tree

2 files changed

+39
-15
lines changed

2 files changed

+39
-15
lines changed

statshouse-ui/src/url2/urlEncode.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,13 @@ export function urlEncodeGlobalParam(
4141
paramArr.push([GET_PARAMS.metricTabNum, params.tabNum]);
4242
}
4343
if (!dequal(defaultParams.timeShifts, params.timeShifts)) {
44-
params.timeShifts.forEach((shift) => {
45-
paramArr.push([GET_PARAMS.metricTimeShifts, shift.toString()]);
46-
});
44+
if (params.timeShifts.length === 0 && defaultParams.timeShifts.length > 0) {
45+
paramArr.push([GET_PARAMS.metricTimeShifts, removeValueChar]);
46+
} else {
47+
params.timeShifts.forEach((shift) => {
48+
paramArr.push([GET_PARAMS.metricTimeShifts, shift.toString()]);
49+
});
50+
}
4751
}
4852
if (defaultParams.eventFrom !== params.eventFrom) {
4953
paramArr.push([GET_PARAMS.metricEventFrom, params.eventFrom.toString()]);

statshouse-ui/src/url2/widgetsParams/metric/metricEncode.ts

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,36 @@ export function metricEncode(plot: PlotParams, defaultPlot: PlotParams = getNewM
9494
}
9595

9696
if (!dequal(defaultPlot.events, plot.events)) {
97-
plot.events.forEach((e) => {
98-
paramArr.push([prefix + GET_PARAMS.metricEvent, e]);
99-
});
97+
//remove metric event
98+
if (plot.events.length === 0 && defaultPlot.events.length > 0) {
99+
paramArr.push([prefix + GET_PARAMS.metricEvent, removeValueChar]);
100+
} else {
101+
plot.events.forEach((e) => {
102+
paramArr.push([prefix + GET_PARAMS.metricEvent, e]);
103+
});
104+
}
100105
}
101106

102107
if (!dequal(defaultPlot.eventsBy, plot.eventsBy)) {
103-
plot.eventsBy.forEach((e) => {
104-
paramArr.push([prefix + GET_PARAMS.metricEventBy, e]);
105-
});
108+
//remove event by
109+
if (plot.eventsBy.length === 0 && defaultPlot.eventsBy.length > 0) {
110+
paramArr.push([prefix + GET_PARAMS.metricEventBy, removeValueChar]);
111+
} else {
112+
plot.eventsBy.forEach((e) => {
113+
paramArr.push([prefix + GET_PARAMS.metricEventBy, e]);
114+
});
115+
}
106116
}
107117

108118
if (!dequal(defaultPlot.eventsHide, plot.eventsHide)) {
109-
plot.eventsHide.forEach((e) => {
110-
paramArr.push([prefix + GET_PARAMS.metricEventHide, e]);
111-
});
119+
//remove event hide
120+
if (plot.eventsHide.length === 0 && defaultPlot.eventsHide.length > 0) {
121+
paramArr.push([prefix + GET_PARAMS.metricEventHide, removeValueChar]);
122+
} else {
123+
plot.eventsHide.forEach((e) => {
124+
paramArr.push([prefix + GET_PARAMS.metricEventHide, e]);
125+
});
126+
}
112127
}
113128

114129
if (defaultPlot.totalLine !== plot.totalLine) {
@@ -128,9 +143,14 @@ export function metricEncode(plot: PlotParams, defaultPlot: PlotParams = getNewM
128143
}
129144

130145
if (!dequal(defaultPlot.timeShifts, plot.timeShifts)) {
131-
plot.timeShifts.forEach((t) => {
132-
paramArr.push([prefix + GET_PARAMS.metricLocalTimeShifts, t.toString()]);
133-
});
146+
//remove local time shifts
147+
if (plot.timeShifts.length === 0 && defaultPlot.timeShifts.length > 0) {
148+
paramArr.push([prefix + GET_PARAMS.metricLocalTimeShifts, removeValueChar]);
149+
} else {
150+
plot.timeShifts.forEach((t) => {
151+
paramArr.push([prefix + GET_PARAMS.metricLocalTimeShifts, t.toString()]);
152+
});
153+
}
134154
}
135155
if (!paramArr.length && !defaultPlot.id) {
136156
if (plot.metricName === promQLMetric) {

0 commit comments

Comments
 (0)