-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add stats #132
Merged
Merged
feat: add stats #132
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
@import '~@app/common.less'; | ||
.nebula-stats { | ||
.operations { | ||
margin: 20px 0 17px; | ||
display: flex; | ||
align-items: center; | ||
font-size: 14px; | ||
.ant-btn { | ||
width: 110px; | ||
} | ||
.label { | ||
margin-left: 30px; | ||
color: @darkGray; | ||
} | ||
.label::after { | ||
content: ": "; | ||
padding-right: 5px; | ||
} | ||
} | ||
} |
125 changes: 125 additions & 0 deletions
125
app/pages/Schema/SchemaConfig/List/SpaceStats/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import { Button, Table, message } from 'antd'; | ||
import dayjs from 'dayjs'; | ||
import React, { useEffect, useMemo, useRef, useState } from 'react'; | ||
import intl from 'react-intl-universal'; | ||
import { useParams } from 'react-router-dom'; | ||
import { observer } from 'mobx-react-lite'; | ||
import { useStore } from '@app/stores'; | ||
import { IJobStatus } from '@app/interfaces/schema'; | ||
import { trackPageView } from '@app/utils/stat'; | ||
import Cookie from 'js-cookie'; | ||
|
||
import './index.less'; | ||
|
||
const SpaceStats = () => { | ||
const timer = useRef<NodeJS.Timeout | null>(null); | ||
const { schema: { getJobStatus, submitStats, getStats } } = useStore(); | ||
const { space } = useParams() as { space :string }; | ||
const [data, setData] = useState([]); | ||
const [updateTime, setUpdateTime] = useState(''); | ||
const [jobId, setJobId] = useState<any>(null); | ||
const [loading, setLoading] = useState(false); | ||
const columns = useMemo(() => [ | ||
{ | ||
title: intl.get('schema.statsType'), | ||
dataIndex: 'Type', | ||
}, | ||
{ | ||
title: intl.get('schema.statsName'), | ||
dataIndex: 'Name', | ||
}, | ||
{ | ||
title: intl.get('schema.statsCount'), | ||
dataIndex: 'Count', | ||
}, | ||
], [Cookie.get('lang')]); | ||
useEffect(() => { | ||
trackPageView('/space/stats'); | ||
initData(); | ||
getJobs(); | ||
return () => { | ||
timer.current && clearTimeout(timer.current); | ||
}; | ||
}, [space]); | ||
|
||
const initData = () => { | ||
setJobId(null); | ||
setUpdateTime(''); | ||
setData([]); | ||
}; | ||
|
||
const getData = async() => { | ||
const { code, data } = await getStats(); | ||
if (code === 0) { | ||
setData(data.tables); | ||
} | ||
}; | ||
|
||
const getJobs = async() => { | ||
const { code, data } = await getJobStatus(); | ||
if (code === 0) { | ||
const stat = data.tables.filter(item => item.Command === 'STATS')[0]; | ||
if (stat?.Status === IJobStatus.Finished) { | ||
getData(); | ||
setUpdateTime(stat['Stop Time']); | ||
} else if (stat) { | ||
const jobId = stat['Job Id']; | ||
setJobId(jobId); | ||
getStatStatus(jobId); | ||
} | ||
} | ||
}; | ||
|
||
const getStatStatus = async id => { | ||
const { code, data } = await getJobStatus(id); | ||
if (code === 0) { | ||
const job = data.tables[0]; | ||
if (job.Status === IJobStatus.Finished) { | ||
getData(); | ||
setUpdateTime(job['Stop Time']); | ||
setJobId(null); | ||
message.success(intl.get('schema.statFinished')); | ||
} else if ([IJobStatus.Running, IJobStatus.Queue].includes(job.Status)) { | ||
timer.current = setTimeout(() => getStatStatus(id), 2000); | ||
} else if (job.Status === 'FAILED') { | ||
message.warning(intl.get('schema.statError')); | ||
setJobId(null); | ||
} | ||
} | ||
}; | ||
const handleSubmitStats = async() => { | ||
setLoading(true); | ||
const { code, data } = await submitStats(); | ||
setLoading(false); | ||
if (code === 0) { | ||
const id = data.tables[0]['New Job Id']; | ||
setJobId(id); | ||
await getStatStatus(id); | ||
} | ||
}; | ||
return ( | ||
<div className="nebula-stats"> | ||
<div className="operations"> | ||
<Button | ||
type="primary" | ||
onClick={handleSubmitStats} | ||
loading={loading || jobId !== null} | ||
> | ||
{intl.get('schema.refresh')} | ||
</Button> | ||
<span className="label">{intl.get('schema.lastRefreshTime')}</span> | ||
<span> | ||
{updateTime ? dayjs(updateTime).format('YYYY-MM-DD HH:mm:ss') : null} | ||
</span> | ||
</div> | ||
<Table | ||
className="expanded-table" | ||
dataSource={data} | ||
columns={columns} | ||
rowKey="Name" | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default observer(SpaceStats); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only
exact
is enough, this is optional