Skip to content

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

chore: tab color for sql editor (#14401)

ecmadao3a60aad72356
diff --git a/backend/api/v1/environment_service.go b/backend/api/v1/environment_service.go
index dfac37e41a..03b7bef4d6 100644
--- a/backend/api/v1/environment_service.go
+++ b/backend/api/v1/environment_service.go
@@ -85,7 +85,7 @@ func (s *EnvironmentService) CreateEnvironment(ctx context.Context, request *v1p
Protected: request.Environment.Tier == v1pb.EnvironmentTier_PROTECTED,
Color: request.Environment.Color,
}
- if pendingCreate.Protected {
+ if pendingCreate.Protected || pendingCreate.Color != "" {
if err := s.licenseService.IsFeatureEnabled(api.FeatureEnvironmentTierPolicy); err != nil {
return nil, status.Error(codes.PermissionDenied, err.Error())
}
@@ -131,17 +131,18 @@ func (s *EnvironmentService) UpdateEnvironment(ctx context.Context, request *v1p
patch.Order = &request.Environment.Order
case "tier":
protected := request.Environment.Tier == v1pb.EnvironmentTier_PROTECTED
- if protected {
- if err := s.licenseService.IsFeatureEnabled(api.FeatureEnvironmentTierPolicy); err != nil {
- return nil, status.Error(codes.PermissionDenied, err.Error())
- }
- }
patch.Protected = &protected
case "color":
patch.Color = &request.Environment.Color
}
}
+ if patch.Protected != nil || patch.Color != nil {
+ if err := s.licenseService.IsFeatureEnabled(api.FeatureEnvironmentTierPolicy); err != nil {
+ return nil, status.Error(codes.PermissionDenied, err.Error())
+ }
+ }
+
environment, err = s.store.UpdateEnvironmentV2(ctx,
environment.ResourceID,
patch,
diff --git a/frontend/src/components/EnvironmentForm/Form.vue b/frontend/src/components/EnvironmentForm/Form.vue
index 22af920747..3739e9a9f0 100644
--- a/frontend/src/components/EnvironmentForm/Form.vue
+++ b/frontend/src/components/EnvironmentForm/Form.vue
@@ -144,7 +144,12 @@ import { Status } from "nice-grpc-common";
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { BBButtonConfirm } from "@/bbkit";
-import { useEnvironmentV1List, useEnvironmentV1Store } from "@/store";
+import {
+ useEnvironmentV1List,
+ useEnvironmentV1Store,
+ hasFeature,
+ pushNotification,
+} from "@/store";
import { environmentNamePrefix } from "@/store/modules/v1/common";
import type { ResourceId, ValidatedMessage } from "@/types";
import { State } from "@/types/proto/v1/common";
@@ -184,12 +189,17 @@ const {
state,
allowEdit,
valueChanged,
+ missingFeature,
hasPermission,
events,
resourceIdField,
} = useEnvironmentFormContext();
const environmentList = useEnvironmentV1List();
+const hasEnvironmentPolicyFeature = computed(() =>
+ hasFeature("bb.feature.environment-tier-policy")
+);
+
const allowArchive = computed(() => {
return (
hasPermission("bb.environments.delete") && environmentList.value.length > 1
@@ -216,6 +226,19 @@ const renderColorPicker = () => {
></div>
)}
onUpdateValue={(color: string) => {
+ if (!hasEnvironmentPolicyFeature.value) {
+ missingFeature.value = "bb.feature.environment-tier-policy";
+ return;
+ }
+ if (color.toUpperCase() === "#FFFFFF") {
+ pushNotification({
+ module: "bytebase",
+ style: "WARN",
+ title: t("common.warning"),
+ description: "Invalid color",
+ });
+ return;
+ }
state.value.environment.color = color;
}}
/>
diff --git a/frontend/src/views/sql-editor/EditorCommon/DatabaseChooser.vue b/frontend/src/views/sql-editor/EditorCommon/DatabaseChooser.vue
index 79a1e92cf2..668184fd68 100644
--- a/frontend/src/views/sql-editor/EditorCommon/DatabaseChooser.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/DatabaseChooser.vue
@@ -21,6 +21,11 @@
"
class="flex flex-row items-center text-main"
>
+ <EnvironmentV1Name
+ :environment="database.effectiveEnvironmentEntity"
+ :link="false"
+ />
+ <ChevronRightIcon class="shrink-0 h-4 w-4 text-control-light" />
<div class="flex items-center gap-1">
<InstanceV1EngineIcon
:instance="instance"
@@ -46,7 +51,7 @@ import { ChevronRightIcon } from "lucide-vue-next";
import { NButton } from "naive-ui";
import { storeToRefs } from "pinia";
import { DatabaseIcon } from "@/components/Icon";
-import { InstanceV1EngineIcon } from "@/components/v2";
+import { InstanceV1EngineIcon, EnvironmentV1Name } from "@/components/v2";
import {
useConnectionOfCurrentSQLEditorTab,
useSQLEditorStore,
diff --git a/frontend/src/views/sql-editor/TabList/TabItem/AdminLabel.vue b/frontend/src/views/sql-editor/TabList/TabItem/AdminLabel.vue
index b44c242006..b1649cef85 100644
--- a/frontend/src/views/sql-editor/TabList/TabItem/AdminLabel.vue
+++ b/frontend/src/views/sql-editor/TabList/TabItem/AdminLabel.vue
@@ -19,33 +19,30 @@
<script lang="ts" setup>
import { ChevronRightIcon } from "lucide-vue-next";
-import type { PropType } from "vue";
import { computed } from "vue";
import { EnvironmentV1Name } from "@/components/v2";
import { useAppFeature, useDatabaseV1Store } from "@/store";
-import type { SQLEditorTab } from "@/types";
+import { type SQLEditorTab, UNKNOWN_ENVIRONMENT_NAME } from "@/types";
import { isValidInstanceName, isValidDatabaseName } from "@/types";
-const props = defineProps({
- tab: {
- type: Object as PropType<SQLEditorTab>,
- required: true,
- },
- index: {
- type: Number,
- required: true,
- },
-});
+const props = defineProps<{
+ tab: SQLEditorTab;
+}>();
-const hideEnvironment = useAppFeature(
- "bb.feature.sql-editor.hide-environments"
-);
const connection = computed(() => props.tab.connection);
const database = computed(() => {
return useDatabaseV1Store().getDatabaseByName(connection.value.database);
});
+
const instance = computed(() => {
return database.value.instanceResource;
});
+
+const hideEnvironment = computed(() => {
+ return (
+ useAppFeature("bb.feature.sql-editor.hide-environments").value ||
+ database.value.effectiveEnvironmentEntity?.name === UNKNOWN_ENVIRONMENT_NAME
+ );
+});
</script>
diff --git a/frontend/src/views/sql-editor/TabList/TabItem/Label.vue b/frontend/src/views/sql-editor/TabList/TabItem/Label.vue
index a0c00053b0..ea52335107 100644
--- a/frontend/src/views/sql-editor/TabList/TabItem/Label.vue
+++ b/frontend/src/views/sql-editor/TabList/TabItem/Label.vue
@@ -26,7 +26,6 @@
</template>
<script lang="ts" setup>
import { NEllipsis } from "naive-ui";
-import type { PropType } from "vue";
import { computed, nextTick, reactive, ref, watch } from "vue";
import { useEmitteryEventListener } from "@/composables/useEmitteryEventListener";
import { useSQLEditorTabStore, useWorkSheetStore } from "@/store";
@@ -38,16 +37,9 @@ type LocalState = {
title: string;
};
-const props = defineProps({
- tab: {
- type: Object as PropType<SQLEditorTab>,
- required: true,
- },
- index: {
- type: Number,
- required: true,
- },
-});
+const props = defineProps<{
+ tab: SQLEditorTab;
+}>();
const state = reactive<LocalState>({
editing: false,
diff --git a/frontend/src/views/sql-editor/TabList/TabItem/Prefix.vue b/frontend/src/views/sql-editor/TabList/TabItem/Prefix.vue
index 35dfcee2aa..ab3332c6a9 100644
--- a/frontend/src/views/sql-editor/TabList/TabItem/Prefix.vue
+++ b/frontend/src/views/sql-editor/TabList/TabItem/Prefix.vue
@@ -14,23 +14,15 @@
<script lang="ts" setup>
import { WrenchIcon } from "lucide-vue-next";
-import type { PropType } from "vue";
import { computed } from "vue";
import { useWorkSheetStore } from "@/store";
import type { SQLEditorTab } from "@/types";
import { Worksheet_Visibility } from "@/types/proto/v1/worksheet_service";
import { SheetConnectionIcon } from "../../EditorCommon";
-const props = defineProps({
- tab: {
- type: Object as PropType<SQLEditorTab>,
- required: true,
- },
- index: {
- type: Number,
- required: true,
- },
-});
+const props = defineProps<{
+ tab: SQLEditorTab;
+}>();
const sheetV1Store = useWorkSheetStore();
diff --git a/frontend/src/views/sql-editor/TabList/TabItem/Suffix.vue b/frontend/src/views/sql-editor/TabList/TabItem/Suffix.vue
index 04ce17c510..23f158304f 100644
--- a/frontend/src/views/sql-editor/TabList/TabItem/Suffix.vue
+++ b/frontend/src/views/sql-editor/TabList/TabItem/Suffix.vue
@@ -15,14 +15,13 @@
<heroicons-solid:x
v-else-if="icon === 'close'"
class="icon close"
- @click.stop.prevent="$emit('close', tab, index)"
+ @click.stop.prevent="$emit('close')"
/>
<span v-else class="icon dummy"></span>
</div>
</template>
<script lang="ts" setup>
-import type { PropType } from "vue";
import { computed, reactive } from "vue";
import type { SQLEditorTab } from "@/types";
@@ -32,23 +31,16 @@ type LocalState = {
type IconType = "unsaved" | "close";
-const props = defineProps({
- tab: {
- type: Object as PropType<SQLEditorTab>,
- required: true,
- },
- index: {
- type: Number,
- required: true,
- },
-});
+const props = defineProps<{
+ tab: SQLEditorTab;
+}>();
const state = reactive<LocalState>({
hovering: false,
});
defineEmits<{
- (e: "close", tab: SQLEditorTab, index: number): void;
+ (e: "close"): void;
}>();
const icon = computed((): IconType | undefined => {
diff --git a/frontend/src/views/sql-editor/TabList/TabItem/TabItem.vue b/frontend/src/views/sql-editor/TabList/TabItem/TabItem.vue
index 069cc7362c..4733f61903 100644
--- a/frontend/src/views/sql-editor/TabList/TabItem/TabItem.vue
+++ b/frontend/src/views/sql-editor/TabList/TabItem/TabItem.vue
@@ -5,7 +5,6 @@
{
current: isCurrentTab,
hovering: state.hovering,
- admin: tab.mode === 'ADMIN',
},
tab.status.toLowerCase(),
]"
@@ -16,20 +15,31 @@
@mouseenter="state.hovering = true"
@mouseleave="state.hovering = false"
>
- <div class="body">
- <Prefix :tab="tab" :index="index" />
- <Label v-if="tab.mode === 'WORKSHEET'" :tab="tab" :index="index" />
- <AdminLabel v-else :tab="tab" :index="index" />
- <Suffix :tab="tab" :index="index" @close="$emit('close', tab, index)" />
+ <div
+ class="body"
+ :style="
+ backgroundColorRgb.length > 0
+ ? {
+ backgroundColor: `rgba(${backgroundColorRgb[0]}, ${backgroundColorRgb[1]}, ${backgroundColorRgb[2]}, 0.5)`,
+ borderTopColor: `rgb(${backgroundColorRgb[0]}, ${backgroundColorRgb[1]}, ${backgroundColorRgb[2]})`,
+ color: `rgb(${backgroundColorRgb[0]}, ${backgroundColorRgb[1]}, ${backgroundColorRgb[2]})`,
+ }
+ : {}
+ "
+ >
+ <Prefix :tab="tab" />
+ <Label v-if="tab.mode === 'WORKSHEET'" :tab="tab" />
+ <AdminLabel v-else :tab="tab" />
+ <Suffix :tab="tab" @close="$emit('close', tab, index)" />
</div>
</div>
</template>
<script lang="ts" setup>
-import type { PropType } from "vue";
import { computed, reactive } from "vue";
import { useSQLEditorTabStore } from "@/store";
-import type { SQLEditorTab } from "@/types";
+import { type SQLEditorTab, UNKNOWN_ENVIRONMENT_NAME } from "@/types";
+import { connectionForSQLEditorTab, hexToRgb } from "@/utils";
import AdminLabel from "./AdminLabel.vue";
import Label from "./Label.vue";
import Prefix from "./Prefix.vue";
@@ -39,16 +49,10 @@ type LocalState = {
hovering: boolean;
};
-const props = defineProps({
- tab: {
- type: Object as PropType<SQLEditorTab>,
- required: true,
- },
- index: {
- type: Number,
- required: true,
- },
-});
+const props = defineProps<{
+ tab: SQLEditorTab;
+ index: number;
+}>();
defineEmits<{
(e: "select", tab: SQLEditorTab, index: number): void;
@@ -62,6 +66,25 @@ const state = reactive<LocalState>({
const tabStore = useSQLEditorTabStore();
const isCurrentTab = computed(() => props.tab.id === tabStore.currentTabId);
+
+const environment = computed(() => {
+ const { database } = connectionForSQLEditorTab(props.tab);
+ const environment = database?.effectiveEnvironmentEntity;
+ if (environment?.name === UNKNOWN_ENVIRONMENT_NAME) {
+ return;
+ }
+ return environment;
+});
+
+const backgroundColorRgb = computed(() => {
+ if (!isCurrentTab.value) {
+ return [];
+ }
+ if (!environment.value || !environment.value.color) {
+ return hexToRgb("#4f46e5");
+ }
+ return hexToRgb(environment.value.color);
+});
</script>
<style scoped lang="postcss">
@@ -79,7 +102,7 @@ const isCurrentTab = computed(() => props.tab.id === tabStore.currentTabId);
@apply flex items-center justify-between gap-x-1 pl-2 pr-1 border-t pt-[4px] h-[36px];
}
.current .body {
- @apply relative bg-white text-accent border-t-accent border-t-[3px] pt-[2px];
+ @apply relative bg-white border-t-[3px] pt-[2px];
}
.tab-item.admin .body {