From de137c90d2fb992b258bc16f01dffa7856a0abd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E9=9B=BE=E4=B8=89=E8=AF=AD?= <32354856+baiwusanyu-c@users.noreply.github.com> Date: Tue, 11 Apr 2023 21:20:35 +0800 Subject: [PATCH] feat: Multi-select rebase function --- .../chrome-option/components/Pr-List.tsx | 98 +++++++++++++++---- 1 file changed, 79 insertions(+), 19 deletions(-) diff --git a/packages/extension/chrome-option/components/Pr-List.tsx b/packages/extension/chrome-option/components/Pr-List.tsx index ff9a85f..815f8f3 100644 --- a/packages/extension/chrome-option/components/Pr-List.tsx +++ b/packages/extension/chrome-option/components/Pr-List.tsx @@ -4,6 +4,7 @@ import { ExclamationCircleFilled } from '@ant-design/icons' import { useEffect, useRef, useState } from 'react' import { createRunList } from '@pr-checker/utils/common' import { compareBranch, getPRDetail, rebasePr } from '@pr-checker/fetchGit' +import type React from 'react' import type { IRepoWithPRs } from './Repo-List' import type { ColumnsType } from 'antd/es/table' @@ -21,6 +22,7 @@ interface DataType { opFlag: 0 | 1 | 2 html_url: string author: string + id: number } // TODO merge @@ -36,9 +38,11 @@ export const PrList = (props: PrListProps) => { useEffect(() => { if (props.repoInfo.pullRequests.length > 0) { setLoading(true) - handleTableData(props.repoInfo.pullRequests) + if(props.opType === 'rebase'){ + handleTableData(props.repoInfo.pullRequests) + } } - }, [props.repoInfo]) + }, [props.repoInfo, props.opType]) async function handleTableData(prl: Record[]) { // rebase @@ -51,6 +55,7 @@ export const PrList = (props: PrListProps) => { state: 'no update', html_url: prl[i].html_url, opFlag: 0, + id: prl[i].id, } // get pr detail data res = await compareBranchToUpdate(prl[i].number, repo, res as DataType) @@ -104,24 +109,17 @@ export const PrList = (props: PrListProps) => { icon: , content: (
-

Do you want to rebase this pr?

- [{item.repoName}]: #{item.number} +

Do you want to rebase this PR?

+ [{item.repoName}]: + #{item.number}
), onOk() { return new Promise((resolve) => { const run = async() => { if (props.opType === 'rebase') { - try { - // TODO refactor with mul - const res = await rebasePr(props.token, item.repoName, item.number) - resolve(res) - messageApi.open({ - type: 'success', - content: 'rebase success', - }) - } catch (e) { - console.error(e) - } + const res = await rebasePrList(props.token, item.repoName, [item.number]) + resolve(res) + handleTableData(props.repoInfo.pullRequests) } } run() @@ -130,6 +128,64 @@ export const PrList = (props: PrListProps) => { }) } + async function rebasePrList(token: string, repoName: string, numberArr: number[] | string[]) { + try { + await Promise.all(createRunList(numberArr.length, async(i: number) => { + await rebasePr(token, repoName, numberArr[i]) + })) + messageApi.open({ + type: 'success', + content: 'rebase success', + }) + } catch (e) { + console.error(e) + } + } + let selectedNumberData: string[] = [] + const rowSelection = { + onChange: (selectedRowKeys: React.Key[], selectedRows: DataType[]) => { + selectedNumberData = selectedRows.map(v => v.number) + }, + getCheckboxProps: (record: DataType) => ({ + disabled: record.opFlag !== 2, + }), + } + + const handleOpAll = async() => { + if (selectedNumberData.length === 0) { + messageApi.open({ + type: 'warning', + content: 'Select the row you want to work on', + }) + return + } + if (props.opType === 'rebase') { + confirm({ + title: 'Tips', + icon: , + content: ( +
+

Do you want to rebase these PRs?

+
), + onOk() { + return new Promise((resolve) => { + const run = async() => { + if (props.opType === 'rebase') { + const res = await rebasePrList(props.token, props.repoInfo.uname, selectedNumberData) + resolve(res) + setLoading(true) + handleTableData(props.repoInfo.pullRequests) + } + } + run() + }) + }, + }) + // const res = await rebasePrList(props.token, item.repoName, [item.number]) + // resolve(res) + } + } + const columns: ColumnsType = [ { title: 'PR Number', @@ -177,7 +233,7 @@ export const PrList = (props: PrListProps) => { dataIndex: 'state', render: (_, { state, opFlag }) => { if (opFlag === 0) - return 🎉{state} + return 🎉 {state} else if (opFlag === 1) return 🔥 {state} else @@ -210,20 +266,24 @@ export const PrList = (props: PrListProps) => {
-
['data']} scroll={{ y: 'calc(100vh - 200px)' }} pagination={false} - rowSelection /> {contextHolder}