Skip to content

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

chore(frontend): code optimize (#18741)

ecmadao199eef520f66
diff --git a/frontend/src/components/Database/DatabaseSensitiveDataPanel.vue b/frontend/src/components/Database/DatabaseSensitiveDataPanel.vue
index ec0af336e9..510d416d73 100644
--- a/frontend/src/components/Database/DatabaseSensitiveDataPanel.vue
+++ b/frontend/src/components/Database/DatabaseSensitiveDataPanel.vue
@@ -36,9 +36,8 @@
:row-selectable="!isMaskingForNoSQL"
:show-operation="hasUpdateCatalogPermission && hasSensitiveDataFeature"
:column-list="filteredColumnList"
- :checked-column-index-list="checkedColumnIndexList"
+ v-model:checked-column-list="state.pendingGrantAccessColumn"
@delete="onColumnRemove"
- @checked:update="updateCheckedColumnList($event)"
/>
</div>
@@ -314,31 +313,4 @@ const onGrantAccessButtonClick = () => {
}
state.showGrantAccessDrawer = true;
};
-
-const checkedColumnIndexList = computed(() => {
- const resp = [];
- for (const column of state.pendingGrantAccessColumn) {
- const index = filteredColumnList.value.findIndex((col) => {
- return (
- col.table === column.table &&
- col.schema === column.schema &&
- col.column === column.column
- );
- });
- if (index >= 0) {
- resp.push(index);
- }
- }
- return resp;
-});
-
-const updateCheckedColumnList = (indexes: number[]) => {
- state.pendingGrantAccessColumn = [];
- for (const index of indexes) {
- const col = filteredColumnList.value[index];
- if (col) {
- state.pendingGrantAccessColumn.push(col);
- }
- }
-};
</script>
diff --git a/frontend/src/components/GrantRequestPanel/GrantRequestPanel.vue b/frontend/src/components/GrantRequestPanel/GrantRequestPanel.vue
index ab8bc7efe1..ec16c9c040 100644
--- a/frontend/src/components/GrantRequestPanel/GrantRequestPanel.vue
+++ b/frontend/src/components/GrantRequestPanel/GrantRequestPanel.vue
@@ -170,7 +170,6 @@ const doCreateIssue = async () => {
},
});
- // TODO(ed): handle no permission
window.open(route.fullPath, "_blank");
emit("close");
diff --git a/frontend/src/components/IssueV1/components/Sidebar/TaskCheckSummarySection/AffectedRowsView.vue b/frontend/src/components/IssueV1/components/Sidebar/TaskCheckSummarySection/AffectedRowsView.vue
index 561c3b3ee3..ede36c546b 100644
--- a/frontend/src/components/IssueV1/components/Sidebar/TaskCheckSummarySection/AffectedRowsView.vue
+++ b/frontend/src/components/IssueV1/components/Sidebar/TaskCheckSummarySection/AffectedRowsView.vue
@@ -19,20 +19,17 @@
<div class="w-full flex flex-col mt-1 gap-y-1">
<div
class="w-full flex flex-row justify-between items-center gap-1 group hover:opacity-90 cursor-pointer"
- v-for="task in affectedTasks"
- :key="task.name"
- @click="onClickTask(task)"
+ v-for="item in affectedTasks"
+ :key="item.task.name"
+ @click="onClickTask(item.task)"
>
<span class="group-hover:underline truncate">
- {{ databaseForTask(projectOfIssue(issue), task).databaseName }}
+ {{ databaseForTask(projectOfIssue(issue), item.task).databaseName }}
</span>
<span
- class="shrink-0"
- :class="
- !affectedTaskMap.get(task.name) ? 'opacity-80' : 'font-medium'
- "
+ class="shrink-0 opacity-80"
>
- {{ affectedTaskMap.get(task.name) }}
+ {{ item.count }}
</span>
</div>
</div>
@@ -56,9 +53,10 @@ const { issue, events } = useIssueContext();
const tasks = computed(() => flattenTaskV1List(issue.value.rolloutEntity));
-const affectedTaskMap = computed(() => {
- const tempMap = new Map<string, bigint>();
- props.taskSummaryReportMap.forEach((planCheckRun, task) => {
+const affectedTasks = computed(() => {
+ const tempMap = new Map<string, { task: Task; count: bigint }>();
+
+ for (const [taskName, planCheckRun] of props.taskSummaryReportMap.entries()) {
if (
planCheckRun.results.every(
(result) =>
@@ -66,7 +64,12 @@ const affectedTaskMap = computed(() => {
result.report.value.affectedRows === undefined
)
) {
- return;
+ continue;
+ }
+
+ const task = tasks.value.find((t) => t.name === taskName);
+ if (!task) {
+ continue;
}
const count = planCheckRun.results.reduce((acc, result) => {
@@ -75,19 +78,11 @@ const affectedTaskMap = computed(() => {
}
return acc;
}, 0n);
- tempMap.set(task, count);
- });
- return new Map(
- Array.from(tempMap.entries()).sort((a, b) => Number(b[1] - a[1]))
- );
-});
-const affectedTasks = computed(
- () =>
- Array.from(affectedTaskMap.value.keys())
- .map((task) => tasks.value.find((t) => t.name === task))
- .filter((task) => task) as Task[]
-);
+ tempMap.set(taskName, { task, count });
+ }
+ return Array.from(tempMap.values()).sort((a, b) => Number(b.count - a.count));
+});
const summaryReportResults = computed(() =>
Array.from(props.taskSummaryReportMap.values()).flatMap(
diff --git a/frontend/src/components/LabelEditorDrawer.vue b/frontend/src/components/LabelEditorDrawer.vue
index 7508adb93a..8f7a36cee3 100644
--- a/frontend/src/components/LabelEditorDrawer.vue
+++ b/frontend/src/components/LabelEditorDrawer.vue
@@ -71,8 +71,8 @@ const state = reactive<LocalState>({
const labelListEditorRef = ref<InstanceType<typeof LabelListEditor>>();
const convertKVListToLabelsList = () => {
+ const labels = convertKVListToLabels(state.kvList);
return props.labels.map((oldLabel) => {
- const labels = convertKVListToLabels(state.kvList);
for (const label of state.kvList) {
if (!label.value) {
if (oldLabel[label.key]) {
diff --git a/frontend/src/components/RolloutV1/components/StageTimeline.vue b/frontend/src/components/RolloutV1/components/StageTimeline.vue
index 70bd816036..f6eca30465 100644
--- a/frontend/src/components/RolloutV1/components/StageTimeline.vue
+++ b/frontend/src/components/RolloutV1/components/StageTimeline.vue
@@ -131,7 +131,7 @@
<script lang="ts" setup>
import { SquareChartGanttIcon } from "lucide-vue-next";
import { NTimeline, NTimelineItem, NTooltip } from "naive-ui";
-import { computed, ref, watch } from "vue";
+import { computed, onUnmounted, ref, watch } from "vue";
import BBSpin from "@/bbkit/BBSpin.vue";
import TaskRunDetail from "@/components/IssueV1/components/TaskRunSection/TaskRunDetail.vue";
import TimestampDisplay from "@/components/misc/Timestamp.vue";
@@ -227,16 +227,27 @@ watch(
);
// Also clear transition flag after a short delay to handle stages with no runs
+let transitionTimeoutId: ReturnType<typeof setTimeout> | undefined;
+
watch(
() => props.stage?.name,
() => {
- // Give time for data to load, then clear transition flag
- setTimeout(() => {
+ if (transitionTimeoutId !== undefined) {
+ clearTimeout(transitionTimeoutId);
+ }
+ transitionTimeoutId = setTimeout(() => {
isStageTransitioning.value = false;
+ transitionTimeoutId = undefined;
}, 300);
}
);
+onUnmounted(() => {
+ if (transitionTimeoutId !== undefined) {
+ clearTimeout(transitionTimeoutId);
+ }
+});
+
// Maximum number of task runs to display in the timeline
const MAX_DISPLAY_ITEMS = 50;
diff --git a/frontend/src/components/SensitiveData/components/SensitiveColumnTable.vue b/frontend/src/components/SensitiveData/components/SensitiveColumnTable.vue
index 25c0dc3e1f..c0cac9b0ee 100644
--- a/frontend/src/components/SensitiveData/components/SensitiveColumnTable.vue
+++ b/frontend/src/components/SensitiveData/components/SensitiveColumnTable.vue
@@ -14,7 +14,7 @@
import { create } from "@bufbuild/protobuf";
import { TrashIcon } from "lucide-vue-next";
import { type DataTableColumn, NDataTable, NPopconfirm } from "naive-ui";
-import { computed, h, ref, watch, withModifiers } from "vue";
+import { computed, h, withModifiers } from "vue";
import { useI18n } from "vue-i18n";
import { RouterLink, useRouter } from "vue-router";
import ClassificationCell from "@/components/ColumnDataTable/ClassificationCell.vue";
@@ -45,33 +45,19 @@ const props = defineProps<{
rowClickable: boolean;
rowSelectable: boolean;
columnList: MaskData[];
- checkedColumnIndexList: number[];
+ checkedColumnList: MaskData[];
}>();
const emit = defineEmits<{
(event: "delete", item: MaskData): void;
- (event: "checked:update", list: number[]): void;
+ (event: "update:checkedColumnList", list: MaskData[]): void;
}>();
const { t } = useI18n();
const router = useRouter();
-const checkedColumnIndex = ref<Set<number>>(
- new Set(props.checkedColumnIndexList)
-);
const settingStore = useSettingV1Store();
const dbCatalogStore = useDatabaseCatalogV1Store();
-watch(
- () => props.columnList,
- () => (checkedColumnIndex.value = new Set()),
- { deep: true }
-);
-watch(
- () => props.checkedColumnIndexList,
- (val) => (checkedColumnIndex.value = new Set(val)),
- { deep: true }
-);
-
const itemKey = (item: MaskData) => {
const parts = [];
const { schema, table, column } = item;
@@ -93,14 +79,7 @@ const classificationConfig = computed(() => {
});
const checkedItemKeys = computed(() => {
- const keys: string[] = [];
- props.checkedColumnIndexList.forEach((index) => {
- const item = props.columnList[index];
- if (item) {
- keys.push(itemKey(item));
- }
- });
- return keys;
+ return props.checkedColumnList.map(itemKey);
});
const dataTableColumns = computed(() => {
@@ -289,13 +268,13 @@ const onMaskingClear = async (item: MaskData) => {
const handleUpdateCheckedRowKeys = (keys: string[]) => {
const keysSet = new Set(keys);
- const checkedIndexList: number[] = [];
- props.columnList.forEach((item, index) => {
- const key = itemKey(item);
+ const checkedList: MaskData[] = [];
+ for (const column of props.columnList) {
+ const key = itemKey(column);
if (keysSet.has(key)) {
- checkedIndexList.push(index);
+ checkedList.push(column);
}
- });
- emit("checked:update", checkedIndexList);
+ }
+ emit("update:checkedColumnList", checkedList);
};
</script>
diff --git a/frontend/src/grpcweb/middlewares/activeInterceptorMiddleware.ts b/frontend/src/grpcweb/middlewares/activeInterceptorMiddleware.ts
index 2418054da5..5407682da6 100644
--- a/frontend/src/grpcweb/middlewares/activeInterceptorMiddleware.ts
+++ b/frontend/src/grpcweb/middlewares/activeInterceptorMiddleware.ts
@@ -2,7 +2,6 @@ import { type Interceptor } from "@connectrpc/connect";
import { useLastActivity } from "@/composables/useLastActivity";
import { useCurrentUserV1 } from "@/store";
-// TODO(ed): some requests are called automatically by the script, for example, refresh the issue status.
export const activeInterceptor: Interceptor = (next) => async (req) => {
const resp = await next(req);
const me = useCurrentUserV1();