Skip to content

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

refactor: expr editor (#10489)

ecmadaocf402825bea0
diff --git a/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue b/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue
index 64ca5334cb..31de8fcb26 100644
--- a/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue
+++ b/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue
@@ -54,7 +54,9 @@
<ExprEditor
:expr="state.expr"
:allow-admin="true"
- :resource-type="resourceType"
+ :factor-list="FactorList.get(resourceType) ?? []"
+ :factor-support-dropdown="[]"
+ :factor-options-map="new Map()"
/>
</div>
<div class="col-span-2">
@@ -82,6 +84,7 @@ import { NInput } from "naive-ui";
import { Status } from "nice-grpc-web";
import { computed, onMounted, reactive, ref, watch } from "vue";
import { useI18n } from "vue-i18n";
+import ExprEditor from "@/components/ExprEditor";
import {
ConditionGroupExpr,
emptySimpleExpr,
@@ -110,8 +113,7 @@ import { EnvironmentSelect, ProjectSelect, ResourceIdField } from "../v2";
import DatabaseGroupSelect from "./DatabaseGroupSelect.vue";
import MatchedDatabaseView from "./MatchedDatabaseView.vue";
import MatchedTableView from "./MatchedTableView.vue";
-import ExprEditor from "./common/ExprEditor";
-import { ResourceType } from "./common/ExprEditor/context";
+import { FactorList, ResourceType } from "./utils";
const props = defineProps<{
project: ComposedProject;
diff --git a/frontend/src/components/DatabaseGroup/common/ExprEditor/Condition.vue b/frontend/src/components/DatabaseGroup/common/ExprEditor/Condition.vue
deleted file mode 100644
index 5ecb14bbc4..0000000000
--- a/frontend/src/components/DatabaseGroup/common/ExprEditor/Condition.vue
+++ /dev/null
@@ -1,50 +0,0 @@
-<!-- eslint-disable vue/no-mutating-props -->
-<template>
- <NInputGroup
- class="bb-risk-expr-editor-condition w-full flex items-center overflow-x-hidden"
- >
- <FactorSelect :expr="expr" />
-
- <OperatorSelect :expr="expr" />
-
- <ValueInput :expr="expr" />
-
- <NButton
- v-if="allowAdmin"
- size="small"
- type="default"
- :style="'flex-shrink: 0;padding-left: 0;padding-right: 0;--n-width: 28px;--n-color: white;'"
- @click="$emit('remove')"
- >
- <heroicons:trash class="w-3.5 h-3.5" />
- </NButton>
- </NInputGroup>
-</template>
-
-<script lang="ts" setup>
-import { NButton, NInputGroup } from "naive-ui";
-import { watch } from "vue";
-import { type ConditionExpr } from "@/plugins/cel";
-import { FactorSelect, OperatorSelect, ValueInput } from "./components";
-import { useExprEditorContext } from "./context";
-
-const props = defineProps<{
- expr: ConditionExpr;
-}>();
-
-const emit = defineEmits<{
- (event: "remove"): void;
- (event: "update"): void;
-}>();
-
-const context = useExprEditorContext();
-const { allowAdmin } = context;
-
-watch(
- () => props.expr,
- () => {
- emit("update");
- },
- { deep: true }
-);
-</script>
diff --git a/frontend/src/components/DatabaseGroup/common/ExprEditor/ConditionGroup.vue b/frontend/src/components/DatabaseGroup/common/ExprEditor/ConditionGroup.vue
deleted file mode 100644
index bb6f8d60a5..0000000000
--- a/frontend/src/components/DatabaseGroup/common/ExprEditor/ConditionGroup.vue
+++ /dev/null
@@ -1,196 +0,0 @@
-<template>
- <div
- class="bb-risk-expr-editor-group w-full overflow-hidden space-y-2 py-0.5"
- :class="[root ? '' : 'border rounded-[3px] bg-gray-50']"
- >
- <div v-if="!root" class="pl-2.5 pr-1 text-gray-500 flex items-center">
- <div class="flex-1">
- <template v-if="args.length > 0">
- <template v-if="operator === '_||_'">
- {{ $t("custom-approval.risk-rule.condition.group.or.description") }}
- </template>
- <template v-if="operator === '_&&_'">
- {{
- $t("custom-approval.risk-rule.condition.group.and.description")
- }}
- </template>
- </template>
- <template v-else>
- <i18n-t
- keypath="custom-approval.risk-rule.condition.add-condition-in-group-placeholder"
- tag="div"
- class="inline-flex items-center"
- >
- <template #plus>
- <heroicons:plus class="w-3 h-3 mx-1" />
- </template>
- </i18n-t>
- </template>
- </div>
- <div v-if="allowAdmin" class="flex items-center justify-end">
- <NButton
- size="tiny"
- quaternary
- type="default"
- :style="`flex-shrink: 0; padding-left: 0; padding-right: 0; --n-width: 22px`"
- @click="addCondition"
- >
- <heroicons:plus class="w-4 h-4" />
- </NButton>
- <NButton
- size="tiny"
- quaternary
- type="default"
- :style="`flex-shrink: 0; padding-left: 0; padding-right: 0; --n-width: 22px;`"
- @click="emit('remove')"
- >
- <heroicons:trash class="w-3.5 h-3.5" />
- </NButton>
- </div>
- </div>
-
- <div v-if="root && args.length === 0" class="px-1.5 text-gray-500">
- {{
- $t("custom-approval.risk-rule.condition.add-root-condition-placeholder")
- }}
- </div>
- <div
- v-for="(operand, i) in args"
- :key="i"
- class="flex items-start gap-x-1 w-full"
- :class="[root ? '' : 'px-1']"
- >
- <div class="w-14 shrink-0">
- <div v-if="i === 0" class="pl-1.5 pt-1 text-control">Where</div>
- <NSelect
- v-else-if="i === 1 && allowAdmin"
- v-model:value="operator"
- :options="OPERATORS"
- :consistent-menu-width="false"
- size="small"
- @update:value="$emit('update')"
- />
- <div v-else class="pl-2 pt-1 text-control lowercase">
- {{ operatorLabel(operator) }}
- </div>
- </div>
- <div class="flex-1 space-y-1 overflow-x-hidden">
- <ConditionGroup
- v-if="isConditionGroupExpr(operand)"
- :expr="operand"
- @remove="removeConditionGroup(operand)"
- @update="$emit('update')"
- />
- <Condition
- v-if="isConditionExpr(operand)"
- :expr="operand"
- @remove="removeCondition(operand)"
- @update="$emit('update')"
- />
- </div>
- </div>
- <div v-if="root && allowAdmin" class="space-x-1">
- <NButton size="small" quaternary @click="addCondition">
- <template #icon><heroicons:plus class="w-4 h-4" /></template>
- <span>{{ $t("custom-approval.risk-rule.condition.add") }}</span>
- </NButton>
- <NButton size="small" quaternary @click="addConditionGroup">
- <template #icon><heroicons:plus class="w-4 h-4" /></template>
- <span>{{ $t("custom-approval.risk-rule.condition.add-group") }}</span>
- <NTooltip>
- <template #trigger>
- <heroicons:question-mark-circle class="ml-1 w-3 h-3" />
- </template>
- <div class="max-w-[18rem]">
- {{ $t("custom-approval.risk-rule.condition.group.tooltip") }}
- </div>
- </NTooltip>
- </NButton>
- </div>
- </div>
-</template>
-
-<script lang="ts" setup>
-/* eslint-disable vue/no-mutating-props */
-import { NButton, NSelect, NTooltip, type SelectOption } from "naive-ui";
-import { computed } from "vue";
-import {
- type ConditionExpr,
- type ConditionGroupExpr,
- type LogicalOperator,
- isConditionGroupExpr,
- isConditionExpr,
- getOperatorListByFactor,
-} from "@/plugins/cel";
-import Condition from "./Condition.vue";
-import { useExprEditorContext } from "./context";
-import { StringFactorList } from "./factor";
-
-const props = defineProps<{
- expr: ConditionGroupExpr;
- root?: boolean;
-}>();
-
-const emit = defineEmits<{
- (event: "remove"): void;
- (event: "update"): void;
-}>();
-
-const context = useExprEditorContext();
-const { allowAdmin } = context;
-
-const operator = computed({
- get() {
- return props.expr.operator;
- },
- set(op) {
- props.expr.operator = op;
- },
-});
-const args = computed(() => props.expr.args);
-
-const operatorLabel = (op: LogicalOperator) => {
- if (op === "_&&_") return "and";
- if (op === "_||_") return "or";
- throw new Error(`unknown logical operator "${op}"`);
-};
-
-const OPERATORS: SelectOption[] = [
- { label: operatorLabel("_&&_"), value: "_&&_" },
- { label: operatorLabel("_||_"), value: "_||_" },
-];
-
-const addCondition = () => {
- const factor = StringFactorList[0];
- const operators = getOperatorListByFactor(factor);
- args.value.push({
- operator: operators[0] as any,
- args: [factor, ""],
- });
- emit("update");
-};
-
-const addConditionGroup = () => {
- args.value.push({
- operator: "_&&_",
- args: [],
- });
- emit("update");
-};
-
-const removeCondition = (condition: ConditionExpr) => {
- const index = args.value.indexOf(condition);
- if (index >= 0) {
- args.value.splice(index, 1);
- emit("update");
- }
-};
-
-const removeConditionGroup = (group: ConditionGroupExpr) => {
- const index = args.value.indexOf(group);
- if (index >= 0) {
- args.value.splice(index, 1);
- emit("update");
- }
-};
-</script>
diff --git a/frontend/src/components/DatabaseGroup/common/ExprEditor/ExprEditor.vue b/frontend/src/components/DatabaseGroup/common/ExprEditor/ExprEditor.vue
deleted file mode 100644
index 3b7126dcbb..0000000000
--- a/frontend/src/components/DatabaseGroup/common/ExprEditor/ExprEditor.vue
+++ /dev/null
@@ -1,54 +0,0 @@
-<template>
- <div class="bb-expr-editor text-sm w-full">
- <ConditionGroup :expr="expr" :root="true" @update="$emit('update')" />
- </div>
-</template>
-
-<script lang="ts" setup>
-import { toRef } from "vue";
-import type { ConditionGroupExpr } from "@/plugins/cel";
-import ConditionGroup from "./ConditionGroup.vue";
-import { ResourceType, provideExprEditorContext } from "./context";
-
-const props = withDefaults(
- defineProps<{
- expr: ConditionGroupExpr;
- resourceType: ResourceType;
- allowAdmin?: boolean;
- }>(),
- {
- resourceType: "DATABASE_GROUP",
- allowAdmin: false,
- }
-);
-
-defineEmits<{
- (event: "update"): void;
-}>();
-
-provideExprEditorContext({
- allowAdmin: toRef(props, "allowAdmin"),
- resourceType: toRef(props, "resourceType"),
-});
-</script>
-
-<style>
-.bb-expr-editor .n-base-selection {
- --n-padding-single: 0 22px 0 8px !important;
- --n-padding-multiple: 3px 24px 0 5px !important;
-}
-.bb-expr-editor .n-base-selection .n-base-suffix {
- right: 5px !important;
-}
-
-.bb-expr-editor .n-base-selection-tag-wrapper {
- padding-right: 2px;
-}
-
-.bb-expr-editor .n-button {
- --n-padding: 0 6px 0 2px !important;
-}
-.bb-expr-editor .n-button .n-button__icon {
- margin-right: 0px !important;
-}
-</style>
diff --git a/frontend/src/components/DatabaseGroup/common/ExprEditor/components/FactorSelect.vue b/frontend/src/components/DatabaseGroup/common/ExprEditor/components/FactorSelect.vue
deleted file mode 100644
index 08e6716dbc..0000000000
--- a/frontend/src/components/DatabaseGroup/common/ExprEditor/components/FactorSelect.vue
+++ /dev/null
@@ -1,57 +0,0 @@
-<template>
- <NSelect
- v-model:value="factor"
- :options="options"
- :consistent-menu-width="false"
- :disabled="!allowAdmin"
- size="small"
- style="width: auto; max-width: 9rem; flex-shrink: 0"
- />
-</template>
-
-<script lang="ts" setup>
-/* eslint-disable vue/no-mutating-props */
-import { SelectOption } from "naive-ui";
-import { computed, watch } from "vue";
-import { type ConditionExpr, type Factor } from "@/plugins/cel";
-import { factorText } from "../../utils";
-import { useExprEditorContext } from "../context";
-import { FactorList } from "../factor";
-
-const props = defineProps<{
- expr: ConditionExpr;
-}>();
-
-const { allowAdmin, resourceType } = useExprEditorContext();
-
-const factor = computed({
- get() {
- return props.expr.args[0];
- },
- set(factor) {
- props.expr.args[0] = factor;
- },
-});
-
-const factorList = computed((): Factor[] => {
- return FactorList[resourceType.value];
-});
-
-const options = computed(() => {
- return factorList.value.map<SelectOption>((v) => ({
- label: factorText(v),
- value: v,
- }));
-});
-
-watch(
- [factor, factorList],
- () => {
- if (factorList.value.length === 0) return;
- if (!factorList.value.includes(factor.value)) {
- factor.value = factorList.value[0];
- }
- },
- { immediate: true }
-);
-</script>
diff --git a/frontend/src/components/DatabaseGroup/common/ExprEditor/components/OperatorSelect.vue b/frontend/src/components/DatabaseGroup/common/ExprEditor/components/OperatorSelect.vue
deleted file mode 100644
index b8a951d5d9..0000000000
--- a/frontend/src/components/DatabaseGroup/common/ExprEditor/components/OperatorSelect.vue
+++ /dev/null
@@ -1,78 +0,0 @@
-<!-- eslint-disable vue/no-mutating-props -->
-<template>
- <NSelect
- v-model:value="operator"
- :options="options"
- :consistent-menu-width="false"
- :disabled="!allowAdmin"
- size="small"
- style="width: auto; max-width: 7rem; min-width: 2.5rem; flex-shrink: 0"
- />
-</template>
-
-<script lang="ts" setup>
-/* eslint-disable vue/no-mutating-props */
-import { SelectOption } from "naive-ui";
-import { computed, watch } from "vue";
-import {
- type Operator,
- type ConditionOperator,
- type ConditionExpr,
- getOperatorListByFactor,
-} from "@/plugins/cel";
-import { useExprEditorContext } from "../context";
-
-const props = defineProps<{
- expr: ConditionExpr;
-}>();
-
-const context = useExprEditorContext();
-const { allowAdmin } = context;
-
-const operator = computed({
- get() {
- return props.expr.operator;
- },
- set(op) {
- props.expr.operator = op;
- },
-});
-
-const factor = computed(() => {
- return props.expr.args[0];
-});
-
-const OPERATOR_DICT = new Map([
- ["_==_", "=="],
- ["_!=_", "!="],
- ["_<_", "<"],
- ["_<=_", "≤"],
- ["_>=_", "≥"],
- ["_>_", ">"],
-]);
-
-const options = computed(() => {
- const operators = getOperatorListByFactor(factor.value);
-
- const mapOption = (op: Operator): SelectOption => {
- const label = OPERATOR_DICT.get(op) ?? op.replace(/^@/g, "");
- return {
- label,
- value: op,
- };
- };
- return operators.map(mapOption);
-});
-
-// normalize operator when factor changed
-watch(
- [options, () => props.expr.operator],
- () => {
- if (options.value.length === 0) return;
- if (!options.value.find((opt) => opt.value === props.expr.operator)) {
- props.expr.operator = options.value[0].value as ConditionOperator;
- }
- },
- { immediate: true }
-);
-</script>
diff --git a/frontend/src/components/DatabaseGroup/common/ExprEditor/components/StringInput.vue b/frontend/src/components/DatabaseGroup/common/ExprEditor/components/StringInput.vue
deleted file mode 100644
index d4a4e215cb..0000000000
--- a/frontend/src/components/DatabaseGroup/common/ExprEditor/components/StringInput.vue
+++ /dev/null
@@ -1,26 +0,0 @@
-<template>
- <NInput
- :value="value"
- :placeholder="$t('custom-approval.risk-rule.condition.input-value')"
- :disabled="!allowAdmin"
- size="small"
- style="min-width: 7rem; width: auto; overflow-x: hidden"
- @update:value="$emit('update:value', $event)"
- />
-</template>
-
-<script lang="ts" setup>
-import { NInput } from "naive-ui";
-import { useExprEditorContext } from "../context";
-
-defineProps<{
- value: string;
-}>();
-
-defineEmits<{
- (event: "update:value", value: string): void;
-}>();
-
-const context = useExprEditorContext();
-const { allowAdmin } = context;
-</script>
diff --git a/frontend/src/components/DatabaseGroup/common/ExprEditor/components/ValueInput.vue b/frontend/src/components/DatabaseGroup/common/ExprEditor/components/ValueInput.vue
deleted file mode 100644
index 2d3e3c5bd7..0000000000
--- a/frontend/src/components/DatabaseGroup/common/ExprEditor/components/ValueInput.vue
+++ /dev/null
@@ -1,82 +0,0 @@
-<template>
- <template v-if="inputType === 'INPUT'">
- <StringInput
- v-if="isStringValue"
- :value="getStringValue()"
- @update:value="setStringValue($event)"
- />
- </template>
-</template>
-
-<script lang="ts" setup>
-/* eslint-disable vue/no-mutating-props */
-import { computed, watch } from "vue";
-import {
- type ConditionExpr,
- isEqualityOperator,
- isStringOperator,
- isStringFactor,
-} from "@/plugins/cel";
-import StringInput from "./StringInput.vue";
-
-type InputType = "INPUT";
-
-const props = defineProps<{
- expr: ConditionExpr;
-}>();
-
-const operator = computed(() => {
- return props.expr.operator;
-});
-
-const factor = computed(() => {
- return props.expr.args[0];
-});
-
-const isStringValue = computed(() => {
- if (isStringOperator(operator.value)) return true;
- if (isEqualityOperator(operator.value) && isStringFactor(factor.value)) {
- return true;
- }
- return false;
-});
-const inputType = computed((): InputType => {
- return "INPUT";
-});
-
-const getStringValue = () => {
- const value = props.expr.args[1];
- if (typeof value !== "string") return "";
- return value;
-};
-const setStringValue = (value: string) => {
- props.expr.args[1] = value;
-};
-
-// clean up value type when factor and operator changed
-watch(
- [operator, () => props.expr.args[1]],
- ([operator, value]) => {
- if (isEqualityOperator(operator)) {
- if (isStringFactor(factor.value) && typeof value !== "string") {
- setStringValue("");
- }
- }
- if (isStringOperator(operator) && typeof value !== "string") {
- setStringValue("");
- }
- },
- {
- immediate: true,
- }
-);
-watch(
- factor,
- (factor) => {
- if (isStringFactor(factor)) {
- setStringValue("");
- }
- },
- { immediate: false }
-);
-</script>
diff --git a/frontend/src/components/DatabaseGroup/common/ExprEditor/components/index.ts b/frontend/src/components/DatabaseGroup/common/ExprEditor/components/index.ts
deleted file mode 100644
index faeac7beeb..0000000000
--- a/frontend/src/components/DatabaseGroup/common/ExprEditor/components/index.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-import FactorSelect from "./FactorSelect.vue";
-import OperatorSelect from "./OperatorSelect.vue";
-import ValueInput from "./ValueInput.vue";
-
-export { FactorSelect, OperatorSelect, ValueInput };
diff --git a/frontend/src/components/DatabaseGroup/common/ExprEditor/context.ts b/frontend/src/components/DatabaseGroup/common/ExprEditor/context.ts
deleted file mode 100644
index bfec46c52c..0000000000
--- a/frontend/src/components/DatabaseGroup/common/ExprEditor/context.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-import { inject, provide, type InjectionKey, type Ref } from "vue";
-
-export type ResourceType = "DATABASE_GROUP" | "SCHEMA_GROUP";
-
-export type ExprEditorContext = {
- allowAdmin: Ref<boolean>;
- resourceType: Ref<ResourceType>;
-};
-
-export const KEY = Symbol(
- "bb.database-group.expr-editor"
-) as InjectionKey<ExprEditorContext>;
-
-export const useExprEditorContext = () => {
- return inject(KEY)!;
-};
-
-export const provideExprEditorContext = (context: ExprEditorContext) => {
- provide(KEY, context);
-};
diff --git a/frontend/src/components/DatabaseGroup/common/ExprEditor/factor.ts b/frontend/src/components/DatabaseGroup/common/ExprEditor/factor.ts
deleted file mode 100644
index 12fc3e6bec..0000000000
--- a/frontend/src/components/DatabaseGroup/common/ExprEditor/factor.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-export const StringFactorList = [
- "resource.database_name",
- "resource.schema_name",
- "resource.table_name",
- "resource.instance_id",
-] as const;
-
-export const FactorList = {
- DATABASE_GROUP: ["resource.database_name", "resource.instance_id"],
- SCHEMA_GROUP: ["resource.table_name"],
-};
diff --git a/frontend/src/components/DatabaseGroup/common/ExprEditor/index.ts b/frontend/src/components/DatabaseGroup/common/ExprEditor/index.ts
deleted file mode 100644
index 497ff06640..0000000000
--- a/frontend/src/components/DatabaseGroup/common/ExprEditor/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-import ExprEditor from "./ExprEditor.vue";
-
-export default ExprEditor;
diff --git a/frontend/src/components/DatabaseGroup/common/utils.ts b/frontend/src/components/DatabaseGroup/common/utils.ts
deleted file mode 100644
index 9a094b89e2..0000000000
--- a/frontend/src/components/DatabaseGroup/common/utils.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import type { Factor } from "@/plugins/cel";
-import { t, te } from "@/plugins/i18n";
-
-const stringifyFactor = (factor: Factor) => {
- return factor.replace(/\./g, "_");
-};
-
-export const factorText = (factor: Factor) => {
- const keypath = `database-group.factor.${stringifyFactor(factor)}`;
- if (te(keypath)) {
- return t(keypath);
- }
- return factor;
-};
diff --git a/frontend/src/components/DatabaseGroup/utils.ts b/frontend/src/components/DatabaseGroup/utils.ts
new file mode 100644
index 0000000000..ca53719ed6
--- /dev/null
+++ b/frontend/src/components/DatabaseGroup/utils.ts
@@ -0,0 +1,8 @@
+import { Factor } from "@/plugins/cel";
+
+export type ResourceType = "DATABASE_GROUP" | "SCHEMA_GROUP";
+
+export const FactorList: Map<ResourceType, Factor[]> = new Map([
+ ["DATABASE_GROUP", ["resource.database_name", "resource.instance_id"]],
+ ["SCHEMA_GROUP", ["resource.table_name"]],
+]);
diff --git a/frontend/src/components/ExprEditor/components/common.ts b/frontend/src/components/ExprEditor/components/common.ts
index d44c7e8b88..c5e2cf7d37 100644
--- a/frontend/src/components/ExprEditor/components/common.ts
+++ b/frontend/src/components/ExprEditor/components/common.ts
@@ -20,8 +20,12 @@ export const useSelectOptions = (expr: Ref<ConditionExpr>) => {
return options;
};
+const stringifyFactor = (factor: Factor) => {
+ return factor.replace(/\./g, "_");
+};
+
export const factorText = (factor: Factor) => {
- const keypath = `cel.factor.${factor}`;
+ const keypath = `cel.factor.${stringifyFactor(factor)}`;
if (te(keypath)) {
return t(keypath);
}
diff --git a/frontend/src/components/RepositoryForm.vue b/frontend/src/components/RepositoryForm.vue
index 2cad4a1c72..721828fc01 100644
--- a/frontend/src/components/RepositoryForm.vue
+++ b/frontend/src/components/RepositoryForm.vue
@@ -2,7 +2,7 @@
<template>
<div class="space-y-4">
<div>
- <div v-if="isDebug && getWebhookLink !== ''">
+ <div v-if="getWebhookLink !== ''" class="mb-2">
<label class="textlabel mt-2">
<i18n-t keypath="repository.our-webhook-link">
<template #webhookLink>
@@ -304,7 +304,6 @@
<script lang="ts" setup>
import { NCheckbox, NSelect, SelectOption } from "naive-ui";
-import { storeToRefs } from "pinia";
import { reactive, computed, h } from "vue";
import { useI18n } from "vue-i18n";
import { BBBetaBadge } from "@/bbkit";
@@ -312,7 +311,6 @@ import {
hasFeature,
useSubscriptionV1Store,
useDatabaseV1Store,
- useActuatorV1Store,
} from "@/store";
import { ExternalRepositoryInfo, RepositoryConfig } from "@/types";
import { ExternalVersionControl_Type } from "@/types/proto/v1/externalvs_service";
@@ -538,10 +536,6 @@ const onSQLReviewCIToggle = (on: boolean) => {
}
};
-const actuatorStore = useActuatorV1Store();
-
-const isDebug = storeToRefs(actuatorStore).isDebug;
-
const renderLabel = (option: SelectOption) => {
const value = option.value as SchemaChange;
const child = [
diff --git a/frontend/src/components/VCS/VCSProviderOAuthPanel.vue b/frontend/src/components/VCS/VCSProviderOAuthPanel.vue
index f2992f4157..5db120f5a4 100644
--- a/frontend/src/components/VCS/VCSProviderOAuthPanel.vue
+++ b/frontend/src/components/VCS/VCSProviderOAuthPanel.vue
@@ -530,7 +530,7 @@
{{ applicationIdErrorDescription }}
</p>
<div class="mt-4 textlabel">
- Secret <span class="text-red-600">*</span>
+ {{ secretField }} <span class="text-red-600">*</span>
</div>
<BBTextField
class="mt-2 w-full"
@@ -545,15 +545,9 @@
</div>
</template>
-<script lang="ts">
+<script lang="ts" setup>
import { isEmpty } from "lodash-es";
-import {
- computed,
- defineComponent,
- onUnmounted,
- PropType,
- reactive,
-} from "vue";
+import { computed, onUnmounted, reactive } from "vue";
import { useI18n } from "vue-i18n";
import { pushNotification } from "@/store";
import {
@@ -572,196 +566,171 @@ interface LocalState {
showSecretError: boolean;
}
-export default defineComponent({
- name: "VCSProviderOAuthPanel",
- props: {
- config: {
- required: true,
- type: Object as PropType<VCSConfig>,
- },
- },
- setup(props) {
- const { t } = useI18n();
- const state = reactive<LocalState>({
- showApplicationIdError:
- !isEmpty(props.config.applicationId) &&
- !isValidVCSApplicationIdOrSecret(
- props.config.type,
- props.config.applicationId
- ),
- showSecretError:
- !isEmpty(props.config.secret) &&
- !isValidVCSApplicationIdOrSecret(
- props.config.type,
- props.config.secret
- ),
- });
+const props = defineProps<{
+ config: VCSConfig;
+}>();
- onUnmounted(() => {
- if (state.applicationIdValidationTimer) {
- clearInterval(state.applicationIdValidationTimer);
- }
- if (state.secretValidationTimer) {
- clearInterval(state.secretValidationTimer);
- }
- });
+const { t } = useI18n();
+const state = reactive<LocalState>({
+ showApplicationIdError:
+ !isEmpty(props.config.applicationId) &&
+ !isValidVCSApplicationIdOrSecret(
+ props.config.type,
+ props.config.applicationId
+ ),
+ showSecretError:
+ !isEmpty(props.config.secret) &&
+ !isValidVCSApplicationIdOrSecret(props.config.type, props.config.secret),
+});
- const createOAuthApplicationUrl = computed((): string => {
- if (props.config.uiType == "GITLAB_SELF_HOST") {
- return `${props.config.instanceUrl}/admin/applications/new`;
- } else if (props.config.uiType == "GITLAB_COM") {
- return `https://gitlab.com/-/profile/applications`;
- } else if (props.config.uiType == "GITHUB_COM") {
- return `https://github.com/settings/applications/new`;
- } else if (props.config.uiType == "AZURE_DEVOPS") {
- return `https://app.vsaex.visualstudio.com/app/register`;
- }
- return "";
- });
+onUnmounted(() => {
+ if (state.applicationIdValidationTimer) {
+ clearInterval(state.applicationIdValidationTimer);
+ }
+ if (state.secretValidationTimer) {
+ clearInterval(state.secretValidationTimer);
+ }
+});
- const copyHomepageURL = () => {
- toClipboard("https://bytebase.com").then(() => {
- pushNotification({
- module: "bytebase",
- style: "INFO",
- title: t(
- "gitops.setting.add-git-provider.oauth-info.copy-homepage-url"
- ),
- });
- });
- };
+const createOAuthApplicationUrl = computed((): string => {
+ if (props.config.uiType == "GITLAB_SELF_HOST") {
+ return `${props.config.instanceUrl}/admin/applications/new`;
+ } else if (props.config.uiType == "GITLAB_COM") {
+ return `https://gitlab.com/-/profile/applications`;
+ } else if (props.config.uiType == "GITHUB_COM") {
+ return `https://github.com/settings/applications/new`;
+ } else if (props.config.uiType == "AZURE_DEVOPS") {
+ return `https://app.vsaex.visualstudio.com/app/register`;
+ }
+ return "";
+});
- const copyRedirectURI = () => {
- toClipboard(redirectUrl()).then(() => {
- pushNotification({
- module: "bytebase",
- style: "INFO",
- title: t(
- "gitops.setting.add-git-provider.oauth-info.copy-redirect-uri"
- ),
- });
- });
- };
+const copyHomepageURL = () => {
+ toClipboard("https://bytebase.com").then(() => {
+ pushNotification({
+ module: "bytebase",
+ style: "INFO",
+ title: t("gitops.setting.add-git-provider.oauth-info.copy-homepage-url"),
+ });
+ });
+};
+
+const copyRedirectURI = () => {
+ toClipboard(redirectUrl()).then(() => {
+ pushNotification({
+ module: "bytebase",
+ style: "INFO",
+ title: t("gitops.setting.add-git-provider.oauth-info.copy-redirect-uri"),
+ });
+ });
+};
- const changeApplicationId = (value: string) => {
- // eslint-disable-next-line vue/no-mutating-props
- props.config.applicationId = value;
+const changeApplicationId = (value: string) => {
+ // eslint-disable-next-line vue/no-mutating-props
+ props.config.applicationId = value;
- if (state.applicationIdValidationTimer) {
- clearInterval(state.applicationIdValidationTimer);
- }
- // If text becomes valid, we immediately clear the error.
- // otherwise, we delay TEXT_VALIDATION_DELAY to do the validation in case there is continous keystroke.
- if (
- isValidVCSApplicationIdOrSecret(
+ if (state.applicationIdValidationTimer) {
+ clearInterval(state.applicationIdValidationTimer);
+ }
+ // If text becomes valid, we immediately clear the error.
+ // otherwise, we delay TEXT_VALIDATION_DELAY to do the validation in case there is continous keystroke.
+ if (
+ isValidVCSApplicationIdOrSecret(
+ props.config.type,
+ props.config.applicationId
+ )
+ ) {
+ state.showApplicationIdError = false;
+ } else {
+ state.applicationIdValidationTimer = setTimeout(() => {
+ // If error is already displayed, we hide the error only if there is valid input.
+ // Otherwise, we hide the error if input is either empty or valid.
+ if (state.showApplicationIdError) {
+ state.showApplicationIdError = !isValidVCSApplicationIdOrSecret(
props.config.type,
props.config.applicationId
- )
- ) {
- state.showApplicationIdError = false;
+ );
} else {
- state.applicationIdValidationTimer = setTimeout(() => {
- // If error is already displayed, we hide the error only if there is valid input.
- // Otherwise, we hide the error if input is either empty or valid.
- if (state.showApplicationIdError) {
- state.showApplicationIdError = !isValidVCSApplicationIdOrSecret(
- props.config.type,
- props.config.applicationId
- );
- } else {
- state.showApplicationIdError =
- !isValidVCSApplicationIdOrSecret(
- props.config.type,
- props.config.applicationId
- ) &&
- !isValidVCSApplicationIdOrSecret(
- props.config.type,
- props.config.applicationId
- );
- }
- }, TEXT_VALIDATION_DELAY);
+ state.showApplicationIdError =
+ !isValidVCSApplicationIdOrSecret(
+ props.config.type,
+ props.config.applicationId
+ ) &&
+ !isValidVCSApplicationIdOrSecret(
+ props.config.type,
+ props.config.applicationId
+ );
}
- };
+ }, TEXT_VALIDATION_DELAY);
+ }
+};
- const changeSecret = (value: string) => {
- // eslint-disable-next-line vue/no-mutating-props
- props.config.secret = value;
+const changeSecret = (value: string) => {
+ // eslint-disable-next-line vue/no-mutating-props
+ props.config.secret = value;
- if (state.secretValidationTimer) {
- clearInterval(state.secretValidationTimer);
- }
- // If text becomes valid, we immediately clear the error.
- // otherwise, we delay TEXT_VALIDATION_DELAY to do the validation in case there is continous keystroke.
- if (
- isValidVCSApplicationIdOrSecret(props.config.type, props.config.secret)
- ) {
- state.showSecretError = false;
+ if (state.secretValidationTimer) {
+ clearInterval(state.secretValidationTimer);
+ }
+ // If text becomes valid, we immediately clear the error.
+ // otherwise, we delay TEXT_VALIDATION_DELAY to do the validation in case there is continous keystroke.
+ if (isValidVCSApplicationIdOrSecret(props.config.type, props.config.secret)) {
+ state.showSecretError = false;
+ } else {
+ state.secretValidationTimer = setTimeout(() => {
+ // If error is already displayed, we hide the error only if there is valid input.
+ // Otherwise, we hide the error if input is either empty or valid.
+ if (state.showSecretError) {
+ state.showSecretError = !isValidVCSApplicationIdOrSecret(
+ props.config.type,
+ props.config.secret
+ );
} else {
- state.secretValidationTimer = setTimeout(() => {
- // If error is already displayed, we hide the error only if there is valid input.
- // Otherwise, we hide the error if input is either empty or valid.
- if (state.showSecretError) {
- state.showSecretError = !isValidVCSApplicationIdOrSecret(
- props.config.type,
- props.config.secret
- );
- } else {
- state.showSecretError =
- !isEmpty(props.config.secret) &&
- !isValidVCSApplicationIdOrSecret(
- props.config.type,
- props.config.secret
- );
- }
- }, TEXT_VALIDATION_DELAY);
+ state.showSecretError =
+ !isEmpty(props.config.secret) &&
+ !isValidVCSApplicationIdOrSecret(
+ props.config.type,
+ props.config.secret
+ );
}
- };
+ }, TEXT_VALIDATION_DELAY);
+ }
+};
- const applicationIdErrorDescription = computed((): string => {
- if (props.config.type === ExternalVersionControl_Type.GITLAB) {
- return t(
- "gitops.setting.add-git-provider.oauth-info.gitlab-application-id-error"
- );
- } else if (props.config.type === ExternalVersionControl_Type.GITHUB) {
- return t(
- "gitops.setting.add-git-provider.oauth-info.github-application-id-error"
- );
- } else if (props.config.type === ExternalVersionControl_Type.BITBUCKET) {
- return t(
- "gitops.setting.add-git-provider.oauth-info.bitbucket-application-id-error"
- );
- }
- return "";
- });
+const applicationIdErrorDescription = computed((): string => {
+ if (props.config.type === ExternalVersionControl_Type.GITLAB) {
+ return t(
+ "gitops.setting.add-git-provider.oauth-info.gitlab-application-id-error"
+ );
+ } else if (props.config.type === ExternalVersionControl_Type.GITHUB) {
+ return t(
+ "gitops.setting.add-git-provider.oauth-info.github-application-id-error"
+ );
+ } else if (props.config.type === ExternalVersionControl_Type.BITBUCKET) {
+ return t(
+ "gitops.setting.add-git-provider.oauth-info.bitbucket-application-id-error"
+ );
+ }
+ return "";
+});
- const secretErrorDescription = computed((): string => {
- if (props.config.type === ExternalVersionControl_Type.GITLAB) {
- return t(
- "gitops.setting.add-git-provider.oauth-info.gitlab-secret-error"
- );
- } else if (props.config.type === ExternalVersionControl_Type.GITHUB) {
- return t(
- "gitops.setting.add-git-provider.oauth-info.github-secret-error"
- );
- } else if (props.config.type === ExternalVersionControl_Type.BITBUCKET) {
- return t(
- "gitops.setting.add-git-provider.oauth-info.bitbucket-secret-error"
- );
- }
- return "";
- });
+const secretErrorDescription = computed((): string => {
+ if (props.config.type === ExternalVersionControl_Type.GITLAB) {
+ return t("gitops.setting.add-git-provider.oauth-info.gitlab-secret-error");
+ } else if (props.config.type === ExternalVersionControl_Type.GITHUB) {
+ return t("gitops.setting.add-git-provider.oauth-info.github-secret-error");
+ } else if (props.config.type === ExternalVersionControl_Type.BITBUCKET) {
+ return t(
+ "gitops.setting.add-git-provider.oauth-info.bitbucket-secret-error"
+ );
+ }
+ return "";
+});
- return {
- redirectUrl,
- state,
- createOAuthApplicationUrl,
- copyHomepageURL,
- copyRedirectURI,
- changeApplicationId,
- changeSecret,
- applicationIdErrorDescription,
- secretErrorDescription,
- };
- },
+const secretField = computed(() => {
+ if (props.config.type === ExternalVersionControl_Type.AZURE_DEVOPS) {
+ return "Client Secret";
+ }
+ return "Secret";
});
</script>
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index fd9e788139..79ffc4f03a 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -3269,11 +3269,6 @@
"create": "New table group",
"edit": "Edit table group"
},
- "factor": {
- "resource_instance_id": "Instance ID",
- "resource_database_name": "Database name",
- "resource_table_name": "Table name"
- },
"condition": {
"self": "Condition"
},
@@ -3339,7 +3334,10 @@
"export_rows": "Export rows",
"table_name": "Table name",
"column_name": "Column name",
- "classification_level": "Classification level"
+ "classification_level": "Classification level",
+ "resource_instance_id": "Instance ID",
+ "resource_database_name": "Database name",
+ "resource_table_name": "Table name"
}
},
"changelist": {
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index c0fd66dc3b..bb244d4677 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -3266,11 +3266,6 @@
"create": "Crear grupo de tablas",
"edit": "Editar grupo de tablas"
},
- "factor": {
- "resource_instance_id": "ID de instancia",
- "resource_database_name": "Nombre de la base de datos",
- "resource_table_name": "Nombre de la tabla"
- },
"condition": {
"self": "Condición"
},
@@ -3337,7 +3332,10 @@
"export_rows": "Exportar filas",
"table_name": "Nombre de la tabla",
"column_name": "Nombre de columna",
- "classification_level": "Nivel de clasificación"
+ "classification_level": "Nivel de clasificación",
+ "resource_instance_id": "ID de instancia",
+ "resource_database_name": "Nombre de la base de datos",
+ "resource_table_name": "Nombre de la tabla"
}
},
"changelist": {
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 5ba1615b30..b88bc423e9 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -3267,11 +3267,6 @@
"create": "新しいテーブルグループ",
"edit": "テーブルグループを編集する"
},
- "factor": {
- "resource_instance_id": "インスタンスID",
- "resource_database_name": "データベース名",
- "resource_table_name": "テーブル名"
- },
"condition": {
"self": "条件"
},
@@ -3337,7 +3332,10 @@
"export_rows": "エクスポートする行数",
"table_name": "テーブル名",
"column_name": "カラム名",
- "classification_level": "分類レベル"
+ "classification_level": "分類レベル",
+ "resource_instance_id": "インスタンスID",
+ "resource_database_name": "データベース名",
+ "resource_table_name": "テーブル名"
}
},
"changelist": {
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 80ce7affae..d672ed9e6b 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -3269,11 +3269,6 @@
"create": "Nhóm bảng mới",
"edit": "Chỉnh sửa nhóm bảng"
},
- "factor": {
- "resource_instance_id": "ID phiên bản",
- "resource_database_name": "Tên cơ sở dữ liệu",
- "resource_table_name": "Tên bảng"
- },
"condition": {
"self": "Tình trạng"
},
@@ -3339,7 +3334,10 @@
"export_rows": "Xuất hàng",
"table_name": "Tên bảng",
"column_name": "Tên cột dọc",
- "classification_level": "Cấp độ phân loại"
+ "classification_level": "Cấp độ phân loại",
+ "resource_instance_id": "ID phiên bản",
+ "resource_database_name": "Tên cơ sở dữ liệu",
+ "resource_table_name": "Tên bảng"
}
},
"changelist": {
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index d0c9307e40..d1e9b8b2e7 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -3262,11 +3262,6 @@
"create": "新建表分组",
"edit": "编辑表分组"
},
- "factor": {
- "resource_instance_id": "实例 ID",
- "resource_database_name": "数据库名",
- "resource_table_name": "表名"
- },
"condition": {
"self": "条件"
},
@@ -3332,7 +3327,10 @@
"export_rows": "导出行数",
"table_name": "表名称",
"column_name": "字段名称",
- "classification_level": "数据分级"
+ "classification_level": "数据分级",
+ "resource_instance_id": "实例 ID",
+ "resource_database_name": "数据库名",
+ "resource_table_name": "表名"
}
},
"changelist": {
diff --git a/frontend/src/views/DatabaseGroupDetail.vue b/frontend/src/views/DatabaseGroupDetail.vue
index ac98928f5b..d7215531f2 100644
--- a/frontend/src/views/DatabaseGroupDetail.vue
+++ b/frontend/src/views/DatabaseGroupDetail.vue
@@ -86,7 +86,9 @@
<ExprEditor
:expr="state.expr!"
:allow-admin="false"
- :resource-type="'DATABASE_GROUP'"
+ :factor-list="FactorList.get('DATABASE_GROUP') ?? []"
+ :factor-support-dropdown="[]"
+ :factor-options-map="new Map()"
/>
</div>
<div class="col-span-2">
@@ -139,8 +141,8 @@ import DatabaseGroupPrevEditorModal from "@/components/AlterSchemaPrepForm/Datab
import DatabaseGroupPanel from "@/components/DatabaseGroup/DatabaseGroupPanel.vue";
import MatchedDatabaseView from "@/components/DatabaseGroup/MatchedDatabaseView.vue";
import SchemaGroupTable from "@/components/DatabaseGroup/SchemaGroupTable.vue";
-import ExprEditor from "@/components/DatabaseGroup/common/ExprEditor";
-import { ResourceType } from "@/components/DatabaseGroup/common/ExprEditor/context";
+import { FactorList, ResourceType } from "@/components/DatabaseGroup/utils";
+import ExprEditor from "@/components/ExprEditor";
import { ConditionGroupExpr } from "@/plugins/cel";
import {
useCurrentUserV1,
diff --git a/frontend/src/views/SchemaGroupDetail.vue b/frontend/src/views/SchemaGroupDetail.vue
index a918e182e0..1f87dce1ec 100644
--- a/frontend/src/views/SchemaGroupDetail.vue
+++ b/frontend/src/views/SchemaGroupDetail.vue
@@ -74,7 +74,9 @@
<ExprEditor
:expr="state.expr!"
:allow-admin="false"
- :resource-type="'SCHEMA_GROUP'"
+ :factor-list="FactorList.get('SCHEMA_GROUP') ?? []"
+ :factor-support-dropdown="[]"
+ :factor-options-map="new Map()"
/>
</div>
<div class="col-span-2">
@@ -102,7 +104,8 @@ import { useDebounceFn } from "@vueuse/core";
import { reactive, computed, watch, ref } from "vue";
import DatabaseGroupPanel from "@/components/DatabaseGroup/DatabaseGroupPanel.vue";
import MatchedTableView from "@/components/DatabaseGroup/MatchedTableView.vue";
-import ExprEditor from "@/components/DatabaseGroup/common/ExprEditor";
+import { FactorList } from "@/components/DatabaseGroup/utils";
+import ExprEditor from "@/components/ExprEditor";
import DatabaseGroupName from "@/components/v2/Model/DatabaseGroupName.vue";
import { ConditionGroupExpr } from "@/plugins/cel";
import {