Skip to content

Commit

Permalink
fix: delete project
Browse files Browse the repository at this point in the history
  • Loading branch information
xsteadybcgo committed Sep 10, 2021
1 parent 98d0755 commit 6aa0f94
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/pages/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ const Home: React.FC = (): ReactElement => {
},
],
}
const chart = echarts.init(requestsEchart.current!)
chart.setOption(requestOption)
if (requestsEchart.current) {
const chart = echarts.init(requestsEchart.current)
chart.setOption(requestOption)
}
})
}, [chartType])

Expand Down
31 changes: 23 additions & 8 deletions src/pages/Projects/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState, useRef, useEffect, useCallback, useContext, FC } from 'react'
import { message } from 'antd'
import { useTranslation } from 'react-i18next'
import { useParams, useLocation } from 'react-router-dom'
import { useParams, useLocation, useHistory } from 'react-router-dom'
import { ENDPOINTS_URL, WSS_ENDPOINTS_URL } from '../../config/origin'
import OverviewCard from '../../shared/components/OverviewCard'
import CreateProjectBtn from '../../shared/components/CreateProjectBtn'
Expand Down Expand Up @@ -29,6 +29,7 @@ import PageLoading from '../../shared/components/PageLoading'

const Projects: FC<{}> = () => {
const location = useLocation<{ pid: string }>()
const history = useHistory()
const [loading, setloading] = useState(true)
const [tabNum, setTabNum] = useState(0)
const [viewType, switchToView] = useState<'setting' | 'request'>('request')
Expand Down Expand Up @@ -101,8 +102,12 @@ const Projects: FC<{}> = () => {
.then(
() => {
message.success(t('tip.delete'))
setTabNum(tabNum - 1 > 0 ? tabNum - 1 : 0)
updatePageData()
const nextTabIdx = tabNum - 1 >= 0 ? tabNum - 1 : 0
projectInfo.splice(tabNum, 1)
const data = projectInfo.slice()
handleSwitchTab(data[nextTabIdx]?.pid)
setProjectInfo(data)
switchToView('request')
updateMenu()
updateUser()
// 更新页面数据
Expand All @@ -117,16 +122,26 @@ const Projects: FC<{}> = () => {
setDeleteModalVisible(false)
}

const handleSwitchTab = useCallback(
(pid: string) => {
history.replace(location.pathname, { pid })
},
[history, location.pathname]
)

useEffect(() => {
updatePageData()
}, [updatePageData])

useEffect(() => {
if (projectInfo.length > 0 && location.state) {
if (projectInfo.length > 0 && location.state?.pid) {
const idx = projectInfo.findIndex((i) => i.pid === location.state.pid)
setTabNum(idx)
}
}, [projectInfo, location.state])
if (projectInfo.length > 0 && !location.state?.pid) {
handleSwitchTab(projectInfo[0].pid)
}
}, [projectInfo, location.state?.pid, handleSwitchTab])

return loading ? (
<PageLoading />
Expand All @@ -145,7 +160,7 @@ const Projects: FC<{}> = () => {
key={data.name}
className={`tab-item ${tabNum === index ? 'active' : ''}`}
onClick={() => {
setTabNum(index)
handleSwitchTab(projectInfo[index].pid)
}}
>
{data.name}
Expand Down Expand Up @@ -205,7 +220,7 @@ const Projects: FC<{}> = () => {
percentageData={{
formatter: formatSize,
used: projectInfo[tabNum]?.bw,
limit: projectInfo[tabNum].bwDayLimit,
limit: projectInfo[tabNum]?.bwDayLimit,
onlyPercentage: false,
}}
tooltip={t('tip.BandwidthNumTip')}
Expand All @@ -216,7 +231,7 @@ const Projects: FC<{}> = () => {
<OverviewCard
percentageData={{
used: projectInfo[tabNum]?.reqCnt,
limit: projectInfo[tabNum].reqDayLimit,
limit: projectInfo[tabNum]?.reqDayLimit,
onlyPercentage: false,
}}
tooltip={t('tip.RequestNumTip')}
Expand Down

0 comments on commit 6aa0f94

Please sign in to comment.