Skip to content

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

fix: sign-in frequency state update handler (#7296)

boojack79ca43783d09
diff --git a/frontend/src/components/GeneralSetting/SignInFrequencySetting.vue b/frontend/src/components/GeneralSetting/SignInFrequencySetting.vue
index a93e58a5f9..e57b83e0af 100644
--- a/frontend/src/components/GeneralSetting/SignInFrequencySetting.vue
+++ b/frontend/src/components/GeneralSetting/SignInFrequencySetting.vue
@@ -11,6 +11,7 @@
:disabled="!allowEdit"
:min="1"
:max="state.timeFormat === 'HOURS' ? 23 : undefined"
+ :precision="0"
/>
<NRadioGroup v-model:value="state.timeFormat" :disabled="!allowEdit">
<NRadio :value="'HOURS'" :label="'Hour(s)'" />
@@ -28,7 +29,7 @@
<script lang="ts" setup>
import { useDebounceFn } from "@vueuse/core";
-import { computed, reactive, onMounted, watch } from "vue";
+import { computed, reactive, watch } from "vue";
import { useI18n } from "vue-i18n";
import { NInputNumber, NRadioGroup, NRadio } from "naive-ui";
import { featureToRef, pushNotification, useCurrentUserV1 } from "@/store";
@@ -36,6 +37,25 @@ import { hasWorkspacePermissionV1 } from "@/utils";
import { FeatureType } from "@/types";
import { useSettingV1Store } from "@/store/modules/v1/setting";
+const getInitialState = (): LocalState => {
+ const defaultState: LocalState = {
+ inputValue: 7,
+ timeFormat: "DAYS",
+ };
+ const seconds =
+ settingV1Store.workspaceProfileSetting?.refreshTokenDuration?.seconds;
+ if (seconds && seconds > 0) {
+ if (seconds < 60 * 60 * 24) {
+ defaultState.inputValue = Math.floor(seconds / (60 * 60)) || 1;
+ defaultState.timeFormat = "HOURS";
+ } else {
+ defaultState.inputValue = Math.floor(seconds / (60 * 60 * 24)) || 1;
+ defaultState.timeFormat = "DAYS";
+ }
+ }
+ return defaultState;
+};
+
interface LocalState {
inputValue: number;
timeFormat: "HOURS" | "DAYS";
@@ -45,10 +65,7 @@ interface LocalState {
const { t } = useI18n();
const settingV1Store = useSettingV1Store();
const currentUserV1 = useCurrentUserV1();
-const state = reactive<LocalState>({
- inputValue: 7,
- timeFormat: "DAYS",
-});
+const state = reactive<LocalState>(getInitialState());
// TODO(steven): update feature name.
const hasSecureTokenFeature = featureToRef("bb.feature.secure-token");
@@ -60,20 +77,6 @@ const allowEdit = computed((): boolean => {
);
});
-onMounted(() => {
- const seconds =
- settingV1Store.workspaceProfileSetting?.refreshTokenDuration?.seconds;
- if (seconds && seconds > 0) {
- if (seconds < 60 * 60 * 24) {
- state.inputValue = Math.floor(seconds / (60 * 60)) || 1;
- state.timeFormat = "HOURS";
- } else {
- state.inputValue = Math.floor(seconds / (60 * 60 * 24)) || 1;
- state.timeFormat = "DAYS";
- }
- }
-});
-
const handleFrequencySettingChange = useDebounceFn(async () => {
if (!hasSecureTokenFeature.value) {
state.featureNameForModal = "bb.feature.secure-token";
@@ -94,6 +97,15 @@ const handleFrequencySettingChange = useDebounceFn(async () => {
});
}, 2000);
+watch(
+ () => [state.timeFormat],
+ () => {
+ if (state.timeFormat === "HOURS" && state.inputValue > 23) {
+ state.inputValue = 23;
+ }
+ }
+);
+
watch(
() => [state.inputValue, state.timeFormat],
() => {