fix: set the step to SECOND in the duration for Log/Trace/Alarm/Tag (#537)

This commit is contained in:
Fine0830
2026-03-30 12:36:59 +08:00
committed by GitHub
parent 370bfbc87d
commit 431bcc0891
5 changed files with 21 additions and 13 deletions

View File

@@ -16,6 +16,7 @@
*/
export enum TimeType {
SECOND_TIME = "SECOND",
MINUTE_TIME = "MINUTE",
HOUR_TIME = "HOUR",
DAY_TIME = "DAY",

View File

@@ -46,6 +46,7 @@ vi.mock("@/utils/dateFormat", () => ({
describe("useDuration hook", () => {
const mockAppStore = {
utc: false,
coldStageMode: false,
} as unknown as ReturnType<typeof useAppStoreWithOut>;
beforeEach(() => {
@@ -66,7 +67,7 @@ describe("useDuration hook", () => {
setDurationRow(newDuration);
const result = getDurationTime();
expect(result.step).toBe("DAY");
expect(result.step).toBe("SECOND");
});
});
@@ -77,9 +78,10 @@ describe("useDuration hook", () => {
const result = getDurationTime();
expect(result).toEqual({
start: "2023-01-01",
end: "2023-01-01",
step: "HOUR",
start: "2023-01-01 00",
end: "2023-01-01 00",
step: "SECOND",
coldStage: false,
});
});
@@ -152,7 +154,7 @@ describe("useDuration hook", () => {
// Test getDurationTime
const durationTime = getDurationTime();
expect(durationTime.step).toBe("MINUTE");
expect(durationTime.step).toBe("SECOND");
// Test getMaxRange
const maxRange = getMaxRange(5);

View File

@@ -18,6 +18,7 @@ import { useAppStoreWithOut, InitializationDurationRow } from "@/store/modules/a
import type { Duration, DurationTime } from "@/types/app";
import getLocalTime from "@/utils/localtime";
import dateFormatStep from "@/utils/dateFormat";
import { TimeType } from "@/constants/data";
export function useDuration() {
let durationRow: Duration = InitializationDurationRow;
@@ -27,13 +28,14 @@ export function useDuration() {
return {
start: getLocalTime(appStore.utc, durationRow.start),
end: getLocalTime(appStore.utc, durationRow.end),
step: durationRow.step,
step: TimeType.SECOND_TIME,
coldStage: appStore.coldStageMode,
};
}
function getDurationTime(): DurationTime {
const appStore = useAppStoreWithOut();
const { start, step, end } = getDuration();
const { start, end } = getDuration();
const step = TimeType.SECOND_TIME;
return {
start: dateFormatStep(start, step, true),
end: dateFormatStep(end, step, true),
@@ -43,7 +45,7 @@ export function useDuration() {
}
function setDurationRow(data: Duration) {
const appStore = useAppStoreWithOut();
durationRow = { ...data, coldStage: appStore.coldStageMode };
durationRow = { ...data, coldStage: appStore.coldStageMode, step: TimeType.SECOND_TIME };
}
function getMaxRange(day: number) {
if (day === undefined || day === null) {

View File

@@ -105,6 +105,7 @@ limitations under the License. -->
import { EntityType, QueryOrders, Status } from "@/views/dashboard/data";
import type { LayoutConfig, FilterDuration } from "@/types/dashboard";
import { useDuration } from "@/hooks/useDuration";
import { TimeType } from "@/constants/data";
/*global defineProps, defineEmits, Recordable */
const emits = defineEmits(["get", "search"]);
@@ -126,7 +127,7 @@ limitations under the License. -->
const { duration: filtersDuration } = filters.value;
const duration = ref<DurationTime | FilterDuration>(
filtersDuration
? { start: filtersDuration.startTime || "", end: filtersDuration.endTime || "", step: filtersDuration.step || "" }
? { start: filtersDuration.startTime || "", end: filtersDuration.endTime || "", step: TimeType.SECOND_TIME }
: getDurationTime(),
);
const minTraceDuration = ref<number>();
@@ -152,7 +153,6 @@ limitations under the License. -->
}
async function init() {
duration.value = filters.value.duration || appStore.durationTime;
if (dashboardStore.entity === EntityType[1].value) {
await getServices();
}
@@ -335,7 +335,7 @@ limitations under the License. -->
? {
start: filtersDuration.startTime || "",
end: filtersDuration.endTime || "",
step: filtersDuration.step || "",
step: TimeType.SECOND_TIME,
}
: getDurationTime();
init();

View File

@@ -93,6 +93,8 @@ limitations under the License. -->
import { ElMessage } from "element-plus";
import { EntityType, QueryOrders, Status } from "@/views/dashboard/data";
import type { LayoutConfig } from "@/types/dashboard";
import { TimeType } from "@/constants/data";
import { useDuration } from "@/hooks/useDuration";
const FiltersKeys: { [key: string]: string } = {
status: "traceState",
@@ -130,10 +132,11 @@ limitations under the License. -->
const tagsMap = ref<Option[]>([]);
const traceId = ref<string>(filters.refId || "");
const { duration: filtersDuration } = props.data.filters || {};
const { getDurationTime } = useDuration();
const duration = ref<DurationTime>(
filtersDuration
? { start: filtersDuration.startTime || "", end: filtersDuration.endTime || "", step: filtersDuration.step || "" }
: appStore.durationTime,
? { start: filtersDuration.startTime || "", end: filtersDuration.endTime || "", step: TimeType.SECOND_TIME }
: getDurationTime(),
);
const state = reactive<Recordable>({
instance: "",