Skip to content
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(console): add job actions #1220

Merged
merged 1 commit into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion console/src/domain/job/schemas/task.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { IAgentSchema } from './agent'

export enum TaskStatusType {
CREATED = 'CREATED',
ASSIGNING = 'ASSIGNING',
PAUSED = 'PAUSED',
PREPARING = 'PREPARING',
RUNNING = 'RUNNING',
Expand Down
58 changes: 50 additions & 8 deletions console/src/pages/Evaluation/EvaluationOverviewLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import React, { useEffect, useMemo } from 'react'
import { useQuery } from 'react-query'
import { useParams } from 'react-router-dom'
import { INavItem } from '@/components/BaseSidebar'
import { fetchJob } from '@job/services/job'
import { doJobAction, fetchJob } from '@job/services/job'
import BaseSubLayout from '@/pages/BaseSubLayout'
import { durationToStr, formatTimestampDateTime } from '@/utils/datetime'
import IconFont from '@/components/IconFont/index'
import Accordion from '@/components/Accordion'
import { Panel } from 'baseui/accordion'
import { JobActionType, JobStatusType } from '@/domain/job/schemas/job'
import { toaster } from 'baseui/toast'
import Button from '@/components/Button'

export interface IJobLayoutProps {
children: React.ReactNode
Expand All @@ -24,16 +27,13 @@ function EvaluationOverviewLayout({ children }: IJobLayoutProps) {
useEffect(() => {
setJobLoading(jobInfo.isLoading)
if (jobInfo.isSuccess) {
if (jobInfo.data?.id !== job?.id) {
setJob(jobInfo.data)
}
setJob(jobInfo.data)
} else if (jobInfo.isLoading) {
setJob(undefined)
}
}, [job?.id, jobInfo.data, jobInfo.isLoading, jobInfo.isSuccess, setJob, setJobLoading])

const [t] = useTranslation()
const uuid = job?.uuid ?? '-'

const breadcrumbItems: INavItem[] = useMemo(() => {
const items = [
Expand All @@ -42,12 +42,12 @@ function EvaluationOverviewLayout({ children }: IJobLayoutProps) {
path: `/projects/${projectId}/evaluations`,
},
{
title: uuid,
title: job?.uuid ?? '-',
path: `/projects/${projectId}/evaluations/${jobId}`,
},
]
return items
}, [projectId, jobId, t, uuid])
}, [projectId, jobId, t, job])

const navItems: INavItem[] = useMemo(() => {
const items = [
Expand Down Expand Up @@ -157,9 +157,51 @@ function EvaluationOverviewLayout({ children }: IJobLayoutProps) {
),
[job, info, t]
)
const handleAction = React.useCallback(
async (jobIdArg, type: JobActionType) => {
await doJobAction(projectId, jobIdArg, type)
toaster.positive(t('job action done'), { autoHideDuration: 2000 })
await jobInfo.refetch()
},
[jobInfo, projectId, t]
)

const extra = React.useMemo(() => {
if (!job) return <></>

const actions: Partial<Record<JobStatusType, React.ReactNode>> = {
[JobStatusType.CREATED]: (
<>
<Button onClick={() => handleAction(job.id, JobActionType.CANCEL)}>{t('Cancel')}</Button>
&nbsp;&nbsp;
<Button onClick={() => handleAction(job.id, JobActionType.PAUSE)}>{t('Pause')}</Button>
</>
),
[JobStatusType.RUNNING]: (
<>
<Button onClick={() => handleAction(job.id, JobActionType.CANCEL)}>{t('Cancel')}</Button>
&nbsp;&nbsp;
<Button onClick={() => handleAction(job.id, JobActionType.PAUSE)}>{t('Pause')}</Button>
</>
),
[JobStatusType.PAUSED]: (
<>
<Button onClick={() => handleAction(job.id, JobActionType.CANCEL)}>{t('Cancel')}</Button>
&nbsp;&nbsp;
<Button onClick={() => handleAction(job.id, JobActionType.RESUME)}>{t('Resume')}</Button>
</>
),
[JobStatusType.FAIL]: (
<>
<Button onClick={() => handleAction(job.id, JobActionType.RESUME)}>{t('Resume')}</Button>
</>
),
}
return actions[job.jobStatus]
}, [job, info, t])

return (
<BaseSubLayout header={header} breadcrumbItems={breadcrumbItems} navItems={navItems}>
<BaseSubLayout header={header} breadcrumbItems={breadcrumbItems} navItems={navItems} extra={extra}>
<div style={{ paddingTop: '12px', flex: '1' }}>{children}</div>
</BaseSubLayout>
)
Expand Down
7 changes: 7 additions & 0 deletions console/src/pages/Job/JobListCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ export default function JobListCard() {
</StyledLink>
</>
),
[JobStatusType.FAIL]: (
<>
<StyledLink onClick={() => handleAction(job.id, JobActionType.RESUME)}>
{t('Resume')}
</StyledLink>
</>
),
[JobStatusType.SUCCESS]: (
<TextLink to={`/projects/${projectId}/jobs/${job.id}/results`}>
{t('View Results')}
Expand Down
8 changes: 4 additions & 4 deletions console/src/pages/Job/JobTasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ export default function JobTasks() {
const onAction = useCallback(
async (type, task: ITaskSchema) => {
setCurrentTask(task)
if ([TaskStatusType.RUNNING, TaskStatusType.PREPARING].includes(task.taskStatus)) {
setCurrentLogFiles({
[task?.uuid]: 'ws',
})
if ([TaskStatusType.RUNNING].includes(task.taskStatus)) {
// setCurrentLogFiles({
// [task?.uuid]: 'ws',
// })
} else {
const data = await fetchTaskOfflineLogFiles(task?.id)
if (_.isEmpty(data)) {
Expand Down