diff --git a/src/forge/DevOps/cardList/api.js b/src/forge/DevOps/cardList/api.js index 7dce8c03c..de157299f 100644 --- a/src/forge/DevOps/cardList/api.js +++ b/src/forge/DevOps/cardList/api.js @@ -1,65 +1,40 @@ -import fetch from './fetch'; -export function addPipelines(owner, repo, data) { - return fetch({ - url:`/v1/${ owner }/${ repo }/pipelines`, - method: 'POST', - data - }) +import axios from 'axios'; +export async function addPipelines(owner, repo, data) { + const res = await axios.post(`/v1/${ owner }/${ repo }/pipelines`, data); + return res.data; } -export function getCardList(owner, repo, params) { - return fetch({ - url:`/v1/${ owner }/${ repo }/pipelines`, - method: 'get', - params - }) +export async function getCardList(owner, repo, params) { + const res = await axios.get(`/v1/${owner}/${repo}/pipelines`, { params }); + return res.data; } -export function getTemplateList() { - return fetch({ - url:`/action/templates.json`, - method: 'get', - }) +export async function getTemplateList() { + const res = await axios.get(`/action/templates.json`); + return res.data; } -export function getProjectBranch(owner, repo) { - return fetch({ - url:`/${ owner }/${ repo }/branches.json`, - method: 'GET', - }) +export async function getProjectBranch(owner, repo) { + const res = await axios.get(`/${ owner }/${ repo }/branches.json`); + return res.data; } -export function runPipeline(owner, repo, params) { - return fetch({ - url:`/v1/${ owner }/${ repo }/actions/runs.json`, - method: 'post', - data: params - }) +export async function runPipeline(owner, repo, params) { + const res = await axios.get(`/v1/${ owner }/${ repo }/actions/runs.json`, { params }); + return res.data; } -export function delPipelines(owner, repo, id) { - return fetch({ - url:`/v1/${ owner }/${ repo }/pipelines/${ id }.json`, - method: 'DELETE', - }) +export async function delPipelines(owner, repo, id) { + const res = await axios.delete(`/v1/${ owner }/${ repo }/pipelines/${ id }.json`); + return res.data; } -export function stopPipelines(owner, repo, params) { - return fetch({ - url:`/v1/${ owner }/${ repo }/actions/disable.json`, - method: 'POST', - data: params - }) +export async function stopPipelines(owner, repo, data) { + const res = await axios.post(`/v1/${ owner }/${ repo }/actions/disable.json`, data); + return res.data; } -export function startPipelines(owner, repo, params) { - return fetch({ - url:`/v1/${ owner }/${ repo }/actions/enable.json`, - method: 'POST', - data: params - }) -} - - - - +export async function startPipelines(owner, repo, data) { + const res = await axios.post(`/v1/${ owner }/${ repo }/actions/enable.json`, data); + return res.data; +} \ No newline at end of file diff --git a/src/forge/DevOps/cardList/fetch.js b/src/forge/DevOps/cardList/fetch.js deleted file mode 100644 index babbe58fe..000000000 --- a/src/forge/DevOps/cardList/fetch.js +++ /dev/null @@ -1,7 +0,0 @@ -import javaFetch from '../../javaFetch'; - -// let settings = JSON.parse(localStorage.chromesetting); - -const service = javaFetch('/api'); -export default service; -export const TokenKey = 'autologin_trustie'; \ No newline at end of file diff --git a/src/forge/DevOps/cardList/index.jsx b/src/forge/DevOps/cardList/index.jsx index e14bb2172..337db25e7 100644 --- a/src/forge/DevOps/cardList/index.jsx +++ b/src/forge/DevOps/cardList/index.jsx @@ -1,25 +1,28 @@ import { message, Popover, Button, Divider, Switch, Modal, Pagination } from "antd"; -import React, { useEffect, useState } from "react"; +import React, { useEffect, useState, useRef } from "react"; import './index.scss'; import { secondsToTimeFormat, timeAgo } from "../../../common/DateUtil"; import { runPipeline, delPipelines, stopPipelines, startPipelines, getCardList } from './api' import Nodata from "../../Nodata"; import New from "./newModal"; +import devops from '../../Images/devops.png'; const { confirm } = Modal; -function CardDevops(props) { - const { project, match } = props || {}; +function CardDevops(props) { + const { project, match, isManager, isDeveloper, isReporter } = props || {}; const {owner, projectsId} = match.params; const [list, setList] = useState([]) const [ visible , setVisible ] = useState(false); const [ pageNum , setPageNum ] = useState(1); const [ total , setTotal ] = useState(0); const pageSize = 20; + + const intervalRef = useRef(null); let settings = localStorage.chromesetting && JSON.parse(localStorage.chromesetting); let pipelineUrl = settings && settings.common.pipeline; - + const isMember = isManager || isDeveloper || isReporter; useEffect(() => { document.title = `流水线-${owner}/${projectsId}`; @@ -27,21 +30,38 @@ function CardDevops(props) { useEffect(()=>{ getList(); - const intervalId = setInterval(() => { - getList(); - }, 10000); - return () => clearInterval(intervalId); - }, [pageNum]) + + if (intervalRef.current) { + clearInterval(intervalRef.current); + } + + if(isMember){ + intervalRef.current = setInterval(() => { + getList(); + }, 10000); + } + + return () => { + if (intervalRef.current) { + clearInterval(intervalRef.current); + } + }; + }, [isMember, pageNum]) function getList(){ - getCardList(owner, projectsId, { limit: pageSize, page: pageNum }).then(res => { + isMember && getCardList(owner, projectsId, { limit: pageSize, page: pageNum }).then(res => { if (res.status === 0) { setList(res.pipelines.map(e => { e.run_data = e.run_data || {} return e })) setTotal(res.count) - } + }else{ + if (intervalRef.current) { + clearInterval(intervalRef.current); + intervalRef.current = null; + } + } }) } @@ -114,64 +134,72 @@ function CardDevops(props) { onCancel={()=>setVisible(false)} onOk={()=>{setVisible(false);getList()}} /> - -
-
- {statusEnum[+e.run_data.status] || ((!e.json && !e.yaml) ? "待设计" : "待启动")} - {!!e.run_data.total && #{e.run_data.total} {timeAgo(e.run_data.stopped)} 执行时长{secondsToTimeFormat(e.run_data.length)}} - -分支:{e.branch}
-+
+ {statusEnum[+e.run_data.status] || ((!e.json && !e.yaml) ? "待设计" : "待启动")} + {!!e.run_data.total && #{e.run_data.total} {timeAgo(e.run_data.stopped)} 执行时长{secondsToTimeFormat(e.run_data.length)}} + +分支:{e.branch}
+