Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: improve expiration time selection UI (#16505)
Danny Xu87058063df90
diff --git a/frontend/src/components/ExpirationSelector.vue b/frontend/src/components/ExpirationSelector.vueindex 69cdeca236..4e29e61062 100644--- a/frontend/src/components/ExpirationSelector.vue+++ b/frontend/src/components/ExpirationSelector.vue@@ -1,62 +1,49 @@<template>- <NRadioGroup- v-bind="$attrs"- :value="state.selected"- class="w-full !grid grid-cols-3 gap-2"- name="radiogroup"- @update:value="onSelect"- >- <div- v-for="option in options"- :key="option.value"- :class="[- 'col-span-1 h-8 flex flex-row justify-start items-center',- option.value === -2 ? 'col-span-2' : '',- option.value === -1 ? 'col-span-3' : '',- ]"- >- <NRadio :value="option.value" :label="option.label" />- <template v-if="option.value === -2">- <NInputNumber- size="small"- style="width: 5rem"- :min="1"- :max="maximumRoleExpiration"- :placeholder="$t('common.date.days')"- :disabled="state.selected !== -2"- :value="customExpirationDays"- @update:value="handleCustomExpirationDaysChange"- />- <span class="ml-2">{{ $t("common.date.days") }}</span>- </template>- <template v-else-if="option.value === -1">+ <div class="w-full space-y-3">+ <NSelect+ v-bind="$attrs"+ :value="state.selected"+ :options="selectOptions"+ @update:value="onSelect"+ />++ <template v-if="state.selected === -1">+ <div class="space-y-2"><NDatePicker- size="small"- :value="- state.selected === -1 ? state.expirationTimestampInMS : undefined- "- :disabled="state.selected !== -1"+ size="medium"+ class="w-full"+ :value="state.expirationTimestampInMS":actions="null":update-value-on-close="true"type="datetime":is-date-disabled="isDateDisabled"clearable- @update:value="(val) => (state.expirationTimestampInMS = val)"+ :placeholder="$t('issue.grant-request.custom-date-placeholder')"+ @update:value="handleCustomDateChange"/>- <span v-if="maximumRoleExpiration" class="ml-3 textinfolabel">+ <div v-if="maximumRoleExpiration" class="text-xs text-gray-500">{{ $t("settings.general.workspace.maximum-role-expiration.self") }}:{{ $t("common.date.days", { days: maximumRoleExpiration }) }}+ </div>+ </div>+ </template>++ <div v-if="state.expirationTimestampInMS && state.selected !== -1" class="p-3 bg-gray-50 rounded-md">+ <div class="text-sm text-gray-600">+ {{ $t("common.access-expires") }}:+ <span class="font-medium text-gray-900">+ {{ formatExpirationDisplay(state.expirationTimestampInMS) }}</span>- </template>+ </div></div>- </NRadioGroup>+ </div></template><script lang="ts" setup>import { useLocalStorage } from "@vueuse/core";import dayjs from "dayjs";-import { NRadio, NRadioGroup, NDatePicker, NInputNumber } from "naive-ui";-import { computed, reactive, watch, watchEffect } from "vue";+import { NSelect, NDatePicker } from "naive-ui";+import { computed, reactive, watch } from "vue";import { useI18n } from "vue-i18n";import { useSettingV1Store } from "@/store";import { PresetRoleType } from "@/types";@@ -83,21 +70,29 @@ const emit = defineEmits<{const { t } = useI18n();const settingV1Store = useSettingV1Store();-const state = reactive<LocalState>({- selected: props.timestampInMs === undefined ? 0 : -1,-});-const customExpirationDays = useLocalStorage(- "bb.roles.custom-expiration-days",- 1+// Remember the last selected expiration option+const lastSelectedExpiration = useLocalStorage<number>(+ "bb.roles.last-expiration-selection",+ 7 // Default to 1 week);-const handleCustomExpirationDaysChange = (val: number | null) => {- if (!val) {- return;+// Initialize state with intelligent defaults+const getInitialSelection = () => {+ if (props.timestampInMs !== undefined) {+ // If timestamp is provided, use custom date+ return -1;}- state.expirationTimestampInMS =- new Date().getTime() + val * 24 * 60 * 60 * 1000;- customExpirationDays.value = val;+ // Otherwise, use the last selected value if it's still valid+ return lastSelectedExpiration.value;+};++const state = reactive<LocalState>({+ selected: getInitialSelection(),+ expirationTimestampInMS: props.timestampInMs,+});++const handleCustomDateChange = (val: number | null) => {+ state.expirationTimestampInMS = val || undefined;};const maximumRoleExpiration = computed(() => {@@ -112,14 +107,9 @@ const maximumRoleExpiration = computed(() => {return Math.floor(seconds / (60 * 60 * 24));});-watchEffect(() => {- if (!maximumRoleExpiration.value) {- return;- }- if (maximumRoleExpiration.value < customExpirationDays.value) {- customExpirationDays.value = maximumRoleExpiration.value;- }-});+const formatExpirationDisplay = (timestampMs: number) => {+ return dayjs(timestampMs).format("YYYY-MM-DD HH:mm:ss");+};const isDateDisabled = (date: number) => {if (date < dayjs().startOf("day").valueOf()) {@@ -132,7 +122,7 @@ const isDateDisabled = (date: number) => {};const options = computed((): ExpirationOption[] => {- let options = [+ const baseOptions = [{value: 1,label: t("common.date.days", { days: 1 }),@@ -141,47 +131,76 @@ const options = computed((): ExpirationOption[] => {value: 3,label: t("common.date.days", { days: 3 }),},+ {+ value: 7,+ label: t("common.date.week", { weeks: 1 }),+ },{value: 30,- label: t("common.date.days", { days: 30 }),+ label: t("common.date.month", { months: 1 }),},{value: 90,- label: t("common.date.days", { days: 90 }),+ label: t("common.date.months", { months: 3 }),+ },+ {+ value: 180,+ label: t("common.date.months", { months: 6 }),+ },+ {+ value: 365,+ label: t("common.date.year", { years: 1 }),},];- if (maximumRoleExpiration.value) {- options = options.filter(- (option) => option.value < maximumRoleExpiration.value!- );- options.push({- value: maximumRoleExpiration.value,- label: t("common.date.days", { days: maximumRoleExpiration.value }),- });- } else {- options.push({++ const availableOptions: ExpirationOption[] = [];++ // Add "Never expires" at the top if no maximum role expiration is set+ if (!maximumRoleExpiration.value) {+ availableOptions.push({value: 0,label: t("project.members.never-expires"),});}- options.push(- {- value: -2,- label: t("issue.grant-request.custom"),- },- {- value: -1,- label: t("issue.grant-request.custom"),- }- );- return options;++ // Add custom date option prominently after "Never expires"+ availableOptions.push({+ value: -1,+ label: t("issue.grant-request.custom-date"),+ });++ // Add time-based options+ if (maximumRoleExpiration.value) {+ availableOptions.push(...baseOptions.filter(+ (option) => option.value <= maximumRoleExpiration.value!+ ));+ } else {+ availableOptions.push(...baseOptions);+ }++ return availableOptions;+});++const selectOptions = computed(() => {+ return options.value.map((option) => ({+ label: option.label,+ value: option.value,+ }));});const onSelect = (value: number) => {if (value > 0) {state.expirationTimestampInMS =new Date().getTime() + value * 24 * 60 * 60 * 1000;+ // Save preset selections to localStorage+ lastSelectedExpiration.value = value;+ } else if (value === 0) {+ // Never expires - clear the timestamp+ state.expirationTimestampInMS = undefined;+ lastSelectedExpiration.value = value;}+ // For value === -1 (custom date), the timestamp is set by the date picker+ // Don't save custom date selection as it's not reusablestate.selected = value;};diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 3ee4a4186a..ef96786039 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -180,8 +180,13 @@"optional": "Optional","reason": "Reason","date": {- "days": "{days} days"+ "days": "{days} days",+ "week": "1 week",+ "month": "1 month",+ "months": "{months} months",+ "year": "1 year"},+ "access-expires": "Access Expires","expiration": "Expiration","configure": "Configure","groups": "Groups",@@ -907,7 +912,8 @@"all-databases": "All","all-databases-tip": "All current and future databases in this project.","manually-select": "Manually select",- "custom": "Custom"+ "custom-date": "Custom date",+ "custom-date-placeholder": "Select expiration date and time"},"review-sent-back": "Review sent back","update-statement": {diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex da10e09497..31467d7ebe 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -180,8 +180,13 @@"optional": "Opcional","reason": "Razón","date": {- "days": "{days} días"+ "days": "{days} días",+ "week": "1 semana",+ "month": "1 mes",+ "months": "{months} meses",+ "year": "1 año"},+ "access-expires": "El acceso expira","expiration": "Expiración","configure": "Configurar","groups": "Grupos",@@ -907,7 +912,8 @@"all-databases": "todas las bases de datos","all-databases-tip": "Todas las bases de datos actuales y futuras de este proyecto.","manually-select": "selección manual",- "custom": "personalice"+ "custom-date-placeholder": "Seleccione la fecha y hora de vencimiento",+ "custom-date": "Fecha personalizada"},"review-sent-back": "Revisión devuelta","update-statement": {@@ -2746,4 +2752,4 @@"last-visit": "Última visita","changelog-for-version": "Registro de cambios para {version}"}-}\ No newline at end of file+}diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex 49e4204731..2520850e5b 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -180,8 +180,13 @@"optional": "オプション","reason": "理由","date": {- "days": "{days} 日"+ "days": "{days} 日",+ "week": "1 週間",+ "month": "1 か月",+ "months": "{months} 月",+ "year": "1 年"},+ "access-expires": "アクセスは期限切れです","expiration": "有効期限","configure": "設定","groups": "グループ",@@ -907,7 +912,8 @@"all-databases": "すべてのデータベース","all-databases-tip": "このプロジェクトに属する現在および将来のすべてのデータベース。","manually-select": "手動選択",- "custom": "カスタマイズ"+ "custom-date-placeholder": "有効期限と時刻を選択します",+ "custom-date": "カスタム日付"},"review-sent-back": "レビューが返されました","update-statement": {@@ -2746,4 +2752,4 @@"last-visit": "最終訪問","changelog-for-version": "{version} の変更履歴"}-}\ No newline at end of file+}diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.jsonindex aa51ec6600..4a3015a382 100644--- a/frontend/src/locales/vi-VN.json+++ b/frontend/src/locales/vi-VN.json@@ -180,8 +180,13 @@"optional": "Tùy chọn","reason": "Lý do","date": {- "days": "{days} ngày"+ "days": "{days} ngày",+ "week": "1 tuần",+ "month": "1 tháng",+ "months": "{months} tháng",+ "year": "1 năm"},+ "access-expires": "Truy cập hết hạn","expiration": "Hết hạn","configure": "Cấu hình","groups": "Nhóm",@@ -907,7 +912,8 @@"all-databases": "Tất cả","all-databases-tip": "Tất cả cơ sở dữ liệu hiện tại và tương lai trong dự án này.","manually-select": "Chọn thủ công",- "custom": "Tùy chỉnh"+ "custom-date-placeholder": "Chọn ngày và giờ hết hạn",+ "custom-date": "Ngày tùy chỉnh"},"review-sent-back": "Đánh giá đã gửi lại","update-statement": {@@ -2746,4 +2752,4 @@"last-visit": "Lần truy cập cuối","changelog-for-version": "Nhật ký thay đổi cho phiên bản {version}"}-}\ No newline at end of file+}diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 743718a52e..fac8046491 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -180,8 +180,13 @@"optional": "可选","reason": "理由","date": {- "days": "{days} 天"+ "days": "{days} 天",+ "week": "1 周",+ "month": "1 个月",+ "months": "{months} 个月",+ "year": "1 年"},+ "access-expires": "访问到期","expiration": "过期时间","configure": "配置","groups": "分组",@@ -907,7 +912,8 @@"all-databases": "所有数据库","all-databases-tip": "所有当前和未来属于这个项目的数据库。","manually-select": "手动选择",- "custom": "自定义"+ "custom-date-placeholder": "选择到期日期和时间",+ "custom-date": "自定义日期"},"review-sent-back": "审核被退回","update-statement": {@@ -2746,4 +2752,4 @@"last-visit": "上次访问","changelog-for-version": "{version} 的更新日志"}-}\ No newline at end of file+}