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: extract expiration selector (#7451)
boojack2b4cc616792d
diff --git a/frontend/src/components/ExpirationSelector.vue b/frontend/src/components/ExpirationSelector.vuenew file mode 100644index 0000000000..6345790fbb--- /dev/null+++ b/frontend/src/components/ExpirationSelector.vue@@ -0,0 +1,67 @@+<template>+ <NRadioGroup+ v-bind="$attrs"+ v-model:value="state.value"+ class="w-full !grid grid-cols-3 gap-2"+ name="radiogroup"+ >+ <div+ v-for="option in options"+ :key="option.value"+ class="col-span-1 h-8 flex flex-row justify-start items-center"+ >+ <NRadio :value="option.value" :label="option.label" />+ </div>+ <div class="col-span-2 flex flex-row justify-start items-center">+ <NRadio :value="-1" :label="$t('issue.grant-request.customize')" />+ <NInputNumber+ v-model:value="state.customValue"+ class="!w-24 ml-2"+ :disabled="!useCustom"+ :min="1"+ :show-button="false"+ :placeholder="''"+ >+ <template #suffix>{{ $t("common.date.days") }}</template>+ </NInputNumber>+ </div>+ </NRadioGroup>+</template>++<script lang="ts" setup>+import { NRadio, NRadioGroup, NInputNumber } from "naive-ui";+import { computed, reactive, watch } from "vue";++interface ExpirationOption {+ value: number;+ label: string;+}++interface LocalState {+ value: number;+ customValue: number;+}++const props = defineProps<{+ options: ExpirationOption[];+ value: number;+}>();++const emit = defineEmits<{+ (event: "update", value: number): void;+}>();++const state = reactive<LocalState>({+ value: props.value,+ customValue: props.value,+});++const useCustom = computed(() => state.value === -1);++watch(+ () => [state.value, state.customValue],+ () => {+ emit("update", useCustom.value ? state.customValue : state.value);+ }+);+</script>diff --git a/frontend/src/components/Issue/panel/RequestExportPanel/index.vue b/frontend/src/components/Issue/panel/RequestExportPanel/index.vueindex f65f72bf07..f2ccacb27f 100644--- a/frontend/src/components/Issue/panel/RequestExportPanel/index.vue+++ b/frontend/src/components/Issue/panel/RequestExportPanel/index.vue@@ -142,40 +142,14 @@</div><div class="w-full flex flex-col justify-start items-start"><span class="flex items-start textlabel mb-2">- {{ $t("issue.grant-request.expire-days") }}+ {{ $t("common.expiration") }}<RequiredStar /></span>- <div>- <NRadioGroup- v-model:value="state.expireDays"- class="!grid grid-cols-6 gap-4"- name="radiogroup"- >- <div- v-for="day in expireDaysOptions"- :key="day.value"- class="col-span-1 flex flex-row justify-start items-center"- >- <NRadio :value="day.value" :label="day.label" />- </div>- <div class="col-span-2 flex flex-row justify-start items-center">- <NRadio- :value="-1"- :label="$t('issue.grant-request.customize')"- />- <NInputNumber- v-model:value="state.customDays"- class="!w-24 ml-2"- :disabled="state.expireDays !== -1"- :min="1"- :show-button="false"- :placeholder="''"- >- <template #suffix>{{ $t("common.date.days") }}</template>- </NInputNumber>- </div>- </NRadioGroup>- </div>+ <ExpirationSelector+ class="grid-cols-6"+ :options="expireDaysOptions"+ :value="state.expireDays"+ /></div><div class="w-full flex flex-col justify-start items-start"><span class="flex items-center textlabel mb-2">{{@@ -211,7 +185,6 @@ import {NDrawerContent,NRadioGroup,NRadio,- NInputNumber,NInput,NTooltip,} from "naive-ui";@@ -248,13 +221,13 @@ import { useRouter } from "vue-router";import SelectTableForm from "./SelectTableForm/index.vue";import dayjs from "dayjs";import { stringifyDatabaseResources } from "@/utils/issue/cel";+import ExpirationSelector from "@/components/ExpirationSelector.vue";interface LocalState {projectId?: string;environmentId?: string;databaseId?: string;expireDays: number;- customDays: number;maxRowCount: number;exportMethod: "SQL" | "DATABASE";exportFormat: "CSV" | "JSON" | "SQL" | "XLSX";@@ -277,7 +250,6 @@ const currentUser = useCurrentUserV1();const databaseStore = useDatabaseV1Store();const state = reactive<LocalState>({expireDays: 1,- customDays: 7,maxRowCount: 1000,exportMethod: "SQL",exportFormat: "CSV",@@ -418,8 +390,7 @@ const doCreateIssue = async () => {}const expression: string[] = [];- const expireDays =- state.expireDays === -1 ? state.customDays : state.expireDays;+ const expireDays = state.expireDays;expression.push(`request.time < timestamp("${dayjs().add(expireDays, "days")diff --git a/frontend/src/components/Issue/panel/RequestQueryPanel/index.vue b/frontend/src/components/Issue/panel/RequestQueryPanel/index.vueindex 8f8260a629..c75d4b9312 100644--- a/frontend/src/components/Issue/panel/RequestQueryPanel/index.vue+++ b/frontend/src/components/Issue/panel/RequestQueryPanel/index.vue@@ -67,40 +67,14 @@</div><div class="w-full flex flex-col justify-start items-start"><span class="flex items-start textlabel mb-4">- {{ $t("issue.grant-request.expire-days") }}+ {{ $t("common.expiration") }}<RequiredStar /></span>- <div>- <NRadioGroup- v-model:value="state.expireDays"- class="!grid grid-cols-4 gap-4"- name="radiogroup"- >- <div- v-for="day in expireDaysOptions"- :key="day.value"- class="col-span-1 flex flex-row justify-start items-center"- >- <NRadio :value="day.value" :label="day.label" />- </div>- <div class="col-span-2 flex flex-row justify-start items-center">- <NRadio- :value="-1"- :label="$t('issue.grant-request.customize')"- />- <NInputNumber- v-model:value="state.customDays"- class="!w-24 ml-2"- :disabled="state.expireDays !== -1"- :min="1"- :show-button="false"- :placeholder="''"- >- <template #suffix>{{ $t("common.date.days") }}</template>- </NInputNumber>- </div>- </NRadioGroup>- </div>+ <ExpirationSelector+ class="grid-cols-4"+ :options="expireDaysOptions"+ :value="state.expireDays"+ /></div><div class="w-full flex flex-col justify-start items-start"><span class="flex items-center textlabel mb-2">{{@@ -136,7 +110,6 @@ import {NDrawerContent,NRadioGroup,NRadio,- NInputNumber,NInput,NTooltip,} from "naive-ui";@@ -163,13 +136,13 @@ import { useRouter } from "vue-router";import dayjs from "dayjs";import { stringifyDatabaseResources } from "@/utils/issue/cel";import SelectDatabaseResourceForm from "./SelectDatabaseResourceForm/index.vue";+import ExpirationSelector from "@/components/ExpirationSelector.vue";interface LocalState {projectId?: string;allDatabases: boolean;selectedDatabaseResourceList: DatabaseResource[];expireDays: number;- customDays: number;description: string;}@@ -211,7 +184,6 @@ const state = reactive<LocalState>({projectId: props.projectId,...extractDatabaseResourceFromProps(),expireDays: 7,- customDays: 365,description: "",});@@ -293,8 +265,7 @@ const doCreateIssue = async () => {}const expression: string[] = [];- const expireDays =- state.expireDays === -1 ? state.customDays : state.expireDays;+ const expireDays = state.expireDays;expression.push(`request.time < timestamp("${dayjs().add(expireDays, "days")diff --git a/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue b/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vueindex 7e9fbe0398..49091a1503 100644--- a/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue+++ b/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue@@ -24,34 +24,12 @@</div><div class="w-full"><span>{{ $t("common.expiration") }}</span>- <div class="w-full mt-2">- <NRadioGroup- v-model:value="state.expireDays"- class="w-full !grid grid-cols-3 gap-2"- name="radiogroup"- >- <div- v-for="day in expireDaysOptions"- :key="day.value"- class="col-span-1 h-8 flex flex-row justify-start items-center"- >- <NRadio :value="day.value" :label="day.label" />- </div>- <div class="col-span-2 flex flex-row justify-start items-center">- <NRadio :value="-1" :label="$t('issue.grant-request.customize')" />- <NInputNumber- v-model:value="state.customDays"- class="!w-24 ml-2"- :disabled="state.expireDays !== -1"- :min="1"- :show-button="false"- :placeholder="''"- >- <template #suffix>{{ $t("common.date.days") }}</template>- </NInputNumber>- </div>- </NRadioGroup>- </div>+ <ExpirationSelector+ class="mt-2"+ :options="expireDaysOptions"+ :value="state.expireDays"+ @update="state.expireDays = $event"+ /></div></div></template>@@ -60,7 +38,6 @@/* eslint-disable vue/no-mutating-props */import dayjs from "dayjs";-import { NRadio, NRadioGroup, NInputNumber } from "naive-ui";import { computed, reactive, watch } from "vue";import { useI18n } from "vue-i18n";import { useUserStore } from "@/store";@@ -68,6 +45,7 @@ import { ComposedProject } from "@/types";import { Binding } from "@/types/proto/v1/iam_policy";import { Expr } from "@/types/proto/google/type/expr";import ProjectMemberRoleSelect from "@/components/v2/Select/ProjectMemberRoleSelect.vue";+import ExpirationSelector from "@/components/ExpirationSelector.vue";const props = defineProps<{project: ComposedProject;@@ -83,15 +61,13 @@ interface LocalState {userUidList: string[];role?: string;expireDays: number;- customDays: number;}const { t } = useI18n();const userStore = useUserStore();const state = reactive<LocalState>({userUidList: [],- expireDays: 0,- customDays: 7,+ expireDays: 7,});const expireDaysOptions = computed(() => [@@ -113,11 +89,11 @@ const expireDaysOptions = computed(() => [},{value: 180,- label: t("common.date.days", { days: 180 }),+ label: t("common.date.months", { months: 6 }),},{value: 365,- label: t("common.date.days", { days: 365 }),+ label: t("common.date.years", { years: 1 }),},{value: 0,@@ -140,10 +116,7 @@ watch(if (state.expireDays === 0) {props.binding.condition = undefined;} else {- let days = state.expireDays;- if (state.expireDays === -1) {- days = state.customDays;- }+ const days = state.expireDays;props.binding.condition = Expr.create({expression: `request.time < timestamp("${dayjs().add(days, "days")diff --git a/frontend/src/components/v2/Select/ProjectMemberRoleSelect.vue b/frontend/src/components/v2/Select/ProjectMemberRoleSelect.vueindex 3aae019af0..18c1e91c70 100644--- a/frontend/src/components/v2/Select/ProjectMemberRoleSelect.vue+++ b/frontend/src/components/v2/Select/ProjectMemberRoleSelect.vue@@ -1,11 +1,11 @@<template><NSelect+ v-bind="$attrs":value="role":options="roleOptions":max-tag-count="'responsive'":placeholder="'Select role'":render-label="renderLabel"- v-bind="$attrs"@update:value="changeRole"/><FeatureModal@@ -16,7 +16,7 @@</template><script setup lang="ts">-import { computed, defineComponent, h, ref } from "vue";+import { computed, h, ref } from "vue";import { type SelectOption, NSelect } from "naive-ui";import { featureToRef, useRoleStore } from "@/store";@@ -32,24 +32,23 @@ type ProjectRoleSelectOption = SelectOption & {};defineProps<{- role: ProjectRoleType;+ role?: ProjectRoleType;}>();const emit = defineEmits<{(event: "update:role", role: ProjectRoleType): void;}>();-const FREE_ROLE_LIST = [PresetRoleType.OWNER, PresetRoleType.DEVELOPER];+const FREE_ROLE_LIST = [+ PresetRoleType.OWNER,+ PresetRoleType.DEVELOPER,+ PresetRoleType.QUERIER,+ PresetRoleType.EXPORTER,+];const hasCustomRoleFeature = featureToRef("bb.feature.custom-role");const showFeatureModal = ref(false);const roleList = computed(() => {const roleList = useRoleStore().roleList;- // For enterprise plan, we don't allow to add exporter role.- if (hasCustomRoleFeature.value) {- return roleList.filter((role) => {- return role.name !== PresetRoleType.EXPORTER;- });- }return roleList;});@@ -98,9 +97,3 @@ const changeRole = (value: string) => {emit("update:role", value);};</script>--<script lang="ts">-defineComponent({- inheritAttrs: false,-});-</script>