Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat(frontend): issue list pagination (#2426)
Liu Ji9ffd2dd130c0
diff --git a/frontend/src/bbkit/BBTable/BBTable.vue b/frontend/src/bbkit/BBTable/BBTable.vueindex 629a1a3394..7062a43e23 100644--- a/frontend/src/bbkit/BBTable/BBTable.vue+++ b/frontend/src/bbkit/BBTable/BBTable.vue@@ -62,12 +62,12 @@</tr></template><template v-else>- <tr>+ <tr v-if="showPlaceholder"><td:colspan="columnList.length"class="text-center text-gray-400">- -+ <slot name="placeholder">-</slot></td></tr></template>@@ -119,6 +119,7 @@ const props = withDefaults(rightBordered?: boolean;topBordered?: boolean;bottomBordered?: boolean;+ showPlaceholder?: boolean;}>(),{columnList: () => [],@@ -133,6 +134,7 @@ const props = withDefaults(rightBordered: true,topBordered: true,bottomBordered: true,+ showPlaceholder: true,});diff --git a/frontend/src/components/Issue/PagedIssueTable.vue b/frontend/src/components/Issue/PagedIssueTable.vuenew file mode 100644index 0000000000..367218b7d1--- /dev/null+++ b/frontend/src/components/Issue/PagedIssueTable.vue@@ -0,0 +1,116 @@+<template>+ <slot name="table" :issue-list="state.issueList" :loading="state.loading" />++ <div+ v-if="state.loading"+ class="flex items-center justify-center py-2 text-gray-400 text-sm"+ >+ <BBSpin />+ </div>++ <slot+ v-if="!state.loading"+ name="more"+ :has-more="state.hasMore"+ :fetch-next-page="fetchNextPage"+ >+ <div+ v-if="!hideLoadMore && pageSize > 0 && state.hasMore"+ class="flex items-center justify-center py-2 text-gray-400 text-sm hover:bg-gray-200 cursor-pointer"+ @click="fetchNextPage"+ >+ {{ $t("common.load-more") }}+ </div>+ </slot>+</template>++<script lang="ts" setup>+import { buildQueryListByIssueFind, useIssueStore } from "@/store";+import { Issue, IssueFind } from "@/types";+import { computed, PropType, reactive, watch } from "vue";++type LocalState = {+ loading: boolean;+ issueList: Issue[];+ paginationToken: string;+ hasMore: boolean;+};++const MAX_PAGE_SIZE = 1000;++const props = defineProps({+ issueFind: {+ type: Object as PropType<IssueFind>,+ default: undefined,+ },+ pageSize: {+ type: Number,+ default: 10,+ },+ hideLoadMore: {+ type: Boolean,+ default: false,+ },+});++const state = reactive<LocalState>({+ loading: false,+ issueList: [],+ paginationToken: "",+ hasMore: true,+});++const issueStore = useIssueStore();++const limit = computed(() => {+ if (props.pageSize <= 0) return MAX_PAGE_SIZE;+ return props.pageSize;+});++const condition = computed(() => {+ const issueFind = {+ ...props.issueFind,+ limit: limit.value,+ };+ return buildQueryListByIssueFind(issueFind).join("&");+});++const fetchData = (refresh = false) => {+ state.loading = true;+ issueStore+ .fetchPagedIssueList({+ ...props.issueFind,+ limit: limit.value,+ token: state.paginationToken,+ })+ .then(({ nextToken, issueList }) => {+ if (refresh) {+ state.issueList = issueList;+ } else {+ state.issueList.push(...issueList);+ }++ if (issueList.length === 0) {+ state.hasMore = false;+ }++ state.paginationToken = nextToken;+ })+ .finally(() => {+ state.loading = false;+ });+};++const refresh = () => {+ state.paginationToken = "";+ state.hasMore = true;+ fetchData(true);+};++const fetchNextPage = () => {+ fetchData(false);+};++fetchData(true);+watch(condition, refresh);+</script>diff --git a/frontend/src/components/ProjectOverviewPanel.vue b/frontend/src/components/ProjectOverviewPanel.vueindex d05a0b2d35..ff14c84a6a 100644--- a/frontend/src/components/ProjectOverviewPanel.vue+++ b/frontend/src/components/ProjectOverviewPanel.vue@@ -83,25 +83,59 @@<p class="text-lg font-medium leading-7 text-main">{{ $t("common.issue") }}</p>- <IssueTable- :mode="'PROJECT'"- :issue-section-list="[- {- title: $t('project.overview.in-progress'),- list: state.progressIssueList,- },- {- title: $t('project.overview.recently-closed'),- list: state.closedIssueList,- },- ]"- />- <router-link- :to="`/issue?status=closed&project=${project.id}`"- class="mt-2 flex justify-end normal-link"- >- {{ $t("project.overview.view-all-closed") }}- </router-link>++ <!-- show OPEN issues with pageSize=10 -->+ <div>+ <PagedIssueTable+ :issue-find="{+ statusList: ['OPEN'],+ projectId: project.id,+ }"+ :page-size="10"+ >+ <template #table="{ issueList, loading }">+ <IssueTable+ :mode="'PROJECT'"+ :issue-section-list="[+ { title: $t('project.overview.in-progress'), list: issueList },+ ]"+ :show-placeholder="!loading"+ />+ </template>+ </PagedIssueTable>++ <!-- show the first 5 DONE or CANCELED issues -->+ <!-- But won't show "Load more", since we have a "View all closed" link below -->+ <PagedIssueTable+ :issue-find="{+ statusList: ['DONE', 'CANCELED'],+ projectId: project.id,+ }"+ :page-size="5"+ :hide-load-more="true"+ >+ <template #table="{ issueList, loading }">+ <IssueTable+ class="-mt-px"+ :mode="'PROJECT'"+ :issue-section-list="[+ {+ title: $t('project.overview.recently-closed'),+ list: issueList,+ },+ ]"+ :show-placeholder="!loading"+ />+ </template>+ </PagedIssueTable>++ <router-link+ :to="`/issue?status=closed&project=${project.id}`"+ class="mt-2 flex justify-end normal-link"+ >+ {{ $t("project.overview.view-all-closed") }}+ </router-link>+ </div></div></div></template>@@ -122,7 +156,8 @@ import TenantDatabaseTable, { YAxisRadioGroup } from "./TenantDatabaseTable";import { IssueTable } from "../components/Issue";import { Activity, Database, Issue, Project, LabelKeyType } from "../types";import { findDefaultGroupByLabel } from "../utils";-import { useActivityStore, useIssueStore, useLabelList } from "@/store";+import { useActivityStore, useLabelList } from "@/store";+import PagedIssueTable from "@/components/Issue/PagedIssueTable.vue";// Show at most 5 activityconst ACTIVITY_LIMIT = 5;@@ -145,6 +180,7 @@ export default defineComponent({IssueTable,YAxisRadioGroup,NSpin,+ PagedIssueTable,},props: {project: {@@ -186,34 +222,12 @@ export default defineComponent({});};- const prepareIssueList = () => {- useIssueStore()- .fetchIssueList({- projectId: props.project.id,- })- .then((issueList: Issue[]) => {- state.progressIssueList = [];- state.closedIssueList = [];- for (const issue of issueList) {- // "OPEN"- if (issue.status === "OPEN") {- state.progressIssueList.push(issue);- }- // "DONE" or "CANCELED"- else if (issue.status === "DONE" || issue.status === "CANCELED") {- state.closedIssueList.push(issue);- }- }- });- };-const isTenantProject = computed((): boolean => {return props.project.tenantMode === "TENANT";});const prepare = () => {prepareActivityList();- prepareIssueList();};onBeforeMount(prepare);diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 81a6e44fa1..3897de3cd9 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -206,7 +206,7 @@"go-now": "Go now","sync-now": "Sync Now","show-help": "Show help",- "success": "Succeed"+ "load-more": "Load more"},"error-page": {"go-back-home": "Go back home"@@ -630,7 +630,7 @@"template": "Below is an example to create user 'bytebase' with password {password} and grant the user with the needed privileges. First you need to enable ClickHouse SQL-driven workflow {link} and then run the following query to create the user.","sql-driven-workflow": "SQL-driven workflow"},- "postgresql": {+ "postgres": {"warn": "If the connecting instance is managed by the cloud provider, then SUPERUSER is not available and you should create the user via that provider's admin console. The created user will have provider specific semi-SUPERUSER privileges.","template": "Below is an example to create user 'bytebase' with password {password} and grant the user with the needed privileges. If the connecting instance is self-hosted, then you can grant SUPERUSER."}@@ -640,8 +640,6 @@"password-write-only": "YOUR_DB_PWD - write only","test-connection": "Test Connection","ignore-and-create": "Ignore and create",- "create-an-onboarding-postgresql-instance": "Create an onboarding PostgreSQL instance",- "successfully-created-postgresql-instance": "Successfully created onboarding PostgreSQL instance and automatically filled into the form.","connection-info-seems-to-be-incorrect": "Connection info seems to be incorrect","new-instance": "New Instance","unable-to-connect": "Bytebase is unable to connect the instance. We recommend you to review the connection info again. But it's OK to ignore this warning for now. You can still fix the connection info from the instance detail page after creation.\n\nError detail: {0}",@@ -881,8 +879,7 @@"not-found-last-successful-sync-was": "Not found, last successful sync was {time}","view-unassigned-databases": "View unassigned databases","unassigned-databases": "Unassigned databases",- "restore-database": "Restore database",- "selected-n-databases": "{n} database selected | {n} databases selected"+ "restore-database": "Restore database"},"repository": {"branch-observe-file-change": "The branch where Bytebase observes the file change.",@@ -1264,9 +1261,7 @@"format": "Format","sql-review-result": "SQL review result","alter-table": "Alter table",- "open-connection": "Open connection",- "visualize-explain": "Visualize Explain",- "sql-execute-in-protected-environment": "The SQL statement below will be executed in a protected environment."+ "open-connection": "Open connection"},"label": {"empty-label-value": "<Empty Value>",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 421437f94f..5ac5940c75 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -206,7 +206,7 @@"go-now": "立即前往","sync-now": "现在同步","show-help": "查看帮助",- "success": "成功"+ "load-more": "加载更多"},"error-page": {"go-back-home": "回到主页"@@ -631,7 +631,7 @@"sql-driven-workflow": "SQL 工作流","template": "创建用户 bytebase,密码 {password},并授予必要权限的例子如下。您需要首先启用 {link},才能执行以下创建用户的命令。"},- "postgresql": {+ "postgres": {"warn": "如果您将要连接到的实例是由云服务供应商管理的话,那么 SUPERUSER 是不可用的,您需要通过供应商的管理员控制台来创建用户。您所创建的用户会拥有供应商特定的 semi-SUPERUSER 的权限。","template": "创建用户 bytebase,密码 {password},并授予必要权限的例子如下。如果您将要连接到的实例是自己托管的,那么您可以 grant SUPERUSER。"}@@ -641,8 +641,6 @@"password-write-only": "YOUR_DB_PWD - 仅写入","test-connection": "测试连接","ignore-and-create": "忽略并创建",- "create-an-onboarding-postgresql-instance": "创建一个临时的 PostgreSQL 数据库实例",- "successfully-created-postgresql-instance": "成功创建临时的 PostgreSQL 数据库实例,并已经自动填充至表单。","connection-info-seems-to-be-incorrect": "连接信息似乎错误","new-instance": "新实例","unable-to-connect": "Bytebase 无法连接到实例。我们推荐您再检查一遍连接信息。但也可以暂时忽略此警告。您在创建后仍能在实例详细页里修复连接信息。\n\n错误详情:{0}",@@ -882,8 +880,7 @@"not-found-last-successful-sync-was": "未找到,上次成功同步于 {time}","view-unassigned-databases": "查看未分配的数据库","unassigned-databases": "未分配的数据库",- "restore-database": "恢复数据库",- "selected-n-databases": "已选择 {n} 个数据库"+ "restore-database": "恢复数据库"},"repository": {"branch-observe-file-change": "Bytebase 跟踪文件变更的分支。",@@ -1265,9 +1262,7 @@"format": "格式化","sql-review-result": "SQL 检查结果","alter-table": "修改表结构",- "open-connection": "打开连接",- "visualize-explain": "可视化 Explain",- "sql-execute-in-protected-environment": "下面的 SQL 语句将会在受保护的环境中执行。"+ "open-connection": "打开连接"},"label": {"empty-label-value": "<空值>",diff --git a/frontend/src/store/modules/issue.ts b/frontend/src/store/modules/issue.tsindex b97a1dd20c..26dc45c20e 100644--- a/frontend/src/store/modules/issue.ts+++ b/frontend/src/store/modules/issue.ts@@ -6,16 +6,14 @@ import {isPagedResponse,Issue,IssueCreate,+ IssueFind,IssueId,IssuePatch,IssueState,- IssueStatus,IssueStatusPatch,Pipeline,Principal,- PrincipalId,Project,- ProjectId,ResourceIdentifier,ResourceObject,unknown,@@ -133,35 +131,8 @@ export const useIssueStore = defineStore("issue", {setIssueById({ issueId, issue }: { issueId: IssueId; issue: Issue }) {this.issueById.set(issueId, issue);},- async fetchPagedIssueList({- issueStatusList,- userId,- projectId,- limit,- token,- }: {- issueStatusList?: IssueStatus[];- userId?: PrincipalId;- projectId?: ProjectId;- limit?: number;- token?: string;- }) {- const queryList = [];- if (issueStatusList && issueStatusList.length > 0) {- queryList.push(`status=${issueStatusList.join(",")}`);- }- if (userId) {- queryList.push(`user=${userId}`);- }- if (projectId) {- queryList.push(`project=${projectId}`);- }- if (limit) {- queryList.push(`limit=${limit}`);- }- if (token) {- queryList.push(`token=${token}`);- }+ async fetchPagedIssueList(params: IssueFind & { token?: string }) {+ const queryList = buildQueryListByIssueFind(params);let url = "/api/issue";if (queryList.length > 0) {@@ -187,12 +158,7 @@ export const useIssueStore = defineStore("issue", {issueList,};},- async fetchIssueList(params: {- issueStatusList?: IssueStatus[];- userId?: PrincipalId;- projectId?: ProjectId;- limit?: number;- }) {+ async fetchIssueList(params: IssueFind) {const result = await this.fetchPagedIssueList(params);return result.issueList;},@@ -321,3 +287,46 @@ export const useIssueStore = defineStore("issue", {},},});++export const buildQueryListByIssueFind = (+ params: IssueFind & { token?: string }+): string[] => {+ const {+ projectId,+ principalId,+ creatorId,+ assigneeId,+ subscriberId,+ statusList,+ limit,+ token,+ } = params;++ const queryList = [];+ if (statusList && statusList.length > 0) {+ queryList.push(`status=${statusList.join(",")}`);+ }+ if (principalId) {+ queryList.push(`user=${principalId}`);+ }+ if (creatorId) {+ queryList.push(`creator=${creatorId}`);+ }+ if (assigneeId) {+ queryList.push(`assignee=${assigneeId}`);+ }+ if (subscriberId) {+ queryList.push(`subscriber=${subscriberId}`);+ }+ if (projectId) {+ queryList.push(`project=${projectId}`);+ }+ if (limit) {+ queryList.push(`limit=${limit}`);+ }+ if (token) {+ queryList.push(`token=${token}`);+ }++ return queryList;+};diff --git a/frontend/src/types/issue.ts b/frontend/src/types/issue.tsindex f59672df50..9849d03910 100644--- a/frontend/src/types/issue.ts+++ b/frontend/src/types/issue.ts@@ -122,6 +122,21 @@ export type IssueCreate = {payload: IssuePayload;};+export type IssueFind = {+ projectId?: ProjectId;+ principalId?: PrincipalId;+ creatorId?: PrincipalId;+ assigneeId?: PrincipalId;+ subscriberId?: PrincipalId;+ statusList?: IssueStatus[];+ limit?: number;++ // defined in Go but not used yet+ // id?: IssueId;+ // pipelineId?: PipelineId;+ // maxId?: IssueId;+};+export type IssuePatch = {// Domain specific fieldsname?: string;diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vueindex 803b2f8340..7f0a7d7317 100644--- a/frontend/src/views/Home.vue+++ b/frontend/src/views/Home.vue@@ -3,7 +3,7 @@<div class="px-5 py-2 flex justify-between items-center"><!-- eslint-disable vue/attribute-hyphenation --><EnvironmentTabFilter- :selectedId="state.selectedEnvironment?.id"+ :selectedId="selectedEnvironment?.id"@select-environment="selectEnvironment"/><BBTableSearch@@ -12,32 +12,103 @@@change-text="(text) => changeSearchText(text)"/></div>- <IssueTable- :left-bordered="false"- :right-bordered="false"- :top-bordered="true"- :bottom-bordered="true"- :issue-section-list="[- {- title: $t('common.assigned'),- list: filteredList(state.assignedList).sort(openIssueSorter),- },- {- title: $t('common.created'),- list: filteredList(state.createdList).sort(openIssueSorter),- },- {- title: $t('common.subscribed'),- list: filteredList(state.subscribeList).sort(openIssueSorter),- },- {- title: $t('project.overview.recently-closed'),- list: filteredList(state.closedList).sort((a, b) => {- return b.updatedTs - a.updatedTs;- }),- },- ]"- />++ <!-- show OPEN Assigned issues with pageSize=10 -->+ <PagedIssueTable+ :issue-find="{+ statusList: ['OPEN'],+ assigneeId: currentUser.id,+ }"+ :page-size="OPEN_ISSUE_LIST_PAGE_SIZE"+ >+ <template #table="{ issueList, loading }">+ <IssueTable+ :left-bordered="false"+ :right-bordered="false"+ :show-placeholder="!loading"+ :issue-section-list="[+ {+ title: $t('common.assigned'),+ list: issueList.filter(keywordAndEnvironmentFilter),+ },+ ]"+ />+ </template>+ </PagedIssueTable>++ <!-- show OPEN Created issues with pageSize=10 -->+ <PagedIssueTable+ :issue-find="{+ statusList: ['OPEN'],+ creatorId: currentUser.id,+ }"+ :page-size="OPEN_ISSUE_LIST_PAGE_SIZE"+ >+ <template #table="{ issueList, loading }">+ <IssueTable+ class="-mt-px"+ :left-bordered="false"+ :right-bordered="false"+ :show-placeholder="!loading"+ :issue-section-list="[+ {+ title: $t('common.created'),+ list: issueList.filter(keywordAndEnvironmentFilter),+ },+ ]"+ />+ </template>+ </PagedIssueTable>++ <!-- show OPEN Subscribed issues with pageSize=10 -->+ <PagedIssueTable+ :issue-find="{+ statusList: ['OPEN'],+ subscriberId: currentUser.id,+ }"+ :page-size="OPEN_ISSUE_LIST_PAGE_SIZE"+ >+ <template #table="{ issueList, loading }">+ <IssueTable+ class="-mt-px"+ :left-bordered="false"+ :right-bordered="false"+ :show-placeholder="!loading"+ :issue-section-list="[+ {+ title: $t('common.subscribed'),+ list: issueList.filter(keywordAndEnvironmentFilter),+ },+ ]"+ />+ </template>+ </PagedIssueTable>++ <!-- show the first 5 DONE or CANCELED issues -->+ <!-- But won't show "Load more", since we have a "View all closed" link below -->+ <PagedIssueTable+ :issue-find="{+ statusList: ['DONE', 'CANCELED'],+ principalId: currentUser.id,+ }"+ :page-size="MAX_CLOSED_ISSUE"+ :hide-load-more="true"+ >+ <template #table="{ issueList, loading }">+ <IssueTable+ class="-mt-px"+ :left-bordered="false"+ :right-bordered="false"+ :show-placeholder="!loading"+ :issue-section-list="[+ {+ title: $t('project.overview.recently-closed'),+ list: issueList.filter(keywordAndEnvironmentFilter),+ },+ ]"+ />+ </template>+ </PagedIssueTable></div><router-linkto="/issue?status=closed"@@ -47,178 +118,82 @@</router-link></template>-<script lang="ts">-import { watchEffect, onMounted, reactive, ref, defineComponent } from "vue";-import { useRouter } from "vue-router";+<script lang="ts" setup>+import { onMounted, reactive, ref, computed } from "vue";+import { useRoute, useRouter } from "vue-router";import EnvironmentTabFilter from "../components/EnvironmentTabFilter.vue";import { IssueTable } from "../components/Issue";-import { activeEnvironment, activeTask } from "../utils";-import { Environment, Issue, TaskStatus, UNKNOWN_ID } from "../types";-import { useCurrentUser, useEnvironmentStore, useIssueStore } from "@/store";--// Show at most 10 recently closed issues-const MAX_CLOSED_ISSUE_COUNT = 10;+import { activeEnvironment } from "../utils";+import { Environment, Issue } from "../types";+import { useCurrentUser, useEnvironmentStore } from "@/store";+import PagedIssueTable from "@/components/Issue/PagedIssueTable.vue";interface LocalState {- createdList: Issue[];- assignedList: Issue[];- subscribeList: Issue[];- closedList: Issue[];searchText: string;- selectedEnvironment?: Environment;}-export default defineComponent({- name: "HomePage",- components: {- EnvironmentTabFilter,- IssueTable,- },- setup() {- const searchField = ref();-- const issueStore = useIssueStore();- const router = useRouter();-- const state = reactive<LocalState>({- createdList: [],- assignedList: [],- subscribeList: [],- closedList: [],- searchText: "",- selectedEnvironment: router.currentRoute.value.query.environment- ? useEnvironmentStore().getEnvironmentById(- parseInt(router.currentRoute.value.query.environment as string, 10)- )- : undefined,- });-- const currentUser = useCurrentUser();+const OPEN_ISSUE_LIST_PAGE_SIZE = 10;+const MAX_CLOSED_ISSUE = 5;- 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) {- issueStore- .fetchIssueList({- issueStatusList: ["OPEN"],- userId: currentUser.value.id,- })- .then((issueList: Issue[]) => {- state.assignedList = [];- state.createdList = [];- state.subscribeList = [];- for (const issue of issueList) {- 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.subscriberList &&- issue.subscriberList- .map((subscriber) => subscriber.id)- .includes(currentUser.value.id)- ) {- state.subscribeList.push(issue);- }- }- });+const searchField = ref();- issueStore- .fetchIssueList({- issueStatusList: ["DONE", "CANCELED"],- userId: currentUser.value.id,- limit: MAX_CLOSED_ISSUE_COUNT,- })- .then((issueList: Issue[]) => {- state.closedList = [];- for (const issue of issueList) {- if (- issue.creator.id === currentUser.value.id ||- issue.assignee?.id === currentUser.value.id ||- (issue.subscriberList &&- issue.subscriberList- .map((subscriber) => subscriber.id)- .includes(currentUser.value.id))- ) {- state.closedList.push(issue);- }- }- });- }- };+const environmentStore = useEnvironmentStore();+const router = useRouter();+const route = useRoute();- watchEffect(prepareIssueList);+const state = reactive<LocalState>({+ searchText: "",+});- const selectEnvironment = (environment: Environment) => {- state.selectedEnvironment = environment;- if (environment) {- router.replace({- name: "workspace.home",- query: { environment: environment.id },- });- } else {- router.replace({ name: "workspace.home" });- }- };+const currentUser = useCurrentUser();- const changeSearchText = (searchText: string) => {- state.searchText = searchText;- };+const selectedEnvironment = computed(() => {+ const { environment } = route.query;+ return environment+ ? environmentStore.getEnvironmentById(parseInt(environment as string, 10))+ : undefined;+});- 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()))- );- });- };+const keywordAndEnvironmentFilter = (issue: Issue) => {+ if (selectedEnvironment.value) {+ if (activeEnvironment(issue.pipeline).id !== selectedEnvironment.value.id) {+ return false;+ }+ }+ const keyword = state.searchText.trim();+ if (keyword) {+ if (!issue.name.toLowerCase().includes(keyword)) {+ return false;+ }+ }+ return true;+};+const selectEnvironment = (environment: Environment) => {+ if (environment) {+ router.replace({+ name: "workspace.home",+ query: {+ ...route.query,+ environment: environment.id,+ },+ });+ } else {+ router.replace({+ name: "workspace.home",+ query: {+ ...route.query,+ environment: undefined,+ },+ });+ }+};- const openIssueSorter = (a: Issue, b: Issue) => {- const statusOrder = (status: TaskStatus) => {- switch (status) {- case "FAILED":- return 0;- case "PENDING_APPROVAL":- return 1;- case "PENDING":- return 2;- case "RUNNING":- return 3;- case "DONE":- return 4;- case "CANCELED":- return 5;- }- };- const aStatusOrder = statusOrder(activeTask(a.pipeline).status);- const bStatusOrder = statusOrder(activeTask(b.pipeline).status);- if (aStatusOrder == bStatusOrder) {- return b.updatedTs - a.updatedTs;- }- return aStatusOrder - bStatusOrder;- };+const changeSearchText = (searchText: string) => {+ state.searchText = searchText;+};- return {- searchField,- state,- filteredList,- selectEnvironment,- changeSearchText,- openIssueSorter,- };- },+onMounted(() => {+ // Focus on the internal search field when mounted+ searchField.value.$el.querySelector("#search").focus();});</script>diff --git a/frontend/src/views/IssueDashboard.vue b/frontend/src/views/IssueDashboard.vueindex 174d7b3a29..e69026cc98 100644--- a/frontend/src/views/IssueDashboard.vue+++ b/frontend/src/views/IssueDashboard.vue@@ -4,7 +4,7 @@<div class="px-4 py-2 flex justify-between items-center"><!-- eslint-disable vue/attribute-hyphenation --><EnvironmentTabFilter- :selectedId="state.selectedEnvironment?.id"+ :selectedId="selectedEnvironment?.id"@select-environment="selectEnvironment"/><div class="flex flex-row space-x-4">@@ -17,265 +17,200 @@</button><!-- eslint-disable vue/attribute-hyphenation --><MemberSelect- v-if="scopeByPrincipal"class="w-72":show-all="true":show-system-bot="true"- :selected-id="state.selectedPrincipalId"+ :selected-id="selectedPrincipalId"@select-principal-id="selectPrincipal"/><BBTableSearchref="searchField":placeholder="$t('issue.search-issue-name')"- @change-text="(text) => changeSearchText(text)"+ @change-text="(text: string) => changeSearchText(text)"/></div></div>- <IssueTable- :left-bordered="false"- :right-bordered="false"- :top-bordered="true"- :bottom-bordered="true"- :issue-section-list="sectionList"- />++ <!-- show all OPEN issues with pageSize=10 -->+ <PagedIssueTable+ v-if="showOpen"+ :issue-find="{+ statusList: ['OPEN'],+ principalId: selectedPrincipalId > 0 ? selectedPrincipalId : undefined,+ projectId: selectedProjectId,+ }"+ :page-size="10"+ >+ <template #table="{ issueList, loading }">+ <IssueTable+ :left-bordered="false"+ :right-bordered="false"+ :top-bordered="true"+ :bottom-bordered="true"+ :issue-section-list="[+ { title: $t('issue.table.open'), list: issueList.filter(filter) },+ ]"+ :show-placeholder="!loading"+ />+ </template>+ </PagedIssueTable>++ <!-- show all DONE and CANCELED issues with pageSize=10 -->+ <PagedIssueTable+ v-if="showClosed"+ :issue-find="{+ statusList: ['DONE', 'CANCELED'],+ principalId: selectedPrincipalId > 0 ? selectedPrincipalId : undefined,+ projectId: selectedProjectId,+ }"+ :page-size="10"+ >+ <template #table="{ issueList, loading }">+ <IssueTable+ class="-mt-px"+ :left-bordered="false"+ :right-bordered="false"+ :top-bordered="true"+ :bottom-bordered="true"+ :issue-section-list="[+ { title: $t('issue.table.closed'), list: issueList.filter(filter) },+ ]"+ :show-placeholder="!loading"+ />+ </template>+ </PagedIssueTable></div></template>-<script lang="ts">+<script lang="ts" setup>import { useRoute, useRouter } from "vue-router";import EnvironmentTabFilter from "../components/EnvironmentTabFilter.vue";import { IssueTable } from "../components/Issue";import MemberSelect from "../components/MemberSelect.vue";import { EMPTY_ID, Environment, Issue, PrincipalId, ProjectId } from "../types";-import {- reactive,- ref,- computed,- onMounted,- watchEffect,- defineComponent,- watch,-} from "vue";+import { reactive, ref, computed, onMounted } from "vue";import { activeEnvironment, isDBAOrOwner, projectSlug } from "../utils";-import { BBTableSectionDataSource } from "../bbkit/types";-import { useI18n } from "vue-i18n";-import {- useCurrentUser,- useEnvironmentStore,- useIssueStore,- useProjectStore,-} from "@/store";+import { useCurrentUser, useEnvironmentStore, useProjectStore } from "@/store";+import PagedIssueTable from "@/components/Issue/PagedIssueTable.vue";interface LocalState {- showOpen: boolean;- showClosed: boolean;- openList: Issue[];- closedList: Issue[];searchText: string;- selectedPrincipalId: PrincipalId;- selectedEnvironment?: Environment;- selectedProjectId?: ProjectId;}-export default defineComponent({- name: "IssueDashboard",- components: { EnvironmentTabFilter, IssueTable, MemberSelect },- setup() {- const { t } = useI18n();- const searchField = ref();-- const issueStore = useIssueStore();- const router = useRouter();- const route = useRoute();+const searchField = ref();- const currentUser = useCurrentUser();- const projectStore = useProjectStore();+const router = useRouter();+const route = useRoute();- const statusList: string[] = route.query.status- ? (route.query.status as string).split(",")- : [];+const currentUser = useCurrentUser();+const projectStore = useProjectStore();+const environmentStore = useEnvironmentStore();- // Applies principal scope if we explicitly specify user in the query parameter- // or project is NOT present in the query parameter.- // In other words, if only project is present in the query parameter, then- // we do NOT apply principal scope, which is the case if we want to list all issues- // for a particular project.- // Note: We do not use computed, otherwise it will cause prepareIssueList to refetch everytime we click environment tab- const scopeByPrincipal = !route.query.user || !route.query.project;+const statusList = computed((): string[] =>+ route.query.status ? (route.query.status as string).split(",") : []+);- const state = reactive<LocalState>({- showOpen: statusList.length == 0 || statusList.includes("open"),- showClosed: statusList.length == 0 || statusList.includes("closed"),- openList: [],- closedList: [],- searchText: "",- selectedPrincipalId: currentUser.value.id, // initialized below- selectedEnvironment: route.query.environment- ? useEnvironmentStore().getEnvironmentById(- parseInt(route.query.environment as string, 10)- )- : undefined,- selectedProjectId: route.query.project- ? parseInt(route.query.project as string)- : undefined,- });- // initialize the selectedPrincipalId- const initializeSelectedPrincipalIdFromQuery = (): PrincipalId => {- const id = parseInt(route.query.user as string, 10);- if (id >= 0) {- return id;- }- return isDBAOrOwner(currentUser.value.role)- ? EMPTY_ID // default to 'All' if current user is owner or DBA- : currentUser.value.id; // default to current user otherwise- };-- watch(- () => route.query.user,- () => {- state.selectedPrincipalId = initializeSelectedPrincipalIdFromQuery();- },- { immediate: true }- );-- onMounted(() => {- // Focus on the internal search field when mounted- searchField.value.$el.querySelector("#search").focus();- });+const state = reactive<LocalState>({+ searchText: "",+});- const project = computed(() => {- if (state.selectedProjectId) {- return projectStore.getProjectById(state.selectedProjectId);- }- return undefined;- });+const showOpen = computed(+ () => statusList.value.length === 0 || statusList.value.includes("open")+);+const showClosed = computed(+ () => statusList.value.length === 0 || statusList.value.includes("closed")+);++const selectedPrincipalId = computed((): PrincipalId => {+ const id = parseInt(route.query.user as string, 10);+ if (id >= 0) {+ return id;+ }+ return isDBAOrOwner(currentUser.value.role)+ ? EMPTY_ID // default to 'All' if current user is owner or DBA+ : currentUser.value.id; // default to current user otherwise+});- const prepareIssueList = () => {- // We call open and close separately because normally the number of open issues is limited- // while the closed issues could be a lot.- // When "All" is selected, the userId is eventually ignored by `fetchIssueList` because- // it's 0 (EMPTY_ID), so we need not to check the special value here.- if (state.showOpen) {- issueStore- .fetchIssueList({- issueStatusList: ["OPEN"],- userId: scopeByPrincipal ? state.selectedPrincipalId : undefined,- projectId: state.selectedProjectId,- })- .then((issueList: Issue[]) => {- state.openList = issueList;- });- }+const selectedEnvironment = computed((): Environment | undefined => {+ const { environment } = route.query;+ return environment+ ? environmentStore.getEnvironmentById(parseInt(environment as string, 10))+ : undefined;+});- if (state.showClosed) {- issueStore- .fetchIssueList({- issueStatusList: ["DONE", "CANCELED"],- userId: scopeByPrincipal ? state.selectedPrincipalId : undefined,- projectId: state.selectedProjectId,- })- .then((issueList: Issue[]) => {- state.closedList = issueList;- });- }- };+const selectedProjectId = computed((): ProjectId | undefined => {+ const { project } = route.query;+ return project ? parseInt(project as string, 10) : undefined;+});- watchEffect(prepareIssueList);+onMounted(() => {+ // Focus on the internal search field when mounted+ searchField.value.$el.querySelector("#search").focus();+});- 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()))- );- });- };+const project = computed(() => {+ if (selectedProjectId.value) {+ return projectStore.getProjectById(selectedProjectId.value);+ }+ return undefined;+});- const sectionList = computed((): BBTableSectionDataSource<Issue>[] => {- const list = [];- if (state.showOpen) {- list.push({- title: t("issue.table.open"),- list: filteredList(state.openList).sort((a, b) => {- return b.updatedTs - a.updatedTs;- }),- });- }- if (state.showClosed) {- list.push({- title: t("issue.table.closed"),- list: filteredList(state.closedList).sort((a, b) => {- return b.updatedTs - a.updatedTs;- }),- });- }- return list;+const filter = (issue: Issue) => {+ if (selectedEnvironment.value) {+ if (activeEnvironment(issue.pipeline).id !== selectedEnvironment.value.id) {+ return false;+ }+ }+ const keyword = state.searchText.trim();+ if (keyword) {+ if (!issue.name.toLowerCase().includes(keyword)) {+ return false;+ }+ }+ return true;+};++const selectEnvironment = (environment: Environment) => {+ if (environment) {+ router.replace({+ name: "workspace.issue",+ query: {+ ...route.query,+ environment: environment.id,+ },});-- const selectEnvironment = (environment: Environment) => {- state.selectedEnvironment = environment;- if (environment) {- router.replace({- name: "workspace.issue",- query: {- ...route.query,- environment: environment.id,- },- });- } else {- router.replace({- name: "workspace.issue",- query: {- ...route.query,- environment: undefined,- },- });- }- };-- const selectPrincipal = (principalId: PrincipalId) => {- state.selectedPrincipalId = principalId;- router.replace({- name: "workspace.issue",- query: {- ...route.query,- user: principalId,- },- });- };-- const changeSearchText = (searchText: string) => {- state.searchText = searchText;- };-- const goProject = () => {- if (!project.value) return;- router.push({- name: "workspace.project.detail",- params: {- projectSlug: projectSlug(project.value),- },- });- };-- return {- searchField,- state,- scopeByPrincipal,- project,- sectionList,- selectEnvironment,- selectPrincipal,- changeSearchText,- goProject,- };- },-});+ } else {+ router.replace({+ name: "workspace.issue",+ query: {+ ...route.query,+ environment: undefined,+ },+ });+ }+};++const selectPrincipal = (principalId: PrincipalId) => {+ router.replace({+ name: "workspace.issue",+ query: {+ ...route.query,+ user: principalId,+ },+ });+};++const changeSearchText = (searchText: string) => {+ state.searchText = searchText;+};++const goProject = () => {+ if (!project.value) return;+ router.push({+ name: "workspace.project.detail",+ params: {+ projectSlug: projectSlug(project.value),+ },+ });+};</script>