Skip to content

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

chore: add expired time field to exporter form (#6459)

boojack116db40bac09
diff --git a/frontend/src/components/Issue/form/GrantRequestExporterForm.vue b/frontend/src/components/Issue/form/GrantRequestExporterForm.vue
index 116b2a3234..5c040595e9 100644
--- a/frontend/src/components/Issue/form/GrantRequestExporterForm.vue
+++ b/frontend/src/components/Issue/form/GrantRequestExporterForm.vue
@@ -60,6 +60,47 @@
{{ selectedDatabase.databaseName }}
</div>
</div>
+ <div class="w-full flex flex-row justify-start items-start">
+ <span class="flex w-40 items-start textlabel !leading-6">
+ {{
+ create
+ ? $t("issue.grant-request.expire-days")
+ : $t("issue.grant-request.expired-at")
+ }}
+ <RequiredStar />
+ </span>
+ <div v-if="create">
+ <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>
+ <div v-else>
+ {{ state.expiredAt }}
+ </div>
+ </div>
<div class="w-full flex flex-row justify-start items-center">
<span class="flex w-40 items-center textlabel !leading-6">
{{ $t("issue.grant-request.export-rows") }}
@@ -114,7 +155,9 @@
<script lang="ts" setup>
import { head } from "lodash-es";
+import { NRadioGroup, NRadio, NInputNumber } from "naive-ui";
import { computed, onMounted, reactive, watch } from "vue";
+import { useI18n } from "vue-i18n";
import { useIssueLogic } from "../logic";
import {
GrantRequestContext,
@@ -142,18 +185,26 @@ interface LocalState {
environmentId?: string;
databaseId?: string;
selectedDatabaseResourceList: DatabaseResource[];
+ expireDays: number;
+ customDays: number;
maxRowCount: number;
exportFormat: "CSV" | "JSON";
statement: string;
+ // For reviewing
+ expiredAt: string;
}
+const { t } = useI18n();
const { create, issue } = useIssueLogic();
const databaseStore = useDatabaseV1Store();
const state = reactive<LocalState>({
selectedDatabaseResourceList: [],
+ expireDays: 1,
+ customDays: 7,
maxRowCount: 1000,
exportFormat: "CSV",
statement: "",
+ expiredAt: "",
});
const projectId = computed(() => {
@@ -167,6 +218,25 @@ const selectedDatabase = computed(() => {
return databaseStore.getDatabaseByUID(state.databaseId);
});
+const expireDaysOptions = computed(() => [
+ {
+ value: 1,
+ label: t("common.date.days", { days: 1 }),
+ },
+ {
+ value: 3,
+ label: t("common.date.days", { days: 3 }),
+ },
+ {
+ value: 7,
+ label: t("common.date.days", { days: 7 }),
+ },
+ {
+ value: 15,
+ label: t("common.date.days", { days: 15 }),
+ },
+]);
+
const dialect = computed((): SQLDialect => {
const db = selectedDatabase.value;
return dialectOfEngineV1(db?.instanceEntity.engine ?? Engine.MYSQL);
@@ -236,6 +306,8 @@ watch(
() => [
state.databaseId,
state.selectedDatabaseResourceList,
+ state.expireDays,
+ state.customDays,
state.maxRowCount,
state.exportFormat,
state.statement,
@@ -254,6 +326,11 @@ watch(
} else {
context.databaseResources = [];
}
+ if (state.expireDays === -1) {
+ context.expireDays = state.customDays;
+ } else {
+ context.expireDays = state.expireDays;
+ }
context.maxRowCount = state.maxRowCount;
context.exportFormat = state.exportFormat;
context.statement = state.statement;
@@ -286,6 +363,13 @@ watch(
state.databaseId = String(resource.databaseId);
}
}
+ if (conditionExpression.expiredTime !== undefined) {
+ state.expiredAt = new Date(
+ conditionExpression.expiredTime
+ ).toLocaleString();
+ } else {
+ state.expiredAt = "-";
+ }
if (conditionExpression.statement !== undefined) {
state.statement = conditionExpression.statement;
}
diff --git a/frontend/src/components/Issue/form/GrantRequestQuerierForm.vue b/frontend/src/components/Issue/form/GrantRequestQuerierForm.vue
index e6aff150af..a832f07a30 100644
--- a/frontend/src/components/Issue/form/GrantRequestQuerierForm.vue
+++ b/frontend/src/components/Issue/form/GrantRequestQuerierForm.vue
@@ -279,14 +279,12 @@ watch(
() => [state.expireDays, state.customDays],
() => {
if (create.value) {
+ const context = (issue.value as IssueCreate)
+ .createContext as GrantRequestContext;
if (state.expireDays === -1) {
- (
- (issue.value as IssueCreate).createContext as GrantRequestContext
- ).expireDays = state.customDays;
+ context.expireDays = state.customDays;
} else {
- (
- (issue.value as IssueCreate).createContext as GrantRequestContext
- ).expireDays = state.expireDays;
+ context.expireDays = state.expireDays;
}
}
}
diff --git a/frontend/src/components/Issue/logic/GrantRequestModeProvider.ts b/frontend/src/components/Issue/logic/GrantRequestModeProvider.ts
index b006f9192e..1d468dccb6 100644
--- a/frontend/src/components/Issue/logic/GrantRequestModeProvider.ts
+++ b/frontend/src/components/Issue/logic/GrantRequestModeProvider.ts
@@ -1,3 +1,4 @@
+import dayjs from "dayjs";
import { cloneDeep } from "lodash-es";
import { defineComponent, onMounted } from "vue";
import { GrantRequestContext, IssueCreate } from "@/types";
@@ -37,11 +38,13 @@ export default defineComponent({
const cel = stringifyDatabaseResources(context.databaseResources);
expression.push(cel);
}
- expression.push(
- `request.time < timestamp("${new Date(
- Date.now() + context.expireDays * 1000 * 60 * 60 * 24
- ).toISOString()}")`
- );
+ if (context.expireDays > 0) {
+ expression.push(
+ `request.time < timestamp("${dayjs()
+ .add(context.expireDays, "days")
+ .toISOString()}")`
+ );
+ }
} else if (context.role === "EXPORTER") {
if (
!Array.isArray(context.databaseResources) ||
@@ -56,6 +59,13 @@ export default defineComponent({
const cel = stringifyDatabaseResources(context.databaseResources);
expression.push(cel);
}
+ if (context.expireDays > 0) {
+ expression.push(
+ `request.time < timestamp("${dayjs()
+ .add(context.expireDays, "days")
+ .toISOString()}")`
+ );
+ }
expression.push(`request.statement == "${btoa(context.statement)}"`);
expression.push(`request.row_limit == ${context.maxRowCount}`);
expression.push(`request.export_format == "${context.exportFormat}"`);