Skip to content

Commit 0fcf606

Browse files
committed
move task expire test function to frontHelpers
1 parent aafce08 commit 0fcf606

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

packages/web/src/helpers/frontHelpers.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,25 @@ export function arrayToCsv(array = []){
135135
URL.revokeObjectURL(pom.href);
136136
document.body.removeChild(pom);
137137
}, 5000);
138+
}
139+
140+
export function getTaskExpireStatusAndColor(taskMeta){
141+
let endDate;
142+
let status;
143+
let color;
144+
let now = Date.now();
145+
if(taskMeta.endTime){
146+
endDate = new Date(taskMeta.endTime).valueOf();
147+
}
148+
if(now > endDate){
149+
status = 'Expired';
150+
color = 'red';
151+
}else if (now + 1000 * 3600 * 24 > endDate){
152+
status = 'Expiring soon';
153+
color = 'yellow';
154+
}else{
155+
status = 'Running';
156+
color = 'green';
157+
}
158+
return {status, color};
138159
}

packages/web/src/pages/task/list.tsx

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useImmerAtom } from 'jotai/immer';
44
import { useResetAtom } from 'jotai/utils'
55
import { createTaskDetailAtom, monacoEditorAtom, userInfoAtom } from '../../atoms';
66
import { CronTime } from '@webest/web-page-monitor-helper';
7-
import { fetchAPI, useI18n, innerHTML, useHeadTitle, arrayToCsv, downloadBlob, genClassNameAndString } from "../../helpers/index";
7+
import { fetchAPI, useI18n, innerHTML, useHeadTitle, arrayToCsv, downloadBlob, genClassNameAndString, getTaskExpireStatusAndColor } from "../../helpers/index";
88
import Link from "next/link";
99
import { ScriptList } from "../../components/scriptList";
1010
import { useRouter } from "next/router";
@@ -98,27 +98,12 @@ const TaskListSimpPage: NextPage = () => {
9898
id: 'runningStatus',
9999
width: 200,
100100
Cell: ({ row: {original: or} }) => {
101-
let status;
102-
let endDate;
103-
let color;
104-
let now = Date.now();
105-
if(or.endTime){
106-
endDate = new Date(or.endTime).valueOf();
107-
}
108-
if(now > endDate){
109-
status = t('Expired');
110-
color = 'red';
111-
}else if (now + 1000 * 3600 * 24 > endDate){
112-
status = t('Expiring soon');
113-
color = 'yellow';
114-
}else{
115-
status = t('Running');
116-
color = 'green';
117-
}
101+
let {status , color } = getTaskExpireStatusAndColor(or);
102+
let transLateStatus = t(status);
118103
return (
119104
<>
120105
<span {...cn(`statusIcon${color} statusIcon`)}></span>
121-
{ status }
106+
{ transLateStatus }
122107
</>
123108
)
124109
}

0 commit comments

Comments
 (0)