Skip to content

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

feat: support assign license to instance in the frontend (#6737)

ecmadao8c7cd71ec44f
diff --git a/frontend/src/components/InstanceAssignment.vue b/frontend/src/components/InstanceAssignment.vue
new file mode 100644
index 0000000000..50e8a2357a
--- /dev/null
+++ b/frontend/src/components/InstanceAssignment.vue
@@ -0,0 +1,299 @@
+<template>
+ <DrawerContent :title="$t('subscription.instance-assignment.manage-license')">
+ <div class="divide-block-border space-y-5 w-[40rem] h-full">
+ <div>
+ <div class="text-gray-400">
+ {{
+ $t("subscription.instance-assignment.available-and-total-license")
+ }}
+ </div>
+ <div class="mt-1 text-4xl flex items-center gap-x-2">
+ <span>{{ availableLicenseCount }}</span>
+ <span class="text-xl">/</span>
+ <span>{{ totalLicenseCount }}</span>
+ </div>
+ </div>
+ <BBTable
+ ref="tableRef"
+ :column-list="columnList"
+ :section-data-source="datasource"
+ :show-header="true"
+ :custom-header="true"
+ :left-bordered="true"
+ :right-bordered="true"
+ :top-bordered="true"
+ :bottom-bordered="true"
+ :compact-section="true"
+ :row-clickable="false"
+ >
+ <template #header>
+ <th
+ v-for="(column, index) in columnList"
+ :key="index"
+ scope="col"
+ class="pl-2 first:pl-4 py-2 text-left text-xs font-medium text-gray-500 tracking-wider capitalize"
+ :class="[column.center && 'text-center pr-2']"
+ >
+ <template v-if="index === 0">
+ <input
+ v-if="instanceList.length > 0"
+ type="checkbox"
+ class="h-4 w-4 text-accent rounded disabled:cursor-not-allowed border-control-border focus:ring-accent"
+ :checked="allSelectionState.checked"
+ :indeterminate="allSelectionState.indeterminate"
+ :disabled="
+ !allSelectionState.checked &&
+ instanceList.length > instanceCount
+ "
+ @input="
+ selectAllInstances(
+ ($event.target as HTMLInputElement).checked
+ )
+ "
+ />
+ </template>
+ <template v-else>{{ $t(column.title) }}</template>
+ </th>
+ </template>
+ <template #body="{ rowData: instance }: { rowData: ComposedInstance }">
+ <BBTableCell
+ class="w-[1%]"
+ @click.stop="
+ toggleSelectInstance(instance, !isInstanceSelected(instance))
+ "
+ >
+ <!-- width: 1% means as narrow as possible -->
+ <input
+ type="checkbox"
+ class="ml-2 h-4 w-4 text-accent rounded disabled:cursor-not-allowed border-control-border focus:ring-accent"
+ :checked="isInstanceSelected(instance)"
+ :disabled="state.selectedInstance.size == instanceCount"
+ />
+ </BBTableCell>
+ <BBTableCell class="bb-grid-cell">
+ <div class="flex items-center gap-x-1">
+ <InstanceV1EngineIcon :instance="instance" />
+ <router-link
+ :to="`/instance/${instanceV1Slug(instance)}`"
+ class="hover:underline"
+ active-class="link"
+ exact-active-class="link"
+ >
+ {{ instanceV1Name(instance) }}
+ </router-link>
+ </div>
+ </BBTableCell>
+ <BBTableCell class="bb-grid-cell">
+ {{ hostPortOfInstanceV1(instance) }}
+ </BBTableCell>
+ <BBTableCell class="bb-grid-cell">
+ <EnvironmentV1Name
+ :environment="instance.environmentEntity"
+ :link="false"
+ />
+ </BBTableCell>
+ </template>
+ </BBTable>
+ </div>
+
+ <template #footer>
+ <div class="w-full flex justify-between items-center">
+ <div class="w-full flex justify-end items-center gap-x-3">
+ <NButton @click.prevent="cancel">
+ {{ $t("common.cancel") }}
+ </NButton>
+ <NButton
+ :disabled="
+ !assignmentChanged ||
+ state.processing ||
+ state.selectedInstance.size > instanceCount
+ "
+ type="primary"
+ @click.prevent="updateAssignment"
+ >
+ {{ $t("common.confirm") }}
+ </NButton>
+ </div>
+ </div>
+ </template>
+ </DrawerContent>
+</template>
+
+<script lang="ts" setup>
+import { reactive, computed, watchEffect, ref } from "vue";
+import { useI18n } from "vue-i18n";
+import { storeToRefs } from "pinia";
+
+import type { BBTableColumn, BBTableSectionDataSource } from "@/bbkit/types";
+import { instanceV1Slug, instanceV1Name, hostPortOfInstanceV1 } from "@/utils";
+import {
+ pushNotification,
+ useInstanceV1Store,
+ useInstanceV1List,
+ useSubscriptionV1Store,
+} from "@/store";
+import { ComposedInstance } from "@/types";
+import { EnvironmentV1Name, InstanceV1EngineIcon } from "@/components/v2";
+import { DrawerContent } from "@/components/v2";
+
+const columnList: BBTableColumn[] = [
+ {
+ // This column is for selection input.
+ title: "",
+ },
+ {
+ title: "common.name",
+ },
+ {
+ title: "common.Address",
+ },
+ {
+ title: "common.environment",
+ },
+];
+
+interface LocalState {
+ selectedInstance: Set<string>;
+ processing: boolean;
+}
+
+const emit = defineEmits(["dismiss"]);
+
+const state = reactive<LocalState>({
+ selectedInstance: new Set(),
+ processing: false,
+});
+const instanceV1Store = useInstanceV1Store();
+const subscriptionStore = useSubscriptionV1Store();
+const { t } = useI18n();
+
+const { instanceList } = useInstanceV1List(false /* !showDeleted */);
+const { instanceCount } = storeToRefs(subscriptionStore);
+
+watchEffect(() => {
+ for (const instance of instanceList.value) {
+ if (instance.activation) {
+ state.selectedInstance.add(instance.name);
+ }
+ }
+});
+
+const totalLicenseCount = computed((): string => {
+ if (instanceCount.value > 0) {
+ return `${instanceCount.value}`;
+ }
+ return t("subscription.unlimited");
+});
+
+const availableLicenseCount = computed((): string => {
+ if (instanceCount.value > 0) {
+ return `${Math.max(0, instanceCount.value - state.selectedInstance.size)}`;
+ }
+ return t("subscription.unlimited");
+});
+
+const tableRef = ref<HTMLTableElement>();
+
+const datasource = computed(
+ (): BBTableSectionDataSource<ComposedInstance>[] => {
+ return [
+ {
+ title: "",
+ list: instanceList.value,
+ },
+ ];
+ }
+);
+
+const isInstanceSelected = (instance: ComposedInstance): boolean => {
+ return state.selectedInstance.has(instance.name);
+};
+
+const allSelectionState = computed(() => {
+ const checked = instanceList.value.every((instance) =>
+ state.selectedInstance.has(instance.name)
+ );
+ const indeterminate =
+ !checked &&
+ instanceList.value.some((instance) =>
+ state.selectedInstance.has(instance.name)
+ );
+
+ return {
+ checked,
+ indeterminate,
+ };
+});
+
+const toggleSelectInstance = (
+ instance: ComposedInstance,
+ selected: boolean
+) => {
+ if (selected) {
+ state.selectedInstance.add(instance.name);
+ } else {
+ state.selectedInstance.delete(instance.name);
+ }
+};
+
+const selectAllInstances = (selected: boolean): void => {
+ for (const instance of instanceList.value) {
+ toggleSelectInstance(instance, selected);
+ }
+};
+
+const assignmentChanged = computed(() => {
+ for (const instance of instanceList.value) {
+ if (instance.activation && !state.selectedInstance.has(instance.name)) {
+ return true;
+ }
+ if (!instance.activation && state.selectedInstance.has(instance.name)) {
+ return true;
+ }
+ }
+ return false;
+});
+
+const cancel = () => {
+ emit("dismiss");
+};
+
+const updateAssignment = async () => {
+ if (state.processing) {
+ return;
+ }
+ state.processing = true;
+
+ const selectedInstanceName = new Set(state.selectedInstance);
+ // deactivate instance first to avoid quota limitation.
+ for (const instance of instanceList.value) {
+ if (instance.activation && !selectedInstanceName.has(instance.name)) {
+ // deactivate instance
+ instance.activation = false;
+ await instanceV1Store.updateInstance(instance, ["activation"]);
+ }
+ if (instance.activation && selectedInstanceName.has(instance.name)) {
+ // remove unchanged
+ selectedInstanceName.delete(instance.name);
+ }
+ }
+
+ for (const instanceName of selectedInstanceName.values()) {
+ const instance = instanceList.value.find((i) => i.name === instanceName);
+ if (!instance) {
+ continue;
+ }
+ // activate instance
+ instance.activation = true;
+ await instanceV1Store.updateInstance(instance, ["activation"]);
+ }
+
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("subscription.instance-assignment.success-notification"),
+ });
+ state.processing = false;
+ emit("dismiss");
+};
+</script>
diff --git a/frontend/src/components/InstanceForm/InstanceForm.vue b/frontend/src/components/InstanceForm/InstanceForm.vue
index 6f815d2d78..4a8aa434b8 100644
--- a/frontend/src/components/InstanceForm/InstanceForm.vue
+++ b/frontend/src/components/InstanceForm/InstanceForm.vue
@@ -60,6 +60,27 @@
/>
</div>
+ <div class="sm:col-span-2 ml-0 sm:ml-3">
+ <label for="activation" class="textlabel block">
+ {{ $t("subscription.instance-assignment.assign-license") }}
+ ({{
+ $t("subscription.instance-assignment.n-license-remain", {
+ n: availableLicenseCount,
+ })
+ }})
+ </label>
+ <BBSwitch
+ class="mt-2"
+ :text="false"
+ :value="basicInfo.activation"
+ :disabled="
+ !allowEdit ||
+ (!basicInfo.activation && availableLicenseCount === 0)
+ "
+ @toggle="(on: boolean) => basicInfo.activation = on"
+ />
+ </div>
+
<div
:key="basicInfo.environment"
class="sm:col-span-3 sm:col-start-1 -mt-4"
@@ -634,6 +655,7 @@ import {
useActuatorV1Store,
useEnvironmentV1Store,
useInstanceV1Store,
+ useSubscriptionV1Store,
useGracefulRequest,
featureToRef,
} from "@/store";
@@ -707,6 +729,7 @@ const instanceV1Store = useInstanceV1Store();
const settingV1Store = useSettingV1Store();
const currentUserV1 = useCurrentUserV1();
const actuatorStore = useActuatorV1Store();
+const subscriptionStore = useSubscriptionV1Store();
const state = reactive<LocalState>({
currentDataSourceType: DataSourceType.ADMIN,
@@ -721,6 +744,13 @@ const hasReadonlyReplicaFeature = featureToRef(
"bb.feature.read-replica-connection"
);
+const availableLicenseCount = computed(() => {
+ return Math.max(
+ 0,
+ subscriptionStore.instanceCount - instanceV1Store.activateInstanceCount
+ );
+});
+
const extractBasicInfo = (instance: Instance | undefined): BasicInfo => {
return {
uid: instance?.uid ?? String(UNKNOWN_ID),
@@ -730,6 +760,7 @@ const extractBasicInfo = (instance: Instance | undefined): BasicInfo => {
engine: instance?.engine ?? Engine.MYSQL,
externalLink: instance?.externalLink ?? "",
environment: instance?.environment ?? UNKNOWN_ENVIRONMENT_NAME,
+ activation: instance?.activation ?? false,
};
};
@@ -1302,6 +1333,9 @@ const doUpdate = async () => {
if (instancePatch.externalLink !== instance.externalLink) {
updateMask.push("external_link");
}
+ if (instancePatch.activation !== instance.activation) {
+ updateMask.push("activation");
+ }
return await instanceV1Store.updateInstance(instancePatch, updateMask);
};
const updateDataSource = async (
diff --git a/frontend/src/components/InstanceTable.vue b/frontend/src/components/InstanceTable.vue
deleted file mode 100644
index 819c2be1e2..0000000000
--- a/frontend/src/components/InstanceTable.vue
+++ /dev/null
@@ -1,107 +0,0 @@
-<template>
- <BBGrid
- :column-list="columnList"
- :data-source="instanceList"
- class="mt-2 border-y"
- @click-row="clickInstance"
- >
- <template #item="{ item: instance }">
- <div class="bb-grid-cell justify-center !px-2">
- <InstanceEngineIcon :instance="instance" />
- </div>
- <div class="bb-grid-cell">
- {{ instanceName(instance) }}
- </div>
- <div class="bb-grid-cell">
- <EnvironmentName :environment="instance.environment" :link="false" />
- </div>
- <div class="bb-grid-cell">
- <template v-if="instance.port"
- >{{ instance.host }}:{{ instance.port }}</template
- ><template v-else>{{ instance.host }}</template>
- </div>
- <div class="bb-grid-cell hidden sm:flex">
- <button
- v-if="instance.externalLink?.trim().length != 0"
- class="btn-icon"
- @click.stop="window.open(urlfy(instance.externalLink), '_blank')"
- >
- <heroicons-outline:external-link class="w-4 h-4" />
- </button>
- </div>
- </template>
- </BBGrid>
-</template>
-
-<script lang="ts">
-import { PropType, defineComponent, computed } from "vue";
-import { useI18n } from "vue-i18n";
-import { useRouter } from "vue-router";
-import { urlfy, instanceSlug } from "@/utils";
-import { Instance } from "@/types";
-import InstanceEngineIcon from "./InstanceEngineIcon.vue";
-import { BBGridColumn } from "@/bbkit";
-import { EnvironmentName } from "@/components/v2";
-
-export default defineComponent({
- name: "InstanceTable",
- components: { InstanceEngineIcon, EnvironmentName },
- props: {
- instanceList: {
- required: true,
- type: Object as PropType<Instance[]>,
- },
- },
- setup(props) {
- const { t } = useI18n();
-
- const router = useRouter();
-
- const columnList = computed((): BBGridColumn[] => {
- return [
- {
- title: "",
- width: "minmax(auto, 4rem)",
- },
- {
- title: t("common.name"),
- width: "minmax(auto, 3fr)",
- },
- {
- title: t("common.environment"),
- width: "minmax(auto, 1fr)",
- },
- {
- title: t("common.Address"),
- width: "minmax(auto, 2fr)",
- },
- {
- title: t("instance.external-link"),
- width: { sm: "1fr" },
- class: "hidden sm:flex",
- },
- ];
- });
-
- const clickInstance = (
- instance: Instance,
- section: number,
- row: number,
- e: MouseEvent
- ) => {
- const url = `/instance/${instanceSlug(instance)}`;
- if (e.ctrlKey || e.metaKey) {
- window.open(url, "_blank");
- } else {
- router.push(url);
- }
- };
-
- return {
- columnList,
- urlfy,
- clickInstance,
- };
- },
-});
-</script>
diff --git a/frontend/src/components/QuickActionPanel.vue b/frontend/src/components/QuickActionPanel.vue
index eb1159c9fb..57a0c02bd5 100644
--- a/frontend/src/components/QuickActionPanel.vue
+++ b/frontend/src/components/QuickActionPanel.vue
@@ -207,6 +207,23 @@
</h3>
</div>
</template>
+
+ <div
+ v-if="quickAction === 'quickaction.bb.subscription.license-assignment'"
+ class="flex flex-col items-center w-24"
+ >
+ <router-link
+ to="/setting/subscription?manageLicense=1"
+ class="btn-icon-primary p-3"
+ >
+ <heroicons-outline:cog class="w-5 h-5" />
+ </router-link>
+ <h3
+ class="flex-1 mt-1.5 text-center text-sm font-normal text-main tracking-tight"
+ >
+ {{ $t("subscription.instance-assignment.assign-license") }}
+ </h3>
+ </div>
</template>
</div>
@@ -315,6 +332,9 @@ const props = defineProps({
},
});
+console.log("quickActionList");
+console.log(props.quickActionList);
+
const { t } = useI18n();
const router = useRouter();
const route = useRoute();
@@ -435,6 +455,14 @@ const QuickActionMap: Record<string, Partial<Action>> = {
name: t("quick-action.transfer-in-db"),
perform: () => transferDatabase(),
},
+ "quickaction.bb.subscription.license-assignment": {
+ name: t("subscription.instance-assignment.manage-license"),
+ perform: () =>
+ router.push({
+ name: "setting.workspace.subscription",
+ query: { manageLicense: 1 },
+ }),
+ },
};
const kbarActions = computed(() => {
diff --git a/frontend/src/components/v2/Model/Instance/InstanceV1Table/InstanceV1Table.vue b/frontend/src/components/v2/Model/Instance/InstanceV1Table/InstanceV1Table.vue
index 1f433e0c92..cbfecd1a81 100644
--- a/frontend/src/components/v2/Model/Instance/InstanceV1Table/InstanceV1Table.vue
+++ b/frontend/src/components/v2/Model/Instance/InstanceV1Table/InstanceV1Table.vue
@@ -30,6 +30,9 @@
<heroicons-outline:external-link class="w-4 h-4" />
</button>
</div>
+ <div v-if="canAssignLicense" class="bb-grid-cell hover:underline">
+ {{ instance.activation ? "Assigned" : "N/A" }}
+ </div>
</template>
</BBGrid>
</template>
@@ -52,8 +55,9 @@ import { BBGrid, BBGridColumn, BBGridRow } from "@/bbkit";
export type InstanceRow = BBGridRow<ComposedInstance>;
-defineProps<{
+const props = defineProps<{
instanceList: ComposedInstance[];
+ canAssignLicense: boolean;
}>();
const { t } = useI18n();
@@ -61,7 +65,7 @@ const { t } = useI18n();
const router = useRouter();
const columnList = computed((): BBGridColumn[] => {
- return [
+ const list = [
{
title: "",
width: "minmax(auto, 4rem)",
@@ -84,6 +88,13 @@ const columnList = computed((): BBGridColumn[] => {
class: "hidden sm:flex",
},
];
+ if (props.canAssignLicense) {
+ list.push({
+ title: t("subscription.instance-assignment.license"),
+ width: "minmax(auto, 1fr)",
+ });
+ }
+ return list;
});
const clickInstance = (
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 4de5c23649..b18a46b005 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1878,6 +1878,14 @@
"trial-for-days": "You can start a free trial for {days} days - no credit card required",
"upgrade-trial": "You can upgrade your free trial to this plan",
"upgrade-now": "Upgrade Now",
+ "instance-assignment": {
+ "license": "License",
+ "assign-license": "Assign License",
+ "n-license-remain": "remain {n}",
+ "manage-license": "Manage License",
+ "available-and-total-license": "Available / Total Instance License",
+ "success-notification": "Successfully update license assignment"
+ },
"update": {
"success": {
"title": "Successfully updated license",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 5381be7d0c..6c110081e0 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -1864,6 +1864,14 @@
"trial-for-days": "Puedes iniciar una prueba gratuita por {days} días - no se requiere tarjeta de crédito",
"upgrade-trial": "Puedes actualizar tu prueba gratuita a este plan",
"upgrade-now": "Actualizar ahora",
+ "instance-assignment": {
+ "license": "Licencia",
+ "assign-license": "Asignar licencia",
+ "n-license-remain": "permanecer {n}",
+ "manage-license": "Administrar licencia",
+ "available-and-total-license": "Licencia de instancia disponible/total",
+ "success-notification": "Actualizar correctamente la asignación de licencia"
+ },
"update": {
"success": {
"title": "Licencia actualizada con éxito",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 3def95116a..e5b5291df4 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1873,6 +1873,14 @@
"trial-for-days": "您可以开启 {days} 天的免费试用 - 无需任何信用卡或预付费",
"upgrade-trial": "您可以直接将现有的试用升级到这个版本",
"upgrade-now": "现在升级",
+ "instance-assignment": {
+ "license": "证书",
+ "assign-license": "分配证书",
+ "n-license-remain": "剩余 {n}",
+ "manage-license": "管理证书",
+ "available-and-total-license": "可分配数 / 证书总数",
+ "success-notification": "证书分配更新成功"
+ },
"update": {
"success": {
"title": "证书更新成功",
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index 8b76842da8..e5dc02e927 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -797,7 +797,13 @@ const routes: Array<RouteRecordRaw> = [
title: () => t("common.instances"),
quickActionListByRole: () => {
return new Map([
- ["OWNER", ["quickaction.bb.instance.create"]],
+ [
+ "OWNER",
+ [
+ "quickaction.bb.instance.create",
+ "quickaction.bb.subscription.license-assignment",
+ ],
+ ],
["DBA", ["quickaction.bb.instance.create"]],
]);
},
diff --git a/frontend/src/store/modules/v1/instance.ts b/frontend/src/store/modules/v1/instance.ts
index 677c2f27c2..b58c0c32c8 100644
--- a/frontend/src/store/modules/v1/instance.ts
+++ b/frontend/src/store/modules/v1/instance.ts
@@ -33,6 +33,15 @@ export const useInstanceV1Store = defineStore("instance_v1", () => {
return instance.state === State.ACTIVE;
});
});
+ const activateInstanceCount = computed(() => {
+ let count = 0;
+ for (const instance of activeInstanceList.value) {
+ if (instance.activation) {
+ count++;
+ }
+ }
+ return count;
+ });
// Actions
const upsertInstances = async (list: Instance[]) => {
@@ -195,6 +204,7 @@ export const useInstanceV1Store = defineStore("instance_v1", () => {
return {
instanceList,
activeInstanceList,
+ activateInstanceCount,
createInstance,
updateInstance,
archiveInstance,
diff --git a/frontend/src/types/quickAction.ts b/frontend/src/types/quickAction.ts
index 857724b741..65360de126 100644
--- a/frontend/src/types/quickAction.ts
+++ b/frontend/src/types/quickAction.ts
@@ -16,6 +16,8 @@ export type DatabaseQuickActionType =
export type IssueQuickActionType =
| "quickaction.bb.issue.grant.request.querier"
| "quickaction.bb.issue.grant.request.exporter";
+type SubscriptionQuickActionType =
+ "quickaction.bb.subscription.license-assignment";
export type QuickActionType =
| EnvironmentQuickActionType
@@ -23,4 +25,5 @@ export type QuickActionType =
| InstanceQuickActionType
| UserQuickActionType
| DatabaseQuickActionType
- | IssueQuickActionType;
+ | IssueQuickActionType
+ | SubscriptionQuickActionType;
diff --git a/frontend/src/utils/v1/instance.ts b/frontend/src/utils/v1/instance.ts
index 0f095546ce..cdb0d66b78 100644
--- a/frontend/src/utils/v1/instance.ts
+++ b/frontend/src/utils/v1/instance.ts
@@ -12,8 +12,11 @@ export const instanceV1Slug = (instance: Instance): string => {
export function instanceV1Name(instance: Instance) {
let name = instance.title;
+ // instance cannot be deleted and activated at the same time.
if (instance.state === State.DELETED) {
name += " (Archived)";
+ } else if (!instance.activation) {
+ name += " (Deactivate)";
}
return name;
}
diff --git a/frontend/src/views/InstanceDashboard.vue b/frontend/src/views/InstanceDashboard.vue
index 6503219e17..2b053a121a 100644
--- a/frontend/src/views/InstanceDashboard.vue
+++ b/frontend/src/views/InstanceDashboard.vue
@@ -18,7 +18,10 @@
:placeholder="$t('instance.search-instance-name')"
/>
</div>
- <InstanceV1Table :instance-list="filteredInstanceV1List" />
+ <InstanceV1Table
+ :instance-list="filteredInstanceV1List"
+ :can-assign-license="true"
+ />
</div>
</template>
diff --git a/frontend/src/views/SettingWorkspaceSubscription.vue b/frontend/src/views/SettingWorkspaceSubscription.vue
index 4c2e5a8b26..afdd8f9063 100644
--- a/frontend/src/views/SettingWorkspaceSubscription.vue
+++ b/frontend/src/views/SettingWorkspaceSubscription.vue
@@ -41,9 +41,19 @@
</div>
<div class="my-3">
<dt class="text-gray-400">
- {{ $t("subscription.instance-count") }}
+ {{
+ $t("subscription.instance-assignment.available-and-total-license")
+ }}
</dt>
- <dd class="mt-1 text-4xl">{{ instanceCount }}</dd>
+ <dd
+ class="mt-1 text-4xl flex items-center gap-x-2 cursor-pointer"
+ @click="state.showInstanceAssignmentDrawer = true"
+ >
+ <span>{{ availableLicenseCount }}</span>
+ <span class="text-xl">/</span>
+ <span>{{ totalLicenseCount }}</span>
+ <heroicons-outline:cog class="h-6 w-6" />
+ </dd>
</div>
<div v-if="!subscriptionStore.isFreePlan" class="my-3">
<dt class="text-gray-400">
@@ -123,28 +133,39 @@
@cancel="state.showTrialModal = false"
/>
</div>
+
+ <Drawer
+ :show="state.showInstanceAssignmentDrawer"
+ @close="state.showInstanceAssignmentDrawer = false"
+ >
+ <InstanceAssignment @dismiss="state.showInstanceAssignmentDrawer = false" />
+ </Drawer>
</template>
<script lang="ts" setup>
-import { computed, reactive } from "vue";
+import { computed, reactive, onMounted } from "vue";
import { useI18n } from "vue-i18n";
import PricingTable from "../components/PricingTable/";
import { PlanType } from "@/types/proto/v1/subscription_service";
import {
pushNotification,
useCurrentUserV1,
+ useInstanceV1Store,
useSubscriptionV1Store,
} from "@/store";
import { storeToRefs } from "pinia";
import { hasWorkspacePermissionV1 } from "@/utils";
+import { Drawer } from "@/components/v2";
interface LocalState {
loading: boolean;
license: string;
showTrialModal: boolean;
+ showInstanceAssignmentDrawer: boolean;
}
const subscriptionStore = useSubscriptionV1Store();
+const instanceV1Store = useInstanceV1Store();
const { t } = useI18n();
const currentUserV1 = useCurrentUserV1();
@@ -152,6 +173,14 @@ const state = reactive<LocalState>({
loading: false,
license: "",
showTrialModal: false,
+ showInstanceAssignmentDrawer: false,
+});
+
+onMounted(() => {
+ const params = new URLSearchParams(window.location.search);
+ if (params.get("manageLicense")) {
+ state.showInstanceAssignmentDrawer = true;
+ }
});
const disabled = computed((): boolean => {
@@ -183,13 +212,22 @@ const uploadLicense = async () => {
}
};
-const { subscription, expireAt, isTrialing, isExpired } =
+const { expireAt, isTrialing, isExpired, instanceCount } =
storeToRefs(subscriptionStore);
-const instanceCount = computed((): string => {
- const count = subscription.value?.instanceCount ?? 5;
- if (count > 0) {
- return `${count}`;
+const totalLicenseCount = computed((): string => {
+ if (instanceCount.value > 0) {
+ return `${instanceCount.value}`;
+ }
+ return t("subscription.unlimited");
+});
+
+const availableLicenseCount = computed((): string => {
+ if (instanceCount.value > 0) {
+ return `${Math.max(
+ 0,
+ instanceCount.value - instanceV1Store.activateInstanceCount
+ )}`;
}
return t("subscription.unlimited");
});