Skip to content

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

refactor: issue-sidebar with better typing support (#1205)

Liu Ji228e709e7bec
diff --git a/frontend/src/components/Issue/IssueSidebar.vue b/frontend/src/components/Issue/IssueSidebar.vue
index e548cc6fb2..14eeba61a6 100644
--- a/frontend/src/components/Issue/IssueSidebar.vue
+++ b/frontend/src/components/Issue/IssueSidebar.vue
@@ -8,9 +8,12 @@
</h2>
<div class="col-span-2">
<span class="flex items-center space-x-2">
- <IssueStatusIcon :issue-status="issue.status" :size="'normal'" />
+ <IssueStatusIcon
+ :issue-status="(issue as Issue).status"
+ :size="'normal'"
+ />
<span class="text-main capitalize">
- {{ issue.status.toLowerCase() }}
+ {{ (issue as Issue).status.toLowerCase() }}
</span>
</span>
</div>
@@ -26,7 +29,7 @@
<MemberSelect
class="w-full"
:disabled="!allowEditAssignee"
- :selectedId="create ? issue.assigneeId : issue.assignee?.id"
+ :selectedId="create ? (issue as IssueCreate).assigneeId : (issue as Issue).assignee?.id"
:allowed-role-list="['OWNER', 'DBA']"
@select-principal-id="
(principalId: number) => {
@@ -75,8 +78,8 @@
</h2>
<div class="col-span-2">
<StageSelect
- :pipeline="issue.pipeline"
- :selected-id="selectedStage.id"
+ :pipeline="(issue.pipeline as Pipeline)"
+ :selected-id="(selectedStage as Stage).id"
@select-stage-id="(stageId) => $emit('select-stage-id', stageId)"
/>
</div>
@@ -88,9 +91,9 @@
</h2>
<div class="col-span-2">
<TaskSelect
- :pipeline="issue.pipeline"
- :stage="selectedStage"
- :selected-id="task.id"
+ :pipeline="(issue.pipeline as Pipeline)"
+ :stage="(selectedStage as Stage)"
+ :selected-id="(task as Task).id"
@select-task-id="(taskId) => $emit('select-task-id', taskId)"
/>
</div>
@@ -221,14 +224,14 @@
{{ $t("common.updated-at") }}
</h2>
<span class="textfield col-span-2">
- {{ dayjs(issue.updatedTs * 1000).format("LLL") }}</span
+ {{ dayjs((issue as Issue).updatedTs * 1000).format("LLL") }}</span
>
<h2 class="textlabel flex items-center col-span-1 col-start-1">
{{ $t("common.created-at") }}
</h2>
<span class="textfield col-span-2">
- {{ dayjs(issue.createdTs * 1000).format("LLL") }}</span
+ {{ dayjs((issue as Issue).createdTs * 1000).format("LLL") }}</span
>
<h2 class="textlabel flex items-center col-span-1 col-start-1">
{{ $t("common.creator") }}
@@ -236,13 +239,16 @@
<ul class="col-span-2">
<li class="flex justify-start items-center space-x-2">
<div class="flex-shrink-0">
- <PrincipalAvatar :principal="issue.creator" :size="'SMALL'" />
+ <PrincipalAvatar
+ :principal="(issue as Issue).creator"
+ :size="'SMALL'"
+ />
</div>
<router-link
- :to="`/u/${issue.creator.id}`"
+ :to="`/u/${(issue as Issue).creator.id}`"
class="text-sm font-medium text-main hover:underline"
>
- {{ issue.creator.name }}
+ {{ (issue as Issue).creator.name }}
</router-link>
</li>
</ul>
@@ -250,7 +256,7 @@
</div>
<IssueSubscriberPanel
v-if="!create"
- :issue="issue"
+ :issue="(issue as Issue)"
@add-subscriber-id="
(subscriberId) => $emit('add-subscriber-id', subscriberId)
"
@@ -266,53 +272,49 @@
</aside>
</template>
-<script lang="ts">
-import {
- computed,
- defineComponent,
- PropType,
- reactive,
- watch,
- watchEffect,
-} from "vue";
-import isEqual from "lodash-es/isEqual";
+<script lang="ts" setup>
+import { computed, PropType, reactive, watch, watchEffect } from "vue";
+import { isEqual } from "lodash-es";
import { NDatePicker } from "naive-ui";
-import PrincipalAvatar from "../PrincipalAvatar.vue";
-import MemberSelect from "../MemberSelect.vue";
+import { useRouter } from "vue-router";
+import dayjs from "dayjs";
+import isSameOrAfter from "dayjs/plugin/isSameOrAfter";
+import { storeToRefs } from "pinia";
import StageSelect from "./StageSelect.vue";
import TaskSelect from "./TaskSelect.vue";
import IssueStatusIcon from "./IssueStatusIcon.vue";
import IssueSubscriberPanel from "./IssueSubscriberPanel.vue";
import InstanceEngineIcon from "../InstanceEngineIcon.vue";
+import PrincipalAvatar from "../PrincipalAvatar.vue";
+import MemberSelect from "../MemberSelect.vue";
import FeatureModal from "../FeatureModal.vue";
-
-import { InputField } from "../../plugins";
-import {
+import { InputField } from "@/plugins";
+import type {
Database,
Environment,
Project,
Issue,
IssueCreate,
+ Pipeline,
Task,
TaskCreate,
- EMPTY_ID,
+ TaskId,
Stage,
StageCreate,
+ StageId,
Instance,
- ONBOARDING_ISSUE_ID,
TaskDatabaseCreatePayload,
DatabaseLabel,
-} from "../../types";
+ PrincipalId,
+} from "@/types";
+import { ONBOARDING_ISSUE_ID } from "@/types";
import {
allTaskList,
databaseSlug,
isDBAOrOwner,
isReservedDatabaseLabel,
hidePrefix,
-} from "../../utils";
-import { useRouter } from "vue-router";
-import dayjs from "dayjs";
-import isSameOrAfter from "dayjs/plugin/isSameOrAfter";
+} from "@/utils";
import {
hasFeature,
useCurrentUser,
@@ -321,294 +323,253 @@ import {
useLabelStore,
useProjectStore,
} from "@/store";
-import { storeToRefs } from "pinia";
+
dayjs.extend(isSameOrAfter);
-// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface LocalState {
earliestAllowedTs: number | null;
showFeatureModal: boolean;
}
-export default defineComponent({
- name: "IssueSidebar",
- components: {
- NDatePicker,
- PrincipalAvatar,
- MemberSelect,
- StageSelect,
- TaskSelect,
- IssueStatusIcon,
- IssueSubscriberPanel,
- InstanceEngineIcon,
- FeatureModal,
+const props = defineProps({
+ issue: {
+ required: true,
+ type: Object as PropType<Issue | IssueCreate>,
},
- props: {
- issue: {
- required: true,
- type: Object as PropType<Issue | IssueCreate>,
- },
- task: {
- required: true,
- type: Object as PropType<Task | TaskCreate>,
- },
- create: {
- required: true,
- type: Boolean,
- },
- selectedStage: {
- required: true,
- type: Object as PropType<Stage | StageCreate>,
- },
- inputFieldList: {
- required: true,
- type: Object as PropType<InputField[]>,
- },
- allowEdit: {
- required: true,
- type: Boolean,
- },
- isTenantDeployMode: {
- type: Boolean,
- default: false,
- },
- database: {
- required: true,
- type: Object as PropType<Database | undefined>,
- },
- instance: {
- required: true,
- type: Object as PropType<Instance>,
- },
+ task: {
+ required: true,
+ type: Object as PropType<Task | TaskCreate>,
},
- emits: [
- "update-assignee-id",
- "update-earliest-allowed-time",
- "add-subscriber-id",
- "remove-subscriber-id",
- "update-custom-field",
- "select-stage-id",
- "select-task-id",
- ],
- setup(props, { emit }) {
- const router = useRouter();
- const labelStore = useLabelStore();
- const projectStore = useProjectStore();
-
- const now = new Date();
- const state = reactive<LocalState>({
- earliestAllowedTs: props.task.earliestAllowedTs,
- showFeatureModal: false,
- });
+ create: {
+ required: true,
+ type: Boolean,
+ },
+ selectedStage: {
+ required: true,
+ type: Object as PropType<Stage | StageCreate>,
+ },
+ inputFieldList: {
+ required: true,
+ type: Object as PropType<InputField[]>,
+ },
+ allowEdit: {
+ required: true,
+ type: Boolean,
+ },
+ isTenantDeployMode: {
+ type: Boolean,
+ default: false,
+ },
+ database: {
+ required: true,
+ type: Object as PropType<Database | undefined>,
+ },
+ instance: {
+ required: true,
+ type: Object as PropType<Instance>,
+ },
+});
- watch(
- () => props.task,
- (cur) => {
- // we show user local time
- state.earliestAllowedTs = cur.earliestAllowedTs;
- }
- );
-
- const currentUser = useCurrentUser();
-
- const fieldValue = (field: InputField): string => {
- return props.issue.payload[field.id];
- };
-
- const databaseName = computed((): string | undefined => {
- if (props.database) {
- return props.database.name;
- }
-
- const stage = props.selectedStage as Stage;
- if (
- stage.taskList[0].type == "bb.task.database.create" ||
- stage.taskList[0].type == "bb.task.database.restore"
- ) {
- if (props.create) {
- const stage = props.selectedStage as StageCreate;
- return stage.taskList[0].databaseName;
- }
- return (
- (stage.taskList[0] as Task).payload as TaskDatabaseCreatePayload
- ).databaseName;
- }
- return undefined;
- });
+const emit = defineEmits<{
+ (e: "update-assignee-id", assigneeId: PrincipalId): void;
+ (e: "update-earliest-allowed-time", newTs: number): void;
+ (e: "add-subscriber-id", subscriberId: PrincipalId): void;
+ (e: "remove-subscriber-id", subscriberId: PrincipalId): void;
+ (e: "update-custom-field", field: InputField, value: any): void;
+ (e: "select-stage-id", stageId: StageId): void;
+ (e: "select-task-id", taskId: TaskId): void;
+}>();
+
+const router = useRouter();
+const labelStore = useLabelStore();
+const projectStore = useProjectStore();
+
+const now = new Date();
+const state = reactive<LocalState>({
+ earliestAllowedTs: props.task.earliestAllowedTs,
+ showFeatureModal: false,
+});
- const environment = computed((): Environment => {
- if (props.create) {
- const stage = props.selectedStage as StageCreate;
- return useEnvironmentStore().getEnvironmentById(stage.environmentId);
- }
- const stage = props.selectedStage as Stage;
- return stage.environment;
- });
+watch(
+ () => props.task,
+ (cur) => {
+ // we show user local time
+ state.earliestAllowedTs = cur.earliestAllowedTs;
+ }
+);
+
+const currentUser = useCurrentUser();
+
+const fieldValue = <T = string>(field: InputField): T => {
+ return props.issue.payload[field.id] as T;
+};
+
+const databaseName = computed((): string | undefined => {
+ if (props.database) {
+ return props.database.name;
+ }
+
+ const stage = props.selectedStage as Stage;
+ if (
+ stage.taskList[0].type == "bb.task.database.create" ||
+ stage.taskList[0].type == "bb.task.database.restore"
+ ) {
+ if (props.create) {
+ const stage = props.selectedStage as StageCreate;
+ return stage.taskList[0].databaseName;
+ }
+ return ((stage.taskList[0] as Task).payload as TaskDatabaseCreatePayload)
+ .databaseName;
+ }
+ return undefined;
+});
- const project = computed((): Project => {
- if (props.create) {
- return projectStore.getProjectById(
- (props.issue as IssueCreate).projectId
- );
- }
- return (props.issue as Issue).project;
- });
+const environment = computed((): Environment => {
+ if (props.create) {
+ const stage = props.selectedStage as StageCreate;
+ return useEnvironmentStore().getEnvironmentById(stage.environmentId);
+ }
+ const stage = props.selectedStage as Stage;
+ return stage.environment;
+});
- const prepareLabelList = () => {
- labelStore.fetchLabelList();
- };
+const project = computed((): Project => {
+ if (props.create) {
+ return projectStore.getProjectById((props.issue as IssueCreate).projectId);
+ }
+ return (props.issue as Issue).project;
+});
- watchEffect(prepareLabelList);
+const prepareLabelList = () => {
+ labelStore.fetchLabelList();
+};
- const { labelList } = storeToRefs(labelStore);
+watchEffect(prepareLabelList);
- const visibleLabelList = computed((): DatabaseLabel[] => {
- // transform non-reserved labels to db properties
- if (!props.database) return [];
- if (labelList.value.length === 0) return [];
+const { labelList } = storeToRefs(labelStore);
- return props.database.labels.filter(
- (label) => !isReservedDatabaseLabel(label, labelList.value)
- );
- });
+const visibleLabelList = computed((): DatabaseLabel[] => {
+ // transform non-reserved labels to db properties
+ if (!props.database) return [];
+ if (labelList.value.length === 0) return [];
- const showStageSelect = computed((): boolean => {
- return (
- !props.create && allTaskList((props.issue as Issue).pipeline).length > 1
- );
- });
+ return props.database.labels.filter(
+ (label) => !isReservedDatabaseLabel(label, labelList.value)
+ );
+});
- const showTaskSelect = computed((): boolean => {
- if (props.create) return false;
- const { taskList } = props.selectedStage;
- return taskList.length > 1;
- });
+const showStageSelect = computed((): boolean => {
+ return (
+ !props.create && allTaskList((props.issue as Issue).pipeline).length > 1
+ );
+});
- const showInstance = computed((): boolean => {
- return isDBAOrOwner(currentUser.value.role);
- });
+const showTaskSelect = computed((): boolean => {
+ if (props.create) return false;
+ const { taskList } = props.selectedStage;
+ return taskList.length > 1;
+});
- const allowEditAssignee = computed(() => {
- const issue = props.issue as Issue;
- // We allow the current assignee or DBA to re-assign the issue.
- // Though only DBA can be assigned to the issue, the current
- // assignee might not have DBA role in case its role is revoked after
- // being assigned to the issue.
- return (
- props.create ||
- (issue.id != ONBOARDING_ISSUE_ID &&
- issue.status == "OPEN" &&
- (currentUser.value.id == issue.assignee?.id ||
- isDBAOrOwner(currentUser.value.role)))
- );
- });
+const showInstance = computed((): boolean => {
+ return isDBAOrOwner(currentUser.value.role);
+});
- const allowEditEarliestAllowedTime = computed(() => {
- const issue = props.issue as Issue;
- const task = props.task as Task;
- // only the assignee is allowed to modify EarliestAllowedTime
- return (
- props.create ||
- (issue.id != ONBOARDING_ISSUE_ID &&
- issue.status == "OPEN" &&
- (task.status == "PENDING" || task.status == "PENDING_APPROVAL") &&
- currentUser.value.id == issue.assignee?.id)
- );
- });
+const allowEditAssignee = computed(() => {
+ const issue = props.issue as Issue;
+ // We allow the current assignee or DBA to re-assign the issue.
+ // Though only DBA can be assigned to the issue, the current
+ // assignee might not have DBA role in case its role is revoked after
+ // being assigned to the issue.
+ return (
+ props.create ||
+ (issue.id != ONBOARDING_ISSUE_ID &&
+ issue.status == "OPEN" &&
+ (currentUser.value.id == issue.assignee?.id ||
+ isDBAOrOwner(currentUser.value.role)))
+ );
+});
- const allowEditCustomField = (field: InputField) => {
- return props.allowEdit && (props.create || field.allowEditAfterCreation);
- };
-
- const trySaveCustomField = (field: InputField, value: string | boolean) => {
- if (!isEqual(value, fieldValue(field))) {
- emit("update-custom-field", field, value);
- }
- };
-
- const isDatabaseCreated = computed(() => {
- const stage = props.selectedStage as Stage;
- if (stage.taskList[0].type == "bb.task.database.create") {
- if (props.create) {
- return false;
- }
- return stage.taskList[0].status == "DONE";
- }
- return true;
- });
+const allowEditEarliestAllowedTime = computed(() => {
+ const issue = props.issue as Issue;
+ const task = props.task as Task;
+ // only the assignee is allowed to modify EarliestAllowedTime
+ return (
+ props.create ||
+ (issue.id != ONBOARDING_ISSUE_ID &&
+ issue.status == "OPEN" &&
+ (task.status == "PENDING" || task.status == "PENDING_APPROVAL") &&
+ currentUser.value.id == issue.assignee?.id)
+ );
+});
- // We only show creation label for database create task
- const showDatabaseCreationLabel = computed(() => {
- const stage = props.selectedStage as Stage;
- if (stage.taskList[0].type != "bb.task.database.create") {
- return "";
- }
- return isDatabaseCreated.value ? "(created)" : "(pending create)";
- });
+const allowEditCustomField = (field: InputField) => {
+ return props.allowEdit && (props.create || field.allowEditAfterCreation);
+};
+
+const trySaveCustomField = (field: InputField, value: string | boolean) => {
+ if (!isEqual(value, fieldValue(field))) {
+ emit("update-custom-field", field, value);
+ }
+};
+
+const isDatabaseCreated = computed(() => {
+ const stage = props.selectedStage as Stage;
+ if (stage.taskList[0].type == "bb.task.database.create") {
+ if (props.create) {
+ return false;
+ }
+ return stage.taskList[0].status == "DONE";
+ }
+ return true;
+});
+
+// We only show creation label for database create task
+const showDatabaseCreationLabel = computed(() => {
+ const stage = props.selectedStage as Stage;
+ if (stage.taskList[0].type != "bb.task.database.create") {
+ return "";
+ }
+ return isDatabaseCreated.value ? "(created)" : "(pending create)";
+});
- const clickDatabase = () => {
- // If the database has not been created yet, do nothing
- if (props.database) {
+const clickDatabase = () => {
+ // If the database has not been created yet, do nothing
+ if (props.database) {
+ router.push({
+ name: "workspace.database.detail",
+ params: {
+ databaseSlug: databaseSlug(props.database),
+ },
+ });
+ } else {
+ useDatabaseStore()
+ .fetchDatabaseByInstanceIdAndName({
+ instanceId: props.instance.id,
+ name: databaseName.value!, // guarded in template to ensure databaseName is not empty
+ })
+ .then((database: Database) => {
router.push({
name: "workspace.database.detail",
params: {
- databaseSlug: databaseSlug(props.database),
+ databaseSlug: databaseSlug(database),
},
});
- } else {
- useDatabaseStore()
- .fetchDatabaseByInstanceIdAndName({
- instanceId: props.instance.id,
- name: databaseName.value!, // guarded in template to ensure databaseName is not empty
- })
- .then((database: Database) => {
- router.push({
- name: "workspace.database.detail",
- params: {
- databaseSlug: databaseSlug(database),
- },
- });
- });
- }
- };
-
- const isDayPassed = (ts: number) => !dayjs(ts).isSameOrAfter(now, "day");
-
- const updateEarliestAllowedTs = (newTimestampMiliSec: number) => {
- if (!hasFeature("bb.feature.task-schedule-time")) {
- state.showFeatureModal = true;
- return;
- }
-
- // n-date-picker would pass timestamp in milisecond.
- // We divide it by 1000 to get timestamp in second
- const newTs = newTimestampMiliSec / 1000;
- state.earliestAllowedTs = newTs;
- emit("update-earliest-allowed-time", newTs);
- };
-
- return {
- EMPTY_ID,
- state,
- fieldValue,
- environment,
- databaseName,
- project,
- hidePrefix,
- visibleLabelList,
- showInstance,
- showStageSelect,
- showTaskSelect,
- allowEditAssignee,
- allowEditEarliestAllowedTime,
- allowEditCustomField,
- trySaveCustomField,
- isDatabaseCreated,
- showDatabaseCreationLabel,
- clickDatabase,
- isDayPassed,
- updateEarliestAllowedTs,
- };
- },
-});
+ });
+ }
+};
+
+const isDayPassed = (ts: number) => !dayjs(ts).isSameOrAfter(now, "day");
+
+const updateEarliestAllowedTs = (newTimestampMS: number) => {
+ if (!hasFeature("bb.feature.task-schedule-time")) {
+ state.showFeatureModal = true;
+ return;
+ }
+
+ // n-date-picker would pass timestamp in millisecond.
+ // We divide it by 1000 to get timestamp in second
+ const newTs = newTimestampMS / 1000;
+ state.earliestAllowedTs = newTs;
+ emit("update-earliest-allowed-time", newTs);
+};
</script>
diff --git a/frontend/src/plugins/types.ts b/frontend/src/plugins/types.ts
index 927ba49ab3..af4c37ee4c 100644
--- a/frontend/src/plugins/types.ts
+++ b/frontend/src/plugins/types.ts
@@ -56,6 +56,7 @@ export type InputField = {
type: InputFieldType;
// Whether to allow edit after creation.
allowEditAfterCreation: boolean;
+ required?: boolean;
// Whether the field is resolved.
// One use case is together with "required" field to validate whether it's ready to submit the data.
// For OUTPUT, one use case is to validate whether the field is filled properly according to the issue.