Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: unify timestamp display (#16924)

boojackb08092671823
diff --git a/frontend/src/components/Plan/components/PlanDataTable/PlanDataTable.vue b/frontend/src/components/Plan/components/PlanDataTable/PlanDataTable.vue
index c298def91b..5af8f9bd90 100644
--- a/frontend/src/components/Plan/components/PlanDataTable/PlanDataTable.vue
+++ b/frontend/src/components/Plan/components/PlanDataTable/PlanDataTable.vue
@@ -19,17 +19,14 @@ import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import { BBAvatar } from "@/bbkit";
+import Timestamp from "@/components/misc/Timestamp.vue";
import { useIssueLayoutVersion } from "@/composables/useIssueLayoutVersion";
import { PROJECT_V1_ROUTE_PLAN_DETAIL } from "@/router/dashboard/projectV1";
import { useUserStore } from "@/store";
-import { getTimeForPbTimestampProtoEs, unknownUser } from "@/types";
+import { unknownUser } from "@/types";
import { State } from "@/types/proto-es/v1/common_pb";
import type { Plan } from "@/types/proto-es/v1/plan_service_pb";
-import {
- extractPlanUID,
- extractProjectResourceName,
- humanizeTs,
-} from "@/utils";
+import { extractPlanUID, extractProjectResourceName } from "@/utils";
import PlanCheckRunStatusIcon from "../PlanCheckRunStatusIcon.vue";
withDefaults(
@@ -99,8 +96,7 @@ const columnList = computed((): DataTableColumn<Plan>[] => {
key: "updateTime",
title: t("issue.table.updated"),
width: 128,
- render: (plan) =>
- humanizeTs(getTimeForPbTimestampProtoEs(plan.updateTime, 0) / 1000),
+ render: (plan) => <Timestamp timestamp={plan.updateTime} />,
},
{
key: "creator",
diff --git a/frontend/src/components/Plan/components/RolloutView/TaskTable.vue b/frontend/src/components/Plan/components/RolloutView/TaskTable.vue
index d395cced40..bac8f85708 100644
--- a/frontend/src/components/Plan/components/RolloutView/TaskTable.vue
+++ b/frontend/src/components/Plan/components/RolloutView/TaskTable.vue
@@ -26,6 +26,7 @@ import { useRouter } from "vue-router";
import { semanticTaskType } from "@/components/IssueV1";
import DatabaseDisplay from "@/components/Plan/components/common/DatabaseDisplay.vue";
import TaskStatus from "@/components/Rollout/kits/TaskStatus.vue";
+import Timestamp from "@/components/misc/Timestamp.vue";
import { PROJECT_V1_ROUTE_ROLLOUT_DETAIL_TASK_DETAIL } from "@/router/dashboard/projectV1";
import { useCurrentProjectV1, batchGetOrFetchDatabases } from "@/store";
import { getTimeForPbTimestampProtoEs } from "@/types";
@@ -240,14 +241,7 @@ const columnList = computed((): DataTableColumn<Task>[] => {
key: "updateTime",
title: t("common.updated-at"),
width: 128,
- render: (task) => {
- if (!task.updateTime) {
- return "-";
- }
- return humanizeTs(
- getTimeForPbTimestampProtoEs(task.updateTime, 0) / 1000
- );
- },
+ render: (task) => <Timestamp timestamp={task.updateTime} />,
},
];
});
diff --git a/frontend/src/components/Rollout/RolloutDataTable.vue b/frontend/src/components/Rollout/RolloutDataTable.vue
index aaf6cd9da7..8bf13e1a6c 100644
--- a/frontend/src/components/Rollout/RolloutDataTable.vue
+++ b/frontend/src/components/Rollout/RolloutDataTable.vue
@@ -20,15 +20,11 @@ import { useRouter } from "vue-router";
import { BBAvatar } from "@/bbkit";
import { TASK_STATUS_FILTERS } from "@/components/Plan/constants/task";
import TaskStatus from "@/components/Rollout/kits/TaskStatus.vue";
+import Timestamp from "@/components/misc/Timestamp.vue";
import { useEnvironmentV1Store, useUserStore } from "@/store";
-import {
- getTimeForPbTimestampProtoEs,
- unknownUser,
- type ComposedRollout,
-} from "@/types";
+import { unknownUser, type ComposedRollout } from "@/types";
import type { Task_Status } from "@/types/proto-es/v1/rollout_service_pb";
import {
- humanizeTs,
stringifyTaskStatus,
getStageStatus,
extractRolloutUID,
@@ -160,10 +156,7 @@ const columnList = computed(
key: "updateTime",
title: t("common.updated-at"),
width: 128,
- render: (rollout) =>
- humanizeTs(
- getTimeForPbTimestampProtoEs(rollout.updateTime, 0) / 1000
- ),
+ render: (rollout) => <Timestamp timestamp={rollout.updateTime} />,
},
{
key: "creator",
diff --git a/frontend/src/components/misc/Timestamp.vue b/frontend/src/components/misc/Timestamp.vue
new file mode 100644
index 0000000000..939c75f82c
--- /dev/null
+++ b/frontend/src/components/misc/Timestamp.vue
@@ -0,0 +1,72 @@
+<template>
+ <NTooltip v-if="hasValidTimestamp" :disabled="!showTooltip">
+ <template #trigger>
+ <span class="text-sm text-control-light" :class="customClass">
+ {{ humanizedTime }}
+ </span>
+ </template>
+ <template #default>
+ <div class="text-sm whitespace-nowrap">
+ {{ fullDateTime }}
+ </div>
+ </template>
+ </NTooltip>
+ <span v-else class="text-sm text-control-light" :class="customClass">
+ {{ fallbackText }}
+ </span>
+</template>
+
+<script setup lang="ts">
+import type { Timestamp } from "@bufbuild/protobuf/wkt";
+import dayjs from "dayjs";
+import timezone from "dayjs/plugin/timezone";
+import { NTooltip } from "naive-ui";
+import { computed } from "vue";
+import { getTimeForPbTimestampProtoEs } from "@/types/timestamp";
+import { humanizeTs } from "@/utils/util";
+
+dayjs.extend(timezone);
+
+interface Props {
+ timestamp?: Timestamp;
+ fallbackText?: string;
+ showTooltip?: boolean;
+ customClass?: string;
+}
+
+const props = withDefaults(defineProps<Props>(), {
+ fallbackText: "-",
+ showTooltip: true,
+ customClass: "",
+});
+
+// Check if we have a valid timestamp
+const hasValidTimestamp = computed(() => {
+ return props.timestamp && (props.timestamp.seconds || props.timestamp.nanos);
+});
+
+// Get timestamp in milliseconds
+const timestampInMilliseconds = computed(() => {
+ if (!hasValidTimestamp.value) return null;
+ return getTimeForPbTimestampProtoEs(props.timestamp, 0);
+});
+
+// Convert to seconds for humanizeTs
+const timestampInSeconds = computed(() => {
+ if (!timestampInMilliseconds.value) return null;
+ return Math.floor(timestampInMilliseconds.value / 1000);
+});
+
+// Humanized time using the existing humanizeTs function
+const humanizedTime = computed(() => {
+ if (!timestampInSeconds.value) return props.fallbackText;
+ return humanizeTs(timestampInSeconds.value);
+});
+
+const fullDateTime = computed(() => {
+ if (!timestampInMilliseconds.value) return "";
+
+ const date = dayjs(timestampInMilliseconds.value);
+ return date.local().format();
+});
+</script>