Skip to content

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

Add /issue route to show all closed issue for now

天舟85276afb4c5c
diff --git a/api/issue.go b/api/issue.go
index 7c556bd82b..2c1928ecd7 100644
--- a/api/issue.go
+++ b/api/issue.go
@@ -124,6 +124,9 @@ type IssueFind struct {
PipelineId *int
// Find issue where principalId is either creator, assignee or subscriber
PrincipalId *int
+ StatusList *[]IssueStatus
+ // If specified, then it will only fetch "Limit" most recently updated issues
+ Limit *int
}
func (find *IssueFind) String() string {
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index 31af8e5bc7..f7e7a67bcf 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -320,6 +320,18 @@ const routes: Array<RouteRecordRaw> = [
},
],
},
+ {
+ path: "issue",
+ name: "workspace.issue",
+ meta: {
+ title: () => "Issue",
+ },
+ components: {
+ content: () => import("../views/IssueDashboard.vue"),
+ leftSidebar: DashboardSidebar,
+ },
+ props: { content: true, leftSidebar: true },
+ },
{
path: "environment",
name: "workspace.environment",
@@ -761,6 +773,7 @@ router.beforeEach((to, from, next) => {
to.name === "workspace.project" ||
to.name === "workspace.database" ||
to.name === "workspace.archive" ||
+ to.name === "workspace.issue" ||
to.name === "workspace.environment" ||
(to.name?.toString().startsWith("setting") &&
to.name?.toString() != "setting.workspace.version-control.detail")
diff --git a/frontend/src/store/modules/issue.ts b/frontend/src/store/modules/issue.ts
index 158048fb03..48b220b482 100644
--- a/frontend/src/store/modules/issue.ts
+++ b/frontend/src/store/modules/issue.ts
@@ -7,6 +7,7 @@ import {
IssueId,
IssuePatch,
IssueState,
+ IssueStatus,
IssueStatusPatch,
Pipeline,
PrincipalId,
@@ -75,10 +76,22 @@ const getters = {
const actions = {
async fetchIssueListForUser(
- { commit, rootGetters }: any,
- userId: PrincipalId
+ { rootGetters }: any,
+ {
+ userId,
+ issueStatusList,
+ limit,
+ }: {
+ userId: PrincipalId;
+ issueStatusList: IssueStatus[];
+ limit?: number;
+ }
) {
- const data = (await axios.get(`/api/issue?user=${userId}`)).data;
+ var url = `/api/issue?user=${userId}&status=${issueStatusList.join(",")}`;
+ if (limit) {
+ url += `&limit=${limit}`;
+ }
+ const data = (await axios.get(url)).data;
const issueList = data.data.map((issue: ResourceObject) => {
return convert(issue, data.included, rootGetters);
});
diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vue
index 808847eeeb..bde422e4af 100644
--- a/frontend/src/views/Home.vue
+++ b/frontend/src/views/Home.vue
@@ -38,6 +38,9 @@
]"
/>
</div>
+ <router-link to="/issue" class="mt-2 px-4 flex justify-end normal-link">
+ View all closed
+ </router-link>
</template>
<script lang="ts">
@@ -49,6 +52,9 @@ import IssueTable from "../components/IssueTable.vue";
import { activeEnvironment, activeTask } from "../utils";
import { Environment, Issue, TaskStatus, UNKNOWN_ID } from "../types";
+// Show at most 10 recently closed issues
+const MAX_CLOSED_ISSUE_COUNT = 10;
+
interface LocalState {
createdList: Issue[];
assignedList: Issue[];
@@ -95,34 +101,42 @@ export default {
// It will also be called when user logout
if (currentUser.value.id != UNKNOWN_ID) {
store
- .dispatch("issue/fetchIssueListForUser", currentUser.value.id)
+ .dispatch("issue/fetchIssueListForUser", {
+ userId: currentUser.value.id,
+ issueStatusList: ["OPEN"],
+ })
.then((issueList: Issue[]) => {
state.assignedList = [];
state.createdList = [];
state.subscribeList = [];
- state.closeList = [];
for (const issue of issueList) {
- // "OPEN"
- if (issue.status === "OPEN") {
- if (issue.assignee?.id === currentUser.value.id) {
- state.assignedList.push(issue);
- } else if (issue.creator.id === currentUser.value.id) {
- state.createdList.push(issue);
- } else if (
- issue.subscriberIdList.includes(currentUser.value.id)
- ) {
- state.subscribeList.push(issue);
- }
+ if (issue.assignee?.id === currentUser.value.id) {
+ state.assignedList.push(issue);
+ } else if (issue.creator.id === currentUser.value.id) {
+ state.createdList.push(issue);
+ } else if (
+ issue.subscriberIdList.includes(currentUser.value.id)
+ ) {
+ state.subscribeList.push(issue);
}
- // "DONE" or "CANCELED"
- else if (issue.status === "DONE" || issue.status === "CANCELED") {
- if (
- issue.creator.id === currentUser.value.id ||
- issue.assignee?.id === currentUser.value.id ||
- issue.subscriberIdList.includes(currentUser.value.id)
- ) {
- state.closeList.push(issue);
- }
+ }
+ });
+
+ store
+ .dispatch("issue/fetchIssueListForUser", {
+ userId: currentUser.value.id,
+ issueStatusList: ["DONE", "CANCELED"],
+ limit: MAX_CLOSED_ISSUE_COUNT,
+ })
+ .then((issueList: Issue[]) => {
+ state.closeList = [];
+ for (const issue of issueList) {
+ if (
+ issue.creator.id === currentUser.value.id ||
+ issue.assignee?.id === currentUser.value.id ||
+ issue.subscriberIdList.includes(currentUser.value.id)
+ ) {
+ state.closeList.push(issue);
}
}
});
diff --git a/frontend/src/views/IssueDashboard.vue b/frontend/src/views/IssueDashboard.vue
new file mode 100644
index 0000000000..b10ace36ba
--- /dev/null
+++ b/frontend/src/views/IssueDashboard.vue
@@ -0,0 +1,143 @@
+<template>
+ <!-- This example requires Tailwind CSS v2.0+ -->
+ <div class="flex flex-col">
+ <div class="px-2 py-2 flex justify-between items-center">
+ <EnvironmentTabFilter
+ :selectedId="state.selectedEnvironment?.id"
+ @select-environment="selectEnvironment"
+ />
+ <BBTableSearch
+ ref="searchField"
+ :placeholder="'Search issue name'"
+ @change-text="(text) => changeSearchText(text)"
+ />
+ </div>
+ <IssueTable
+ :leftBordered="false"
+ :rightBordered="false"
+ :topBordered="true"
+ :bottomBordered="true"
+ :issueSectionList="[
+ {
+ title: 'Closed',
+ list: filteredList(state.closeList).sort((a, b) => {
+ return b.updatedTs - a.updatedTs;
+ }),
+ },
+ ]"
+ />
+ </div>
+</template>
+
+<script lang="ts">
+import { reactive, ref } from "@vue/reactivity";
+import { useRouter } from "vue-router";
+import { useStore } from "vuex";
+import EnvironmentTabFilter from "../components/EnvironmentTabFilter.vue";
+import IssueTable from "../components/IssueTable.vue";
+import { Environment, Issue, UNKNOWN_ID } from "../types";
+import { computed, onMounted, watchEffect } from "@vue/runtime-core";
+import { activeEnvironment } from "../utils";
+
+interface LocalState {
+ closeList: Issue[];
+ searchText: string;
+ selectedEnvironment?: Environment;
+}
+
+export default {
+ name: "IssueDashboard",
+ components: { EnvironmentTabFilter, IssueTable },
+ setup(props, ctx) {
+ const searchField = ref();
+
+ const store = useStore();
+ const router = useRouter();
+
+ const state = reactive<LocalState>({
+ closeList: [],
+ searchText: "",
+ selectedEnvironment: router.currentRoute.value.query.environment
+ ? store.getters["environment/environmentById"](
+ router.currentRoute.value.query.environment
+ )
+ : undefined,
+ });
+
+ const currentUser = computed(() => store.getters["auth/currentUser"]());
+
+ onMounted(() => {
+ // Focus on the internal search field when mounted
+ searchField.value.$el.querySelector("#search").focus();
+ });
+
+ const prepareIssueList = () => {
+ // It will also be called when user logout
+ if (currentUser.value.id != UNKNOWN_ID) {
+ store
+ .dispatch("issue/fetchIssueListForUser", {
+ userId: currentUser.value.id,
+ issueStatusList: ["DONE", "CANCELED"],
+ })
+ .then((issueList: Issue[]) => {
+ state.closeList = [];
+ for (const issue of issueList) {
+ // "DONE" or "CANCELED"
+ if (issue.status === "DONE" || issue.status === "CANCELED") {
+ if (
+ issue.creator.id === currentUser.value.id ||
+ issue.assignee?.id === currentUser.value.id ||
+ issue.subscriberIdList.includes(currentUser.value.id)
+ ) {
+ state.closeList.push(issue);
+ }
+ }
+ }
+ });
+ }
+ };
+
+ watchEffect(prepareIssueList);
+
+ const selectEnvironment = (environment: Environment) => {
+ state.selectedEnvironment = environment;
+ if (environment) {
+ router.replace({
+ name: "workspace.issue",
+ query: { environment: environment.id },
+ });
+ } else {
+ router.replace({ name: "workspace.issue" });
+ }
+ };
+
+ const changeSearchText = (searchText: string) => {
+ state.searchText = searchText;
+ };
+
+ const filteredList = (list: Issue[]) => {
+ if (!state.selectedEnvironment && !state.searchText) {
+ // Select "All"
+ return list;
+ }
+ return list.filter((issue) => {
+ return (
+ (!state.selectedEnvironment ||
+ activeEnvironment(issue.pipeline).id ===
+ state.selectedEnvironment.id) &&
+ (!state.searchText ||
+ issue.name.toLowerCase().includes(state.searchText.toLowerCase()))
+ );
+ });
+ };
+
+ return {
+ searchField,
+ state,
+ filteredList,
+ selectEnvironment,
+ changeSearchText,
+ };
+ },
+};
+</script>
diff --git a/server/issue.go b/server/issue.go
index dc81b8e5f9..37a19ac9dc 100644
--- a/server/issue.go
+++ b/server/issue.go
@@ -6,6 +6,7 @@ import (
"fmt"
"net/http"
"strconv"
+ "strings"
"github.com/bytebase/bytebase"
"github.com/bytebase/bytebase/api"
@@ -53,6 +54,20 @@ func (s *Server) registerIssueRoutes(g *echo.Group) {
}
issueFind.ProjectId = &projectId
}
+ if issueStatusListStr := c.QueryParam("status"); issueStatusListStr != "" {
+ statusList := []api.IssueStatus{}
+ for _, status := range strings.Split(issueStatusListStr, ",") {
+ statusList = append(statusList, api.IssueStatus(status))
+ }
+ issueFind.StatusList = &statusList
+ }
+ if limitStr := c.QueryParam("limit"); limitStr != "" {
+ limit, err := strconv.Atoi(limitStr)
+ if err != nil {
+ return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("limit query parameter is not a number: %s", limitStr)).SetInternal(err)
+ }
+ issueFind.Limit = &limit
+ }
userIdStr := c.QueryParams().Get("user")
if userIdStr != "" {
userId, err := strconv.Atoi(userIdStr)
diff --git a/store/issue.go b/store/issue.go
index 8493ac1e6f..691f2b8ed3 100644
--- a/store/issue.go
+++ b/store/issue.go
@@ -202,8 +202,15 @@ func (s *IssueService) findIssueList(ctx context.Context, tx *Tx, find *api.Issu
args = append(args, *v)
args = append(args, *v)
}
+ if v := find.StatusList; v != nil {
+ list := []string{}
+ for _, status := range *v {
+ list = append(list, fmt.Sprintf("'%s'", status))
+ }
+ where = append(where, fmt.Sprintf("`status` in (%s)", strings.Join(list, ",")))
+ }
- rows, err := tx.QueryContext(ctx, `
+ var query = `
SELECT
id,
creator_id,
@@ -213,15 +220,18 @@ func (s *IssueService) findIssueList(ctx context.Context, tx *Tx, find *api.Issu
project_id,
pipeline_id,
name,
- `+"`status`,"+`
- `+"`type`,"+`
+ ` + "`status`," + `
+ ` + "`type`," + `
description,
assignee_id,
payload
FROM issue
- WHERE `+strings.Join(where, " AND "),
- args...,
- )
+ WHERE ` + strings.Join(where, " AND ")
+ if v := find.Limit; v != nil {
+ query += fmt.Sprintf(" ORDER BY updated_ts DESC LIMIT %d", *v)
+ }
+
+ rows, err := tx.QueryContext(ctx, query, args...)
if err != nil {
return nil, FormatError(err)
}