Skip to content

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

refactor: simplify the resource id validation (#15990)

ecmadaoa378209146ea
diff --git a/frontend/src/components/Changelist/ChangelistDashboard/CreateChangelistPanel.vue b/frontend/src/components/Changelist/ChangelistDashboard/CreateChangelistPanel.vue
index 049d9b5863..6e0eaf94bc 100644
--- a/frontend/src/components/Changelist/ChangelistDashboard/CreateChangelistPanel.vue
+++ b/frontend/src/components/Changelist/ChangelistDashboard/CreateChangelistPanel.vue
@@ -42,7 +42,13 @@
v-model:value="resourceId"
resource-type="changelist"
:resource-title="title"
- :validate="validateResourceId"
+ :fetch-resource="
+ (resourceId: ResourceId) =>
+ changelistStore.getOrFetchChangelistByName(
+ `${projectName}/changelists/${resourceId}`,
+ true /* silent */
+ )
+ "
/>
</div>
</div>
@@ -144,7 +150,6 @@ import {
type UploadFileInfo,
NSelect,
} from "naive-ui";
-import { Status } from "nice-grpc-common";
import { zindexable as vZindexable } from "vdirs";
import { computed, reactive, ref, watch } from "vue";
import { useI18n } from "vue-i18n";
@@ -158,7 +163,7 @@ import {
ResourceIdField,
} from "@/components/v2";
import { pushNotification, useChangelistStore, useSheetV1Store } from "@/store";
-import type { ResourceId, ValidatedMessage } from "@/types";
+import type { ResourceId } from "@/types";
import type { ComposedProject } from "@/types";
import {
Changelist,
@@ -172,7 +177,6 @@ import {
setSheetStatement,
type Encoding,
} from "@/utils";
-import { getErrorCode } from "@/utils/grpcweb";
import { readUpload, type ParsedFile } from "../import";
import { useChangelistDashboardContext } from "./context";
@@ -197,6 +201,7 @@ const projectName = ref<string>(props.project.name);
const isLoading = ref(false);
const resourceId = ref("");
const resourceIdField = ref<InstanceType<typeof ResourceIdField>>();
+const changelistStore = useChangelistStore();
const encodingOptions = computed(() =>
ENCODINGS.map((encoding) => ({
@@ -217,38 +222,6 @@ const errors = asyncComputed(() => {
return errors;
}, []);
-const validateResourceId = async (
- resourceId: ResourceId
-): Promise<ValidatedMessage[]> => {
- if (!resourceId) {
- return [];
- }
-
- try {
- const name = `${projectName.value}/changelists/${resourceId}`;
- const maybeExistedChangelist =
- await useChangelistStore().getOrFetchChangelistByName(
- name,
- true /* silent */
- );
- if (maybeExistedChangelist) {
- return [
- {
- type: "error",
- message: t("resource-id.validation.duplicated", {
- resource: t("resource.changelist"),
- }),
- },
- ];
- }
- } catch (error) {
- if (getErrorCode(error) !== Status.NOT_FOUND) {
- throw error;
- }
- }
- return [];
-};
-
const uploadFileList = ref<UploadFileInfo[]>([]);
const files = ref<ParsedFile[]>([]);
const isParsingUploadFile = ref(false);
diff --git a/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue b/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue
index 998340b293..c34ca278c7 100644
--- a/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue
+++ b/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue
@@ -12,7 +12,13 @@
:readonly="!isCreating"
:value="state.resourceId"
:resource-title="state.placeholder"
- :validate="validateResourceId"
+ :fetch-resource="
+ (id) =>
+ dbGroupStore.getOrFetchDBGroupByName(
+ `${props.project.name}/${databaseGroupNamePrefix}${id}`,
+ { silent: true }
+ )
+ "
/>
</div>
</div>
@@ -62,7 +68,6 @@
import { cloneDeep, head, isEqual } from "lodash-es";
import { Trash2Icon } from "lucide-vue-next";
import { NButton, NDivider, NInput, useDialog } from "naive-ui";
-import { Status } from "nice-grpc-web";
import { computed, onMounted, reactive, ref } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
@@ -83,12 +88,11 @@ import {
databaseGroupNamePrefix,
getProjectNameAndDatabaseGroupName,
} from "@/store/modules/v1/common";
-import type { ComposedProject, ResourceId, ValidatedMessage } from "@/types";
+import type { ComposedProject } from "@/types";
import { Expr as CELExpr } from "@/types/proto/google/api/expr/v1alpha1/syntax";
import { Expr } from "@/types/proto/google/type/expr";
import type { DatabaseGroup } from "@/types/proto/v1/database_group_service";
import { batchConvertParsedExprToCELString } from "@/utils";
-import { getErrorCode } from "@/utils/grpcweb";
import { ResourceIdField } from "../v2";
import MatchedDatabaseView from "./MatchedDatabaseView.vue";
import {
@@ -149,43 +153,6 @@ onMounted(async () => {
}
});
-const validateResourceId = async (
- resourceId: ResourceId
-): Promise<ValidatedMessage[]> => {
- if (!resourceId) {
- return [];
- }
-
- const request = dbGroupStore.getOrFetchDBGroupByName(
- `${props.project.name}/${databaseGroupNamePrefix}${resourceId}`,
- { silent: true }
- );
-
- if (!request) {
- return [];
- }
-
- try {
- const data = await request;
- if (data) {
- return [
- {
- type: "error",
- message: t("resource-id.validation.duplicated", {
- resource: t(`resource.database-group`),
- }),
- },
- ];
- }
- } catch (error) {
- if (getErrorCode(error) !== Status.NOT_FOUND) {
- throw error;
- }
- }
-
- return [];
-};
-
const doDelete = () => {
dialog.error({
title: "Confirm to delete",
diff --git a/frontend/src/components/EnvironmentForm/Form.vue b/frontend/src/components/EnvironmentForm/Form.vue
index a130406c80..e0841dc992 100644
--- a/frontend/src/components/EnvironmentForm/Form.vue
+++ b/frontend/src/components/EnvironmentForm/Form.vue
@@ -23,7 +23,13 @@
:readonly="!create"
:value="state.environment.id"
:resource-title="state.environment.title"
- :validate="validateResourceId"
+ :fetch-resource="
+ (id) =>
+ environmentStore.getOrFetchEnvironmentByName(
+ `${environmentNamePrefix}${id}`,
+ true /* silent */
+ )
+ "
/>
</div>
@@ -129,7 +135,6 @@
<script lang="tsx" setup>
import { NCheckbox, NInput, NColorPicker } from "naive-ui";
-import { Status } from "nice-grpc-common";
import { computed, ref, watch } from "vue";
import { useI18n } from "vue-i18n";
import { BBButtonConfirm } from "@/bbkit";
@@ -141,8 +146,6 @@ import {
pushNotification,
} from "@/store";
import { environmentNamePrefix } from "@/store/modules/v1/common";
-import type { ResourceId, ValidatedMessage } from "@/types";
-import { getErrorCode } from "@/utils/grpcweb";
import { FeatureBadge } from "../FeatureGuard";
import SQLReviewForResource from "../SQLReview/components/SQLReviewForResource.vue";
import { ResourceIdField } from "../v2";
@@ -180,6 +183,7 @@ const {
resourceIdField,
} = useEnvironmentFormContext();
const environmentList = useEnvironmentV1List();
+const environmentStore = useEnvironmentV1Store();
const accessControlConfigureRef =
ref<InstanceType<typeof AccessControlConfigure>>();
@@ -246,36 +250,6 @@ const renderColorPicker = () => {
);
};
-const validateResourceId = async (
- resourceId: ResourceId
-): Promise<ValidatedMessage[]> => {
- if (!resourceId) {
- return [];
- }
-
- try {
- const env = await useEnvironmentV1Store().getOrFetchEnvironmentByName(
- environmentNamePrefix + resourceId,
- true /* silent */
- );
- if (env) {
- return [
- {
- type: "error",
- message: t("resource-id.validation.duplicated", {
- resource: t("resource.environment"),
- }),
- },
- ];
- }
- } catch (error) {
- if (getErrorCode(error) !== Status.NOT_FOUND) {
- throw error;
- }
- }
- return [];
-};
-
const deleteEnvironment = () => {
events.emit("delete", state.value.environment);
};
diff --git a/frontend/src/components/InstanceForm/Form.vue b/frontend/src/components/InstanceForm/Form.vue
index f62d699e1a..c000076fd7 100644
--- a/frontend/src/components/InstanceForm/Form.vue
+++ b/frontend/src/components/InstanceForm/Form.vue
@@ -73,7 +73,13 @@
resource-type="instance"
:readonly="!isCreating"
:resource-title="basicInfo.title"
- :validate="validateResourceId"
+ :fetch-resource="
+ (id) =>
+ instanceV1Store.getOrFetchInstanceByName(
+ `${instanceNamePrefix}${id}`,
+ true /* silent */
+ )
+ "
/>
</div>
@@ -86,7 +92,9 @@
class="mt-1 w-full"
required="true"
:environment-name="
- isValidEnvironmentName(`${environmentNamePrefix}${environment.id}`)
+ isValidEnvironmentName(
+ `${environmentNamePrefix}${environment.id}`
+ )
? `${environmentNamePrefix}${environment.id}`
: undefined
"
@@ -478,7 +486,6 @@ import {
NRadio,
NCheckbox,
} from "naive-ui";
-import { Status } from "nice-grpc-common";
import { computed, ref } from "vue";
import { useI18n } from "vue-i18n";
import { BBAttention, BBBetaBadge } from "@/bbkit";
@@ -497,8 +504,11 @@ import {
useSubscriptionV1Store,
pushNotification,
} from "@/store";
-import { environmentNamePrefix, instanceNamePrefix } from "@/store/modules/v1/common";
-import type { ResourceId, ValidatedMessage, ComposedInstance } from "@/types";
+import {
+ environmentNamePrefix,
+ instanceNamePrefix,
+} from "@/store/modules/v1/common";
+import type { ComposedInstance } from "@/types";
import { UNKNOWN_ID, isValidEnvironmentName } from "@/types";
import type { Duration } from "@/types/proto/google/protobuf/duration";
import { Engine } from "@/types/proto/v1/common";
@@ -512,7 +522,6 @@ import {
autoSubscriptionRoute,
urlfy,
} from "@/utils";
-import { getErrorCode } from "@/utils/grpcweb";
import LearnMoreLink from "../LearnMoreLink.vue";
import BigQueryHostInput from "./BigQueryHostInput.vue";
import DataSourceSection from "./DataSourceSection/DataSourceSection.vue";
@@ -723,36 +732,6 @@ const addDSAdditionalAddress = () => {
}
};
-const validateResourceId = async (
- resourceId: ResourceId
-): Promise<ValidatedMessage[]> => {
- if (!resourceId) {
- return [];
- }
-
- try {
- const instance = await instanceV1Store.getOrFetchInstanceByName(
- instanceNamePrefix + resourceId,
- true /* silent */
- );
- if (instance) {
- return [
- {
- type: "error",
- message: t("resource-id.validation.duplicated", {
- resource: t("resource.instance"),
- }),
- },
- ];
- }
- } catch (error) {
- if (getErrorCode(error) !== Status.NOT_FOUND) {
- throw error;
- }
- }
- return [];
-};
-
const changeInstanceActivation = async (on: boolean) => {
basicInfo.value.activation = on;
if (instance.value) {
diff --git a/frontend/src/components/Plan/components/SpecListSection/SpecCard.vue b/frontend/src/components/Plan/components/SpecListSection/SpecCard.vue
index 4ab857d8f8..af63d5b8e0 100644
--- a/frontend/src/components/Plan/components/SpecListSection/SpecCard.vue
+++ b/frontend/src/components/Plan/components/SpecListSection/SpecCard.vue
@@ -50,7 +50,7 @@
>
<NTooltip>
<template #trigger><DatabaseGroupIcon class="w-4 h-auto" /></template>
- {{ $t("resource.database-group") }}
+ {{ $t("dynamic.resource.database-group") }}
</NTooltip>
<span class="truncate text-sm">{{
relatedDatabaseGroup.databaseGroupName
diff --git a/frontend/src/components/Project/ProjectCreatePanel.vue b/frontend/src/components/Project/ProjectCreatePanel.vue
index 4a37feede6..72d3e009ea 100644
--- a/frontend/src/components/Project/ProjectCreatePanel.vue
+++ b/frontend/src/components/Project/ProjectCreatePanel.vue
@@ -25,7 +25,13 @@
resource-type="project"
:value="state.resourceId"
:resource-title="state.project.title"
- :validate="validateResourceId"
+ :fetch-resource="
+ (id) =>
+ projectV1Store.getOrFetchProjectByName(
+ `${projectNamePrefix}${id}`,
+ true /* silent */
+ )
+ "
@update:value="state.resourceId = $event"
/>
</div>
@@ -59,7 +65,6 @@
<script lang="ts" setup>
import { isEmpty } from "lodash-es";
import { NButton } from "naive-ui";
-import { Status } from "nice-grpc-common";
import { computed, reactive, ref } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
@@ -69,11 +74,10 @@ import ResourceIdField from "@/components/v2/Form/ResourceIdField.vue";
import { pushNotification, useUIStateStore } from "@/store";
import { projectNamePrefix } from "@/store/modules/v1/common";
import { useProjectV1Store } from "@/store/modules/v1/project";
-import type { ResourceId, ValidatedMessage, ComposedProject } from "@/types";
+import type { ComposedProject } from "@/types";
import { emptyProject } from "@/types";
import type { Project } from "@/types/proto/v1/project_service";
import { hasWorkspacePermissionV2 } from "@/utils";
-import { getErrorCode } from "@/utils/grpcweb";
interface LocalState {
project: Project;
@@ -106,37 +110,6 @@ const state = reactive<LocalState>({
});
const resourceIdField = ref<InstanceType<typeof ResourceIdField>>();
-const validateResourceId = async (
- resourceId: ResourceId
-): Promise<ValidatedMessage[]> => {
- if (!resourceId) {
- return [];
- }
-
- try {
- const project = await projectV1Store.getOrFetchProjectByName(
- projectNamePrefix + resourceId,
- true /* silent */
- );
- if (project) {
- return [
- {
- type: "error",
- message: t("resource-id.validation.duplicated", {
- resource: t("resource.project"),
- }),
- },
- ];
- }
- } catch (error) {
- if (getErrorCode(error) !== Status.NOT_FOUND) {
- throw error;
- }
- }
-
- return [];
-};
-
const allowCreate = computed(() => {
if (isEmpty(state.project.title)) return false;
if (!resourceIdField.value?.isValidated) return false;
diff --git a/frontend/src/components/SQLReview/SQLReviewInfo.vue b/frontend/src/components/SQLReview/SQLReviewInfo.vue
index ec557b0661..7999ba1237 100644
--- a/frontend/src/components/SQLReview/SQLReviewInfo.vue
+++ b/frontend/src/components/SQLReview/SQLReviewInfo.vue
@@ -26,7 +26,10 @@
name="environment"
:environment-name="attachedResources[0]"
:disabled="!allowChangeAttachedResource"
- :filter="(env: Environment, _: number) => filterResource(formatEnvironmentName(env.id))"
+ :filter="
+ (env: Environment, _: number) =>
+ filterResource(formatEnvironmentName(env.id))
+ "
@update:environment-name="
(val: string | undefined) => {
if (!val) {
@@ -91,7 +94,13 @@
:readonly="!isCreate"
:resource-title="name"
:suffix="true"
- :validate="validateResourceId"
+ :fetch-resource="
+ (id) =>
+ sqlReviewStore.fetchReviewPolicyByName({
+ name: `${reviewConfigNamePrefix}${id}`,
+ silent: true,
+ })
+ "
@update:value="emit('resource-id-change', $event)"
/>
</div>
@@ -107,22 +116,18 @@
<script lang="ts" setup>
import { NRadio, NRadioGroup } from "naive-ui";
-import { Status } from "nice-grpc-common";
import { ref, watch, computed } from "vue";
-import { useI18n } from "vue-i18n";
import { BBAttention, BBTextField } from "@/bbkit";
import ResourceIdField from "@/components/v2/Form/ResourceIdField.vue";
import { useResourceByName } from "@/components/v2/ResourceOccupiedModal/useResourceByName";
import { useSQLReviewStore } from "@/store";
import { reviewConfigNamePrefix } from "@/store/modules/v1/common";
-import type {
- SQLReviewPolicyTemplateV2,
- ResourceId,
- ValidatedMessage,
-} from "@/types";
+import type { SQLReviewPolicyTemplateV2 } from "@/types";
import type { Database } from "@/types/proto/v1/database_service";
-import { formatEnvironmentName, type Environment } from "@/types/v1/environment";
-import { getErrorCode } from "@/utils/grpcweb";
+import {
+ formatEnvironmentName,
+ type Environment,
+} from "@/types/v1/environment";
import { DatabaseSelect, EnvironmentSelect, ProjectSelect } from "../v2";
import { SQLReviewTemplateSelector } from "./components";
@@ -147,7 +152,6 @@ const sqlReviewStore = useSQLReviewStore();
const { resourceType } = useResourceByName({
resource: computed(() => props.attachedResources[0] ?? ""),
});
-const { t } = useI18n();
watch(
() => resourceType.value,
@@ -162,35 +166,4 @@ const filterResource = (name: string): boolean => {
};
const resourceIdField = ref<InstanceType<typeof ResourceIdField>>();
-
-const validateResourceId = async (
- resourceId: ResourceId
-): Promise<ValidatedMessage[]> => {
- if (!resourceId) {
- return [];
- }
-
- try {
- const existed = await sqlReviewStore.fetchReviewPolicyByName({
- name: `${reviewConfigNamePrefix}${resourceId}`,
- silent: true,
- });
- if (existed) {
- return [
- {
- type: "error",
- message: t("resource-id.validation.duplicated", {
- resource: t("resource.review-config"),
- }),
- },
- ];
- }
- } catch (error) {
- if (getErrorCode(error) !== Status.NOT_FOUND) {
- throw error;
- }
- }
-
- return [];
-};
</script>
diff --git a/frontend/src/components/SSO/IdentityProviderCreateForm.vue b/frontend/src/components/SSO/IdentityProviderCreateForm.vue
index 0114f18cbc..85bc26dea6 100644
--- a/frontend/src/components/SSO/IdentityProviderCreateForm.vue
+++ b/frontend/src/components/SSO/IdentityProviderCreateForm.vue
@@ -167,7 +167,13 @@
:value="resourceId"
:suffix="true"
:resource-title="identityProvider.title"
- :validate="validateResourceId"
+ :fetch-resource="
+ (id) =>
+ identityProviderStore.getOrFetchIdentityProviderByName(
+ `${idpNamePrefix}${id}`,
+ true /* silent */
+ )
+ "
/>
</div>
<div class="w-full flex flex-col justify-start items-start">
@@ -637,10 +643,7 @@
</div>
</div>
<div class="mt-4">
- <NButton
- :disabled="!allowTestConnection"
- @click="testConnection"
- >
+ <NButton :disabled="!allowTestConnection" @click="testConnection">
{{ $t("identity-provider.test-connection") }}
</NButton>
</div>
@@ -662,9 +665,7 @@
/>
</template>
</div>
- <div
- class="space-x-3 flex flex-row justify-end items-center"
- >
+ <div class="space-x-3 flex flex-row justify-end items-center">
<template v-if="isCreating">
<NButton @click="handleCancelButtonClick">
{{ $t("common.cancel") }}
@@ -706,9 +707,7 @@ import {
NButton,
} from "naive-ui";
import type { ClientError } from "nice-grpc-common";
-import { Status } from "nice-grpc-common";
import { computed, reactive, ref, onMounted, watch } from "vue";
-import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import { BBAttention, BBButtonConfirm, BBTextField } from "@/bbkit";
import ResourceIdField from "@/components/v2/Form/ResourceIdField.vue";
@@ -726,11 +725,7 @@ import {
getIdentityProviderResourceId,
idpNamePrefix,
} from "@/store/modules/v1/common";
-import type {
- OAuthWindowEventPayload,
- ResourceId,
- ValidatedMessage,
-} from "@/types";
+import type { OAuthWindowEventPayload } from "@/types";
import { planTypeToString } from "@/types";
import {
FieldMapping,
@@ -749,7 +744,6 @@ import {
identityProviderTypeToString,
openWindowForSSO,
} from "@/utils";
-import { getErrorCode } from "@/utils/grpcweb";
import IdentityProviderExternalURL from "./IdentityProviderExternalURL.vue";
interface IdentityProviderTemplate extends OAuth2IdentityProviderTemplate {
@@ -769,7 +763,6 @@ const props = defineProps<{
onCanceled?: () => void;
}>();
-const { t } = useI18n();
const router = useRouter();
const identityProviderStore = useIdentityProviderStore();
const subscriptionStore = useSubscriptionV1Store();
@@ -1150,36 +1143,6 @@ const loginWithIdentityProviderEventListener = async (event: Event) => {
});
};
-const validateResourceId = async (
- resourceId: ResourceId
-): Promise<ValidatedMessage[]> => {
- if (!resourceId) {
- return [];
- }
-
- try {
- const idp = await identityProviderStore.getOrFetchIdentityProviderByName(
- idpNamePrefix + resourceId,
- true /* silent */
- );
- if (idp) {
- return [
- {
- type: "error",
- message: t("resource-id.validation.duplicated", {
- resource: t("resource.idp"),
- }),
- },
- ];
- }
- } catch (error) {
- if (getErrorCode(error) !== Status.NOT_FOUND) {
- throw error;
- }
- }
- return [];
-};
-
const testConnection = async () => {
if (
state.type === IdentityProviderType.OAUTH2 ||
diff --git a/frontend/src/components/v2/Form/ResourceIdField.vue b/frontend/src/components/v2/Form/ResourceIdField.vue
index 0edda9c1b9..6c745fccae 100644
--- a/frontend/src/components/v2/Form/ResourceIdField.vue
+++ b/frontend/src/components/v2/Form/ResourceIdField.vue
@@ -1,13 +1,18 @@
<template>
<div v-if="visible">
<template v-if="readonly || !state.manualEdit">
- <div v-if="state.resourceId" class="textinfolabel text-sm">
+ <div class="textinfolabel text-sm space-x-1">
{{ $t("resource-id.self", { resource: resourceName }) }}:
- <span class="text-gray-600 font-medium mr-1">{{
- state.resourceId
- }}</span>
+ <span v-if="state.resourceId" class="text-gray-600 font-medium mr-1">
+ {{ state.resourceId }}
+ </span>
+ <span v-else class="text-control-placeholder italic">
+ {{ "<EMPTY>" }}
+ </span>
<template v-if="!readonly">
- {{ $t("resource-id.cannot-be-changed-later") }}
+ <span>
+ {{ $t("resource-id.cannot-be-changed-later") }}
+ </span>
<span
class="text-accent font-medium cursor-pointer hover:opacity-80"
@click="state.manualEdit = true"
@@ -28,6 +33,7 @@
<NInput
:value="state.resourceId"
:status="inputStatus"
+ :placeholder="$t('resource-id.self', { resource: resourceName })"
v-bind="inputProps"
@update:value="handleResourceIdInput($event)"
/>
@@ -53,10 +59,12 @@
<script lang="ts" setup>
import { NInput, type InputProps } from "naive-ui";
+import { Status } from "nice-grpc-common";
import { computed, reactive, watch } from "vue";
import { useI18n } from "vue-i18n";
import type { ResourceId, ValidatedMessage } from "@/types";
import { randomString } from "@/utils";
+import { getErrorCode } from "@/utils/grpcweb";
// characters is the validated characters for resource id.
const characters = "abcdefghijklmnopqrstuvwxyz1234567890-";
@@ -99,6 +107,8 @@ const props = withDefaults(
inputProps?: Partial<InputProps>;
editingClass?: string;
validate?: (resourceId: ResourceId) => Promise<ValidatedMessage[]>;
+ // fetchResource will be used to check if the resource id is duplicate.
+ fetchResource?: (resourceId: ResourceId) => Promise<any>;
}>(),
{
value: "",
@@ -126,11 +136,11 @@ let initialized = false;
const randomSuffix = randomString(4).toLowerCase();
const resourceName = computed(() => {
- return t(`resource.${props.resourceType}`);
+ return t(`dynamic.resource.${props.resourceType}`);
});
const visible = computed(() => {
- if (props.readonly || !state.manualEdit) {
+ if (props.readonly) {
return !!state.resourceId;
}
return true;
@@ -158,13 +168,15 @@ const handleResourceIdChange = async (newValue: string) => {
emit("update:value", newValue);
- // if the resource id is empty, do not validate.
- if (newValue === "" && !state.manualEdit) {
- return;
- }
-
// common validation for resource id (min length, max length, pattern).
- if (state.resourceId.length < 1) {
+ if (state.resourceId === "") {
+ state.validatedMessages.push({
+ type: "error",
+ message: t("resource-id.validation.empty", {
+ resource: resourceName.value,
+ }),
+ });
+ } else if (state.resourceId.length < 1) {
state.validatedMessages.push({
type: "error",
message: t("resource-id.validation.minlength", {
@@ -194,6 +206,24 @@ const handleResourceIdChange = async (newValue: string) => {
state.validatedMessages.push(...messages);
}
}
+
+ if (props.fetchResource && state.resourceId) {
+ try {
+ const resource = await props.fetchResource(state.resourceId);
+ if (resource) {
+ state.validatedMessages.push({
+ type: "error",
+ message: t("resource-id.validation.duplicated", {
+ resource: resourceName.value,
+ }),
+ });
+ }
+ } catch (error) {
+ if (getErrorCode(error) !== Status.NOT_FOUND) {
+ throw error;
+ }
+ }
+ }
};
watch(
diff --git a/frontend/src/locales/dynamic/en-US.json b/frontend/src/locales/dynamic/en-US.json
index e63094250f..c080e352c8 100644
--- a/frontend/src/locales/dynamic/en-US.json
+++ b/frontend/src/locales/dynamic/en-US.json
@@ -251,5 +251,14 @@
"desc": "Restrict sign-in to users with email addresses from the specified domains."
}
}
+ },
+ "resource": {
+ "environment": "Environment",
+ "instance": "Instance",
+ "project": "Project",
+ "idp": "Identity Provider",
+ "database-group": "Database Group",
+ "changelist": "Changelist",
+ "review-config": "Review Config"
}
}
diff --git a/frontend/src/locales/dynamic/es-ES.json b/frontend/src/locales/dynamic/es-ES.json
index fad42fd061..5f0467d33a 100644
--- a/frontend/src/locales/dynamic/es-ES.json
+++ b/frontend/src/locales/dynamic/es-ES.json
@@ -251,5 +251,14 @@
"desc": "Restrinja el inicio de sesión a usuarios con direcciones de correo electrónico de los dominios especificados."
}
}
+ },
+ "resource": {
+ "environment": "Entorno",
+ "instance": "Instancia",
+ "project": "Proyecto",
+ "idp": "Proveedor de Identidad",
+ "database-group": "grupo de bases de datos",
+ "changelist": "Lista de cambios",
+ "review-config": "Revisar configuración"
}
}
diff --git a/frontend/src/locales/dynamic/ja-JP.json b/frontend/src/locales/dynamic/ja-JP.json
index 9934f2863a..0c3bcd6721 100644
--- a/frontend/src/locales/dynamic/ja-JP.json
+++ b/frontend/src/locales/dynamic/ja-JP.json
@@ -251,5 +251,14 @@
"desc": "指定されたドメインの電子メール アドレスを持つユーザーのみにサインインを制限します。"
}
}
+ },
+ "resource": {
+ "environment": "環境",
+ "instance": "例",
+ "project": "プロジェクト",
+ "idp": "アイデンティティプロバイダー",
+ "database-group": "データベースのグループ化",
+ "changelist": "変更リスト",
+ "review-config": "設定を確認する"
}
}
diff --git a/frontend/src/locales/dynamic/vi-VN.json b/frontend/src/locales/dynamic/vi-VN.json
index 61bc51c2e6..eff926d1b1 100644
--- a/frontend/src/locales/dynamic/vi-VN.json
+++ b/frontend/src/locales/dynamic/vi-VN.json
@@ -251,5 +251,14 @@
"desc": "Hạn chế đăng nhập đối với người dùng có địa chỉ email từ các miền được chỉ định."
}
}
+ },
+ "resource": {
+ "environment": "Môi trường",
+ "instance": "Phiên bản",
+ "project": "Dự án",
+ "idp": "Nhà cung cấp danh tính",
+ "database-group": "Nhóm cơ sở dữ liệu",
+ "changelist": "Danh sách thay đổi",
+ "review-config": "Cấu hình đánh giá"
}
}
diff --git a/frontend/src/locales/dynamic/zh-CN.json b/frontend/src/locales/dynamic/zh-CN.json
index 7600b7e87d..27793365a7 100644
--- a/frontend/src/locales/dynamic/zh-CN.json
+++ b/frontend/src/locales/dynamic/zh-CN.json
@@ -251,5 +251,14 @@
"desc": "仅允许具有指定域名的电子邮箱的用户进行登录或注册。"
}
}
+ },
+ "resource": {
+ "environment": "环境",
+ "instance": "实例",
+ "project": "项目",
+ "idp": "身份提供商",
+ "database-group": "数据库分组",
+ "changelist": "变更列表",
+ "review-config": "审查配置"
}
}
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 118273d281..e09b7693c7 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -2142,13 +2142,6 @@
"self": "Sensitive Data"
},
"resource": {
- "environment": "Environment",
- "instance": "Instance",
- "project": "Project",
- "idp": "Identity Provider",
- "database-group": "Database Group",
- "changelist": "Changelist",
- "review-config": "Review Config",
"delete-warning": "The \"{name}\" will be deleted. This action cannot be undone.",
"delete-warning-with-resources": "The \"{name}\" is used by following resources:",
"delete-warning-retry": "Please remove it from these resources then retry again."
@@ -2161,7 +2154,8 @@
"duplicated": "The {resource} ID already exists. Please choose another one.",
"pattern": "The {resource} ID can have lowercase letters, digits, or hyphens. It must start with a lowercase letter and end with a letter or number.",
"minlength": "The {resource} ID is too short. It should have at least 1 character.",
- "overflow": "The {resource} ID is too long. It should have less than 64 characters."
+ "overflow": "The {resource} ID is too long. It should have less than 64 characters.",
+ "empty": "The {resource} ID cannot be empty"
}
},
"multi-factor": {
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 5fb8a8cf4e..3f416b4843 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -2142,13 +2142,6 @@
"self": "Datos Sensibles"
},
"resource": {
- "environment": "Entorno",
- "instance": "Instancia",
- "project": "Proyecto",
- "idp": "Proveedor de Identidad",
- "database-group": "grupo de bases de datos",
- "changelist": "Lista de cambios",
- "review-config": "Revisar configuración",
"delete-warning": "Se eliminará el elemento \"{name}\". Esta acción no se puede deshacer.",
"delete-warning-with-resources": "El \"{name}\" lo utilizan los siguientes recursos:",
"delete-warning-retry": "Elimínelo de estos recursos y vuelva a intentarlo."
@@ -2161,7 +2154,8 @@
"duplicated": "El ID de {resource} ya existe. Por favor, elige otro.",
"pattern": "La identificación {recurso} puede tener letras, dígitos o guiones minúsculas. Debe comenzar con una letra minúscula y terminar con una letra o número.",
"minlength": "El ID de {resource} es demasiado corto. Debe tener al menos 1 carácter.",
- "overflow": "El ID de {resource} es demasiado largo. Debe tener menos de 64 caracteres."
+ "overflow": "El ID de {resource} es demasiado largo. Debe tener menos de 64 caracteres.",
+ "empty": "El ID {resource} no puede estar vacío"
}
},
"multi-factor": {
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index fa31bd159a..af8a674936 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -2142,13 +2142,6 @@
"self": "機密データ"
},
"resource": {
- "environment": "環境",
- "instance": "例",
- "project": "プロジェクト",
- "idp": "アイデンティティプロバイダー",
- "database-group": "データベースのグループ化",
- "changelist": "変更リスト",
- "review-config": "設定を確認する",
"delete-warning": "「{name}」は削除されます。この操作は元に戻せません。",
"delete-warning-with-resources": "「{name}」は次のリソースによって使用されます:",
"delete-warning-retry": "これらのリソースから削除して、もう一度お試しください。"
@@ -2161,7 +2154,8 @@
"duplicated": "{resource} ID はすでに存在します。別のIDを使用してください。",
"pattern": "{resource} ID には、小文字、数字、またはハイフンを持つことができます。\n小文字から始めて、文字または番号で終わる必要があります。",
"minlength": "{resource} ID には少なくとも 1 文字が含まれている必要があります。",
- "overflow": "{resource} ID は 64 文字未満である必要があります。"
+ "overflow": "{resource} ID は 64 文字未満である必要があります。",
+ "empty": "{resource} ID は空にできません"
}
},
"multi-factor": {
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 7bc409f534..3279e3229b 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -2142,13 +2142,6 @@
"self": "Dữ liệu nhạy cảm"
},
"resource": {
- "environment": "Môi trường",
- "instance": "Phiên bản",
- "project": "Dự án",
- "idp": "Nhà cung cấp danh tính",
- "database-group": "Nhóm cơ sở dữ liệu",
- "changelist": "Danh sách thay đổi",
- "review-config": "Cấu hình đánh giá",
"delete-warning": "\"{name}\" sẽ bị xóa. Hành động này không thể hoàn tác.",
"delete-warning-with-resources": "\"{name}\" được sử dụng bởi các tài nguyên sau:",
"delete-warning-retry": "Vui lòng xóa nó khỏi các tài nguyên này rồi thử lại."
@@ -2161,7 +2154,8 @@
"duplicated": "ID {resource} đã tồn tại. Vui lòng chọn một ID khác.",
"pattern": "ID {resource} có thể có chữ thường, chữ số hoặc dấu gạch nối. \nNó phải bắt đầu với một chữ cái viết thường và kết thúc bằng một chữ cái hoặc số.",
"minlength": "ID {resource} quá ngắn. Nó phải có ít nhất 1 ký tự.",
- "overflow": "ID {resource} quá dài. Nó phải có ít hơn 64 ký tự."
+ "overflow": "ID {resource} quá dài. Nó phải có ít hơn 64 ký tự.",
+ "empty": "ID {resource} không được để trống"
}
},
"multi-factor": {
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 6711279dc0..ed58f604e8 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -2142,13 +2142,6 @@
"self": "敏感数据"
},
"resource": {
- "environment": "环境",
- "instance": "实例",
- "project": "项目",
- "idp": "身份提供商",
- "database-group": "数据库分组",
- "changelist": "变更列表",
- "review-config": "审查配置",
"delete-warning": "“{name}”将被删除。此操作无法撤消。",
"delete-warning-with-resources": "以下资源使用了“{name}”:",
"delete-warning-retry": "请将其从这些资源中删除,然后重试。"
@@ -2161,7 +2154,8 @@
"duplicated": "{resource} ID 已存在。请使用其他 ID。",
"pattern": "{resource} ID 可以具有小写字母,数字或连字符。\n它必须从小写字母开始,并以字母或数字结尾。",
"minlength": "{resource} ID 至少包含 1 个字符。",
- "overflow": "{resource} ID 应该少于 64 个字符。"
+ "overflow": "{resource} ID 应该少于 64 个字符。",
+ "empty": "{resource} ID 不能为空"
}
},
"multi-factor": {