|
|
|
@ -1,19 +1,30 @@
|
|
|
|
import { startML, useLastMLRun } from "../api.js";
|
|
|
|
import { startML, useLastMLRun } from "../api.js";
|
|
|
|
import { Button, Popover, Spin, Tooltip } from "antd";
|
|
|
|
import { Button, Popover, Spin, Tooltip } from "antd";
|
|
|
|
import { InfoCircleOutlined, LoadingOutlined } from "@ant-design/icons";
|
|
|
|
import { InfoCircleOutlined, LoadingOutlined } from "@ant-design/icons";
|
|
|
|
import { useMemo } from "react";
|
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
|
|
|
|
|
|
|
|
const TASK_STATUSES = {
|
|
|
|
const TASK_STATUSES = {
|
|
|
|
finished: "Перерасчет ML завершен"
|
|
|
|
finished: "Перерасчет ML завершен"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
export function LastMLRun() {
|
|
|
|
export function LastMLRun() {
|
|
|
|
const { data } = useLastMLRun();
|
|
|
|
const { data } = useLastMLRun();
|
|
|
|
const hasFinishedUpdate = useMemo(() => {
|
|
|
|
const [isUpdating, setIsUpdating] = useState(false);
|
|
|
|
return data?.task_status === TASK_STATUSES.finished
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
setIsUpdating(data?.task_status !== TASK_STATUSES.finished);
|
|
|
|
}, [data]);
|
|
|
|
}, [data]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const startUpdating = async () => {
|
|
|
|
|
|
|
|
setIsUpdating(true);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
await startML();
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
setIsUpdating(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const lastMLRunRender = () => {
|
|
|
|
const lastMLRunRender = () => {
|
|
|
|
if (hasFinishedUpdate) return (
|
|
|
|
if (!isUpdating) return (
|
|
|
|
<>
|
|
|
|
<>
|
|
|
|
<div className="text-xs text-grey z-10 bg-white-background rounded-xl px-2 py-0.5 space-y-3">
|
|
|
|
<div className="text-xs text-grey z-10 bg-white-background rounded-xl px-2 py-0.5 space-y-3">
|
|
|
|
Последнее обновление системы
|
|
|
|
Последнее обновление системы
|
|
|
|
@ -21,7 +32,7 @@ export function LastMLRun() {
|
|
|
|
<div className="text-xs text-grey z-10 bg-white-background rounded-xl px-2 py-0.5 space-y-3">
|
|
|
|
<div className="text-xs text-grey z-10 bg-white-background rounded-xl px-2 py-0.5 space-y-3">
|
|
|
|
{new Date(data?.last_time).toLocaleString('ru-RU')}
|
|
|
|
{new Date(data?.last_time).toLocaleString('ru-RU')}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<Button type="text" className="flex items-center p-2 text-[#C50000] hover:text-[#C50000] text-xs" onClick={() => startML()}>
|
|
|
|
<Button type="text" className="flex items-center p-2 text-[#C50000] hover:text-[#C50000] text-xs" onClick={() => startUpdating()}>
|
|
|
|
Обновить систему
|
|
|
|
Обновить систему
|
|
|
|
</Button>
|
|
|
|
</Button>
|
|
|
|
</>
|
|
|
|
</>
|
|
|
|
@ -45,7 +56,7 @@ export function LastMLRun() {
|
|
|
|
>
|
|
|
|
>
|
|
|
|
<Tooltip title="Инфо">
|
|
|
|
<Tooltip title="Инфо">
|
|
|
|
<Button className="absolute bottom-[64px] right-[20px] flex items-center justify-center p-3">
|
|
|
|
<Button className="absolute bottom-[64px] right-[20px] flex items-center justify-center p-3">
|
|
|
|
{hasFinishedUpdate
|
|
|
|
{!isUpdating
|
|
|
|
? <InfoCircleOutlined className="w-4 h-4" />
|
|
|
|
? <InfoCircleOutlined className="w-4 h-4" />
|
|
|
|
: <Spin indicator={<LoadingOutlined style={{ fontSize: 16, color: "#000000" }} spin />} />
|
|
|
|
: <Spin indicator={<LoadingOutlined style={{ fontSize: 16, color: "#000000" }} spin />} />
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|