Skip to content

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

feat(frontend): label management (#290)

Liu Ji21733ad5e227
diff --git a/frontend/.eslintrc.js b/frontend/.eslintrc.js
index d8e1077f10..4039b30b2e 100644
--- a/frontend/.eslintrc.js
+++ b/frontend/.eslintrc.js
@@ -25,7 +25,13 @@ module.exports = {
"vue/no-unused-components": "warn",
"vue/no-useless-template-attributes": "warn",
},
- ignorePatterns: ["node_modules", "build", "dist", "public"],
+ ignorePatterns: [
+ "node_modules",
+ "build",
+ "dist",
+ "public",
+ "components.d.ts",
+ ],
overrides: [
{
files: ["./*.js"],
diff --git a/frontend/src/bbkit/BBTable/BBTableCell.vue b/frontend/src/bbkit/BBTable/BBTableCell.vue
index fc4446f4ae..994c24cc57 100644
--- a/frontend/src/bbkit/BBTable/BBTableCell.vue
+++ b/frontend/src/bbkit/BBTable/BBTableCell.vue
@@ -1,14 +1,13 @@
<template>
- <td
- class="table-cell text-sm leading-5 py-2 max-w-prose"
- :class="`pl-` + leftPadding + ` pr-` + rightPadding"
- >
+ <td class="table-cell text-sm leading-5 max-w-prose" :class="classNames">
<slot />
</td>
</template>
<script lang="ts">
-export default {
+import { defineComponent } from "vue";
+
+export default defineComponent({
name: "BBTableCell",
props: {
leftPadding: {
@@ -19,6 +18,19 @@ export default {
type: Number,
default: 2,
},
+ compact: {
+ type: Boolean,
+ default: false,
+ },
+ },
+ setup(props) {
+ const classNames: string[] = [];
+ if (!props.compact) {
+ classNames.push(`pl-${props.leftPadding}`);
+ classNames.push(`pr-${props.rightPadding}`);
+ classNames.push("py-2");
+ }
+ return { classNames };
},
-};
+});
</script>
diff --git a/frontend/src/bbkit/BBTable/BBTableHeaderCell.vue b/frontend/src/bbkit/BBTable/BBTableHeaderCell.vue
index 776730423c..734668953a 100644
--- a/frontend/src/bbkit/BBTable/BBTableHeaderCell.vue
+++ b/frontend/src/bbkit/BBTable/BBTableHeaderCell.vue
@@ -1,22 +1,17 @@
<template>
<th
scope="col"
- class="
- table-cell
- text-left text-xs
- font-medium
- text-gray-500
- tracking-wider
- py-2
- "
- :class="`pl-` + leftPadding"
+ class="table-cell text-left text-xs font-medium text-gray-500 tracking-wider"
+ :class="classNames"
>
- {{ title }}
+ <slot>{{ title }}</slot>
</th>
</template>
<script lang="ts">
-export default {
+import { defineComponent } from "vue";
+
+export default defineComponent({
name: "BBTableHeaderCell",
props: {
title: {
@@ -27,6 +22,18 @@ export default {
type: Number,
default: 2,
},
+ compact: {
+ type: Boolean,
+ default: false,
+ },
+ },
+ setup(props) {
+ const classNames: string[] = [];
+ if (!props.compact) {
+ classNames.push(`pl-${props.leftPadding}`);
+ classNames.push("py-2");
+ }
+ return { classNames };
},
-};
+});
</script>
diff --git a/frontend/src/components/AddLabelValue.vue b/frontend/src/components/AddLabelValue.vue
new file mode 100644
index 0000000000..3a1fa29718
--- /dev/null
+++ b/frontend/src/components/AddLabelValue.vue
@@ -0,0 +1,198 @@
+<template>
+ <div class="add-label-value">
+ <template v-if="!state.isAdding">
+ <NPopover trigger="hover" :disabled="!reserved">
+ <template #trigger>
+ <div
+ class="icon-btn"
+ :class="{ disabled: reserved }"
+ @click="toggleAdding"
+ >
+ <heroicons-solid:plus class="w-4 h-4" />
+ </div>
+ </template>
+
+ <span class="text-red-600">
+ {{
+ $t("label.error.cannot-edit-reserved-label", {
+ key: label.key,
+ })
+ }}
+ </span>
+ </NPopover>
+ </template>
+ <template v-else>
+ <input
+ ref="input"
+ v-model="state.text"
+ type="text"
+ autocomplete="off"
+ class="textfield"
+ :class="{ error: !!state.error && state.changed }"
+ :placeholder="$t('setting.label.value-placeholder')"
+ @blur="cancel"
+ @keyup.esc="cancel"
+ @keyup.enter="tryAdd"
+ />
+ <div class="icon-btn cancel" @click="cancel">
+ <heroicons-solid:x class="w-4 h-4" />
+ </div>
+ <NPopover trigger="hover" :disabled="!state.error">
+ <template #trigger>
+ <div
+ class="icon-btn save"
+ :class="{ disabled: !!state.error }"
+ @mousedown.prevent.stop="tryAdd"
+ >
+ <heroicons-solid:check class="w-4 h-4" />
+ </div>
+ </template>
+
+ <div class="text-red-600 whitespace-nowrap">
+ {{ state.error }}
+ </div>
+ </NPopover>
+ </template>
+ </div>
+</template>
+
+<script lang="ts">
+import {
+ defineComponent,
+ PropType,
+ ref,
+ nextTick,
+ watch,
+ reactive,
+ computed,
+} from "vue";
+import { useI18n } from "vue-i18n";
+import { Label } from "../types";
+import { NPopover } from "naive-ui";
+import { isReservedLabel } from "../utils";
+
+type LocalState = {
+ isAdding: boolean;
+ text: string;
+ error: string | undefined;
+ changed: boolean;
+};
+
+const MAX_VALUE_LENGTH = 63;
+
+export default defineComponent({
+ name: "AddLabelValue",
+ components: { NPopover },
+ props: {
+ label: {
+ type: Object as PropType<Label>,
+ required: true,
+ },
+ },
+ emits: ["add"],
+ setup(props, { emit }) {
+ const { t } = useI18n();
+ const input = ref<HTMLInputElement>();
+ const state = reactive<LocalState>({
+ isAdding: false,
+ text: "",
+ error: undefined,
+ changed: false,
+ });
+
+ const reserved = computed(() => isReservedLabel(props.label));
+
+ const toggleAdding = () => {
+ if (isReservedLabel(props.label)) return;
+ state.isAdding = !state.isAdding;
+ };
+
+ const validate = () => {
+ const v = state.text.trim();
+ if (!v) {
+ // can't be empty
+ state.error = t("label.error.value-necessary");
+ } else if (props.label.valueList.includes(v)) {
+ // must be unique
+ state.error = t("label.error.value-duplicated");
+ } else if (v.length > MAX_VALUE_LENGTH) {
+ // max length exceeded
+ state.error = t("label.error.max-length-exceeded", {
+ len: MAX_VALUE_LENGTH,
+ });
+ } else {
+ // ok
+ state.error = undefined;
+ }
+ return !state.error;
+ };
+
+ watch(
+ () => state.text,
+ () => {
+ state.changed = true;
+ validate();
+ }
+ );
+
+ const cancel = () => {
+ state.isAdding = false;
+ state.text = "";
+ };
+
+ const tryAdd = () => {
+ if (state.error) {
+ return;
+ }
+ const v = state.text.trim();
+ emit("add", v);
+ cancel();
+ };
+
+ watch(
+ () => state.isAdding,
+ (isAdding) => {
+ if (isAdding) {
+ // reset input state
+ validate();
+ state.changed = false;
+ // auto focus if possible
+ nextTick(() => input.value?.focus());
+ }
+ }
+ );
+
+ return { state, reserved, toggleAdding, tryAdd, cancel, input };
+ },
+});
+</script>
+
+<style scoped lang="postcss">
+.add-label-value {
+ @apply inline-flex flex-nowrap items-center gap-1 h-6;
+}
+.add-label-value > * {
+ @apply h-full;
+}
+.icon-btn {
+ @apply px-1 py-1 inline-flex items-center
+ rounded bg-white border border-control-border
+ hover:bg-control-bg-hover
+ cursor-pointer;
+}
+.icon-btn.disabled {
+ @apply cursor-not-allowed bg-control-bg;
+}
+.textfield {
+ @apply rounded px-2 py-0 text-sm w-32;
+}
+.textfield.error {
+ @apply border-error focus:ring-error focus:border-error;
+}
+.cancel {
+ @apply text-error;
+}
+.save {
+ @apply text-success;
+}
+</style>
diff --git a/frontend/src/locales/en.yml b/frontend/src/locales/en.yml
index db977e6afa..243aa7e77f 100644
--- a/frontend/src/locales/en.yml
+++ b/frontend/src/locales/en.yml
@@ -138,6 +138,8 @@ common:
assigned: Assigned
subscribed: Subscribed
created: Created
+ label: Label
+ labels: Labels
roletype: Role Type
readonly: readonly
user: User
@@ -150,6 +152,7 @@ common:
billings: Billings
all: All
by: by
+ ok: OK
share: Share
error-page:
go-back-home: Go back home
@@ -224,6 +227,7 @@ settings:
members: Members
version-control: Version Control
plans: Plans
+ labels: Labels
profile:
email: Email
role: Role
@@ -696,8 +700,6 @@ database:
columns: Columns
indexes: Indexes
row-count-est: Row count est.
-t:
- database: {}
repository:
branch-observe-file-change: The branch where Bytebase observes the file change.
branch-specify-tip: 'Tip: You can also use wildcard like ''feature/*'
@@ -1015,6 +1017,19 @@ setting:
free: Free
team: Team
enterprise: Enterprise
+ label:
+ key: Key
+ values: Values
+ value-placeholder: Label value...
sql-editor:
self: SQL Editor
select-connection: Select Connections
+label:
+ error:
+ key-necessary: Key is required
+ value-necessary: Value is required
+ key-duplicated: Duplicated keys
+ value-duplicated: Duplicated values
+ max-length-exceeded: Length cannot exceed {len} characters
+ max-label-count-exceeded: Cannot exceed {count} labels
+ cannot-edit-reserved-label: Cannot edit reserved label "{key}"
diff --git a/frontend/src/locales/zh-CN.yml b/frontend/src/locales/zh-CN.yml
index bdbe1fd574..b4a4408ed5 100644
--- a/frontend/src/locales/zh-CN.yml
+++ b/frontend/src/locales/zh-CN.yml
@@ -138,6 +138,8 @@ common:
assigned: 已指派
subscribed: 已订阅
created: 已创建
+ label: 标签
+ labels: 标签
roletype: 角色类型
readonly: 只读
user: 用户
@@ -150,6 +152,7 @@ common:
billings: 计费
all: 全部
by: 由
+ ok: OK
share: 分享
error-page:
go-back-home: 回到主页
@@ -218,6 +221,7 @@ settings:
members: 成员
version-control: 版本控制
plans: 价格方案
+ labels: 标签
profile:
email: 邮箱
role: 角色
@@ -884,6 +888,19 @@ setting:
free: 免费版
team: 团队版
enterprise: 企业版
+ label:
+ key: Key
+ values: 值
+ value-placeholder: 标签值…
sql-editor:
self: SQL 编辑器
select-connection: 请选择数据连接
+label:
+ error:
+ key-necessary: 需要指定 Key
+ value-necessary: 需要指定值
+ key-duplicated: Key 重复了
+ value-duplicated: 值重复了
+ max-length-exceeded: 长度不能超过 {len} 字符
+ max-label-count-exceeded: 不能多于 {count} 个标签
+ cannot-edit-reserved-label: 不能编辑预留标签 "{key}"
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index bd973f8a1a..1a38a44d6e 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -269,6 +269,13 @@ const routes: Array<RouteRecordRaw> = [
component: () => import("../views/SettingWorkspaceGeneral.vue"),
props: true,
},
+ {
+ path: "label",
+ name: "setting.workspace.label",
+ meta: { title: () => t("settings.sidebar.labels") },
+ component: () => import("../views/SettingWorkspaceLabel.vue"),
+ props: true,
+ },
{
path: "agent",
name: "setting.workspace.agent",
diff --git a/frontend/src/store/index.ts b/frontend/src/store/index.ts
index f530fd3888..9c1fa05407 100644
--- a/frontend/src/store/index.ts
+++ b/frontend/src/store/index.ts
@@ -2,14 +2,14 @@ import { createStore, Store } from "vuex";
/**
* Following states are persisted in database
- * activity | actuator | anomlay | auth | backup | bookmark |
+ * activity | actuator | anomaly | auth | backup | bookmark |
* command | database | dataSource | environment | gitlab |
* inbox |instance | issue | issueSubscriber | member | notification |
* pipeline | plan | policy | principal | project | projectWebhook | repository |
- *
+ *
* Following states are only stored in memory
- * router | setting | sql | stage | table | task | sqlEdtior
- *
+ * router | setting | sql | stage | table | task | sqlEditor
+ *
* Following states are persisted in local storage
* uistate | vsc | view
*/
diff --git a/frontend/src/store/modules/index.ts b/frontend/src/store/modules/index.ts
index d359063041..0efd5eb234 100644
--- a/frontend/src/store/modules/index.ts
+++ b/frontend/src/store/modules/index.ts
@@ -1,11 +1,9 @@
// https://vitejs.dev/guide/features.html#glob-import
const modules = Object.fromEntries(
- Object.entries(import.meta.globEager("./*.ts")).map(
- ([key, value]) => {
- const moduleName = key.replace("./", "").replace(".ts", "");
- return [moduleName, value.default];
- }
- )
+ Object.entries(import.meta.globEager("./*.ts")).map(([key, value]) => {
+ const moduleName = key.replace("./", "").replace(".ts", "");
+ return [moduleName, value.default];
+ })
);
export default modules;
diff --git a/frontend/src/store/modules/label.ts b/frontend/src/store/modules/label.ts
new file mode 100644
index 0000000000..3f7e248733
--- /dev/null
+++ b/frontend/src/store/modules/label.ts
@@ -0,0 +1,84 @@
+import axios from "axios";
+import {
+ Label,
+ ResourceObject,
+ LabelState,
+ LabelId,
+ LabelPatch,
+} from "../../types";
+
+function convert(
+ label: ResourceObject,
+ includedList: ResourceObject[],
+ rootGetters: any
+): Label {
+ return {
+ ...(label.attributes as Omit<Label, "id">),
+ id: parseInt(label.id, 10),
+ };
+}
+
+const state: () => LabelState = () => ({
+ labelList: [],
+});
+
+const getters = {
+ labelList: (state: LabelState) => (): Label[] => {
+ return state.labelList;
+ },
+};
+
+const actions = {
+ async fetchLabelList({ commit, rootGetters }: any) {
+ const data = (await axios.get(`/api/label`)).data;
+
+ const labelList = data.data.map((label: ResourceObject) => {
+ return convert(label, data.included, rootGetters);
+ });
+
+ commit("setLabelList", labelList);
+ return labelList;
+ },
+
+ async patchLabel(
+ { commit, rootGetters }: any,
+ { id, labelPatch }: { id: LabelId; labelPatch: LabelPatch }
+ ) {
+ const data = (
+ await axios.patch(`/api/label/${id}`, {
+ data: {
+ type: "labelPatch",
+ attributes: labelPatch,
+ },
+ })
+ ).data;
+ const updatedLabel = convert(data.data, data.included, rootGetters);
+
+ commit("replaceLabelInList", updatedLabel);
+
+ return updatedLabel;
+ },
+};
+
+const mutations = {
+ setLabelList(state: LabelState, labelList: Label[]) {
+ state.labelList = labelList;
+ },
+
+ replaceLabelInList(state: LabelState, updatedLabel: Label) {
+ const i = state.labelList.findIndex(
+ (item: Label) => item.id == updatedLabel.id
+ );
+ if (i != -1) {
+ state.labelList[i] = updatedLabel;
+ }
+ },
+};
+
+export default {
+ namespaced: true,
+ state,
+ getters,
+ actions,
+ mutations,
+};
diff --git a/frontend/src/types/id.ts b/frontend/src/types/id.ts
index 73f544ba0b..ea3e624abc 100644
--- a/frontend/src/types/id.ts
+++ b/frontend/src/types/id.ts
@@ -72,3 +72,5 @@ export type CommandRegisterId = IdType;
// Currently, only issue can be used a container.
// The type is used by Activity and Message
export type ContainerId = IssueId;
+
+export type LabelId = IdType;
diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.ts
index d539509171..6cffa0b9a2 100644
--- a/frontend/src/types/index.ts
+++ b/frontend/src/types/index.ts
@@ -33,4 +33,5 @@ export * from "./table";
export * from "./tableIndex";
export * from "./vcs";
export * from "./view";
+export * from "./label";
export * from "./sqlEditor";
diff --git a/frontend/src/types/label.ts b/frontend/src/types/label.ts
new file mode 100644
index 0000000000..fe21669811
--- /dev/null
+++ b/frontend/src/types/label.ts
@@ -0,0 +1,23 @@
+import { LabelId } from "./id";
+import { Principal } from "./principal";
+
+export type LabelKeyType = string;
+export type LabelValueType = string;
+
+export type Label = {
+ id: LabelId;
+
+ // Standard fields
+ creator: Principal;
+ createdTs: number;
+ updater: Principal;
+ updatedTs: number;
+
+ // Domain specific fields
+ key: LabelKeyType;
+ valueList: LabelValueType[];
+};
+
+export type LabelPatch = {
+ valueList?: LabelValueType[];
+};
diff --git a/frontend/src/types/setting.ts b/frontend/src/types/setting.ts
index 8ccee00315..c04b179855 100644
--- a/frontend/src/types/setting.ts
+++ b/frontend/src/types/setting.ts
@@ -1,6 +1,8 @@
import { SettingId } from "./id";
import { Principal } from "./principal";
+export type SettingName = string;
+
export type Setting = {
id: SettingId;
diff --git a/frontend/src/types/store.ts b/frontend/src/types/store.ts
index 378470338a..1d3bfae012 100644
--- a/frontend/src/types/store.ts
+++ b/frontend/src/types/store.ts
@@ -32,8 +32,8 @@ import { Repository } from "./repository";
import { Setting, SettingName } from "./setting";
import { Table } from "./table";
import { VCS } from "./vcs";
+import { Label } from "./label";
import { ConnectionAtom, ConnectionContext } from "./sqlEditor";
-
import instanceStore from "../store/modules/instance";
import sqlEditorStore from "../store/modules/sqlEditor";
@@ -172,6 +172,10 @@ export interface CommandState {
commandListById: Map<CommandId, Command[]>;
}
+export interface LabelState {
+ labelList: Label[];
+}
+
// type for vuex
export interface SqlEditorState {
connectionTree: ConnectionAtom[];
diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts
index 2dd1fe165d..096ac3ab96 100644
--- a/frontend/src/utils/index.ts
+++ b/frontend/src/utils/index.ts
@@ -9,3 +9,4 @@ export * from "./project";
export * from "./role";
export * from "./slug";
export * from "./util";
+export * from "./label";
diff --git a/frontend/src/utils/label.ts b/frontend/src/utils/label.ts
new file mode 100644
index 0000000000..ad45780582
--- /dev/null
+++ b/frontend/src/utils/label.ts
@@ -0,0 +1,9 @@
+import { Label } from "../types";
+
+// reserved labels (e.g. bb.environment) have zero ID and their values are immutable.
+// see api/label.go for more details
+export const RESERVED_LABEL_ID = 0;
+
+export const isReservedLabel = (label: Label): boolean => {
+ return label.id === RESERVED_LABEL_ID;
+};
diff --git a/frontend/src/views/SettingSidebar.vue b/frontend/src/views/SettingSidebar.vue
index 94f2184f10..87b23d9ea7 100644
--- a/frontend/src/views/SettingSidebar.vue
+++ b/frontend/src/views/SettingSidebar.vue
@@ -23,7 +23,9 @@
<router-link
to="/setting/profile"
class="outline-item group w-full flex items-center pl-11 pr-2 py-2"
- >{{ $t("settings.sidebar.profile") }}</router-link>
+ >
+ {{ $t("settings.sidebar.profile") }}
+ </router-link>
</div>
</div>
<div class="mt-8">
@@ -39,36 +41,52 @@
class="outline-item group w-full flex items-center pl-11 pr-2 py-2"
>
{{ $t("settings.sidebar.general") }}
- </router-link>-->
+ </router-link> -->
<!-- <router-link
to="/setting/agent"
class="outline-item group w-full flex items-center pl-11 pr-2 py-2"
>
Agents
- </router-link>-->
+ </router-link> -->
<router-link
to="/setting/member"
class="outline-item group w-full flex items-center pl-11 pr-2 py-2"
- >{{ $t("settings.sidebar.members") }}</router-link>
+ >
+ {{ $t("settings.sidebar.members") }}
+ </router-link>
+ <!--
+ Label Management is visible to all
+ but only editable to Owners and DBAs
+ -->
+ <router-link
+ to="/setting/label"
+ class="outline-item group w-full flex items-center pl-11 pr-2 py-2"
+ >
+ {{ $t("settings.sidebar.labels") }}
+ </router-link>
<router-link
v-if="showOwnerItem"
to="/setting/version-control"
class="outline-item group w-full flex items-center pl-11 pr-2 py-2"
- >{{ $t("settings.sidebar.version-control") }}</router-link>
+ >
+ {{ $t("settings.sidebar.version-control") }}
+ </router-link>
<router-link
v-if="false"
to="/setting/plan"
class="outline-item group w-full flex items-center pl-11 pr-2 py-2"
- >{{ $t("settings.sidebar.plans") }}</router-link>
+ >
+ {{ $t("settings.sidebar.plans") }}
+ </router-link>
<!-- <router-link
to="/setting/billing"
class="outline-item group w-full flex items-center pl-11 pr-2 py-2"
>
Billing
- </router-link>-->
+ </router-link> -->
<!-- <div class="pl-9 mt-1">
<BBOutline :title="'Integrations'" :itemList="integrationList" />
- </div>-->
+ </div> -->
</div>
</div>
</div>
@@ -76,7 +94,7 @@
</template>
<script lang="ts">
-import { computed, reactive } from "vue";
+import { computed, defineComponent, reactive } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import { isOwner } from "../utils";
@@ -85,7 +103,7 @@ interface LocalState {
collapseState: boolean;
}
-export default {
+export default defineComponent({
name: "SettingSidebar",
props: {
vcsSlug: {
@@ -130,5 +148,5 @@ export default {
toggleCollapse,
};
},
-};
+});
</script>
diff --git a/frontend/src/views/SettingWorkspaceLabel.vue b/frontend/src/views/SettingWorkspaceLabel.vue
new file mode 100644
index 0000000000..54ef83d5d4
--- /dev/null
+++ b/frontend/src/views/SettingWorkspaceLabel.vue
@@ -0,0 +1,139 @@
+<template>
+ <div class="mt-2 space-y-6 divide-y divide-block-border">
+ <div class="mt-4">
+ <BBTable
+ class="mt-2"
+ :column-list="COLUMN_LIST"
+ :data-source="labelList"
+ :show-header="true"
+ :row-clickable="false"
+ >
+ <template #body="{ rowData: label }">
+ <BBTableCell :left-padding="4" class="w-36 table-cell">
+ {{ label.key }}
+ </BBTableCell>
+ <BBTableCell class="whitespace-nowrap">
+ <div class="tags">
+ <div v-for="(value, j) in label.valueList" :key="j" class="tag">
+ <span>{{ value }}</span>
+ <span
+ v-if="allowRemove"
+ class="remove"
+ @click="removeValue(label, value)"
+ >
+ <heroicons-solid:x class="w-3 h-3" />
+ </span>
+ </div>
+ <AddLabelValue
+ v-if="allowEdit"
+ :label="label"
+ @add="(v) => addValue(label, v)"
+ />
+ </div>
+ </BBTableCell>
+ </template>
+ </BBTable>
+ </div>
+ </div>
+</template>
+
+<script lang="ts">
+import { computed, defineComponent, watchEffect } from "vue";
+import { useStore } from "vuex";
+import { isDBAOrOwner } from "../utils";
+import { Principal, Label, LabelPatch } from "../types";
+import { BBTableColumn } from "../bbkit/types";
+import { BBTable, BBTableCell } from "../bbkit";
+import { useI18n } from "vue-i18n";
+import AddLabelValue from "../components/AddLabelValue.vue";
+
+export default defineComponent({
+ name: "SettingWorkspaceLabels",
+ components: {
+ BBTable,
+ BBTableCell,
+ AddLabelValue,
+ },
+ setup() {
+ const { t } = useI18n();
+ const store = useStore();
+ const currentUser = computed(
+ () => store.getters["auth/currentUser"]() as Principal
+ );
+
+ const prepareLabelList = () => {
+ store.dispatch("label/fetchLabelList");
+ };
+
+ watchEffect(prepareLabelList);
+
+ const labelList = computed(
+ () => store.getters["label/labelList"]() as Label[]
+ );
+
+ const allowEdit = computed(() => {
+ return isDBAOrOwner(currentUser.value.role);
+ });
+
+ const allowRemove = computed(() => {
+ // no, we don't allow to remove values now
+ return false;
+ // return allowEdit.value;
+ });
+
+ const addValue = (label: Label, value: string) => {
+ const labelPatch: LabelPatch = {
+ valueList: [...label.valueList, value],
+ };
+ store.dispatch("label/patchLabel", {
+ id: label.id,
+ labelPatch,
+ });
+ };
+
+ const removeValue = (label: Label, value: string) => {
+ const valueList = [...label.valueList];
+ const index = valueList.indexOf(value);
+ if (index < 0) return;
+ valueList.splice(index, 1);
+ const labelPatch: LabelPatch = {
+ valueList,
+ };
+ store.dispatch("label/patchLabel", {
+ id: label.id,
+ labelPatch,
+ });
+ };
+
+ const COLUMN_LIST = computed((): BBTableColumn[] => [
+ {
+ title: t("setting.label.key"),
+ },
+ {
+ title: t("setting.label.values"),
+ },
+ ]);
+
+ return {
+ COLUMN_LIST,
+ labelList,
+ allowEdit,
+ allowRemove,
+ addValue,
+ removeValue,
+ };
+ },
+});
+</script>
+
+<style scoped lang="postcss">
+.tags {
+ @apply flex flex-wrap gap-2;
+}
+.tag {
+ @apply h-6 bg-blue-100 border-blue-300 border px-2 rounded whitespace-nowrap inline-flex items-center;
+}
+.tag > .remove {
+ @apply ml-1 -mr-1 p-px cursor-pointer hover:bg-blue-300 rounded-sm;
+}
+</style>