From 5a8e2dee2f2d7b95e855dd553149a683a298f24c Mon Sep 17 00:00:00 2001 From: Fachba Date: Sat, 25 Oct 2025 23:54:22 +0700 Subject: [PATCH] integration api history alarm and event alarm --- src/api/history-value.jsx | 21 +++++++ .../alarm/component/ListHistoryAlarm.jsx | 60 ++++++++++++++----- .../event/component/ListHistoryEvent.jsx | 39 ++++++------ 3 files changed, 86 insertions(+), 34 deletions(-) create mode 100644 src/api/history-value.jsx diff --git a/src/api/history-value.jsx b/src/api/history-value.jsx new file mode 100644 index 0000000..b96f39a --- /dev/null +++ b/src/api/history-value.jsx @@ -0,0 +1,21 @@ +import { SendRequest } from '../components/Global/ApiRequest'; + +const getAllHistoryAlarm = async (queryParams) => { + const response = await SendRequest({ + method: 'get', + prefix: `history/alarm?${queryParams.toString()}`, + }); + + return response.data; +}; + +const getAllHistoryEvent = async (queryParams) => { + const response = await SendRequest({ + method: 'get', + prefix: `history/event?${queryParams.toString()}`, + }); + + return response.data; +}; + +export { getAllHistoryAlarm, getAllHistoryEvent }; diff --git a/src/pages/history/alarm/component/ListHistoryAlarm.jsx b/src/pages/history/alarm/component/ListHistoryAlarm.jsx index e11124a..b80e9f0 100644 --- a/src/pages/history/alarm/component/ListHistoryAlarm.jsx +++ b/src/pages/history/alarm/component/ListHistoryAlarm.jsx @@ -2,6 +2,7 @@ import React, { memo, useState, useEffect } from 'react'; import { Button, Row, Col, Card, Input } from 'antd'; import { SearchOutlined } from '@ant-design/icons'; import TableList from '../../../../components/Global/TableList'; +import { getAllHistoryAlarm } from '../../../../api/history-value'; const ListHistoryAlarm = memo(function ListHistoryAlarm(props) { const columns = [ @@ -16,7 +17,8 @@ const ListHistoryAlarm = memo(function ListHistoryAlarm(props) { title: 'Datetime', dataIndex: 'datetime', key: 'datetime', - width: '10%', + width: '15%', + // render: (_, record) => toAppDateTimezoneFormatter(record.datetime), }, { title: 'Tag Name', @@ -26,50 +28,78 @@ const ListHistoryAlarm = memo(function ListHistoryAlarm(props) { }, { title: 'Value', - dataIndex: 'stat', - key: 'stat', + dataIndex: 'new_val', + key: 'new_val', width: '10%', + render: (_, record) => Number(record.new_val).toFixed(4), }, { title: 'Threshold', dataIndex: 'threshold', key: 'threshold', width: '10%', + render: (_, record) => { + switch (record.status) { + case 1: + return ( + + {record.lim_low + 1} : {record.lim_high - 1} + + ); + case 2: + return {`< ${record.lim_low_crash}`}; + case 3: + return ( + + {record.lim_low_crash + 1} : {record.lim_low - 1} + + ); + case 4: + return ( + + {record.lim_high + 1} : {record.lim_high_crash - 1} + + ); + case 5: + return {`> ${record.lim_high_crash}`}; + default: + return Undefined; + } + }, }, { title: 'Condition', dataIndex: 'condition', key: 'condition', width: '20%', + render: (_, record) => ( + + ), }, { title: 'Stat', - dataIndex: 'stat', - key: 'stat', + dataIndex: 'status', + key: 'status', width: '5%', }, ]; const [trigerFilter, setTrigerFilter] = useState(false); - const defaultFilter = { search: '' }; + const defaultFilter = { criteria: '' }; const [formDataFilter, setFormDataFilter] = useState(defaultFilter); const [searchValue, setSearchValue] = useState(''); - const getAllEventAlarm = async (params) => { - return { - data: [], - }; - }; - const handleSearch = () => { - setFormDataFilter({ search: searchValue }); + setFormDataFilter({ criteria: searchValue }); setTrigerFilter((prev) => !prev); }; const handleSearchClear = () => { setSearchValue(''); - setFormDataFilter({ search: '' }); + setFormDataFilter({ criteria: '' }); setTrigerFilter((prev) => !prev); }; @@ -113,7 +143,7 @@ const ListHistoryAlarm = memo(function ListHistoryAlarm(props) { toAppDateTimezoneFormatter(record.datetime), }, { title: 'Tag Name', @@ -25,39 +27,38 @@ const ListHistoryEvent = memo(function ListHistoryEvent(props) { width: '40%', }, { - title: 'Stat', - dataIndex: 'stat', - key: 'stat', - width: '5%', + title: 'Description', + dataIndex: 'condition', + key: 'condition', + width: '20%', + render: (_, record) => ( + + ), }, { - title: 'Description', - dataIndex: 'description', - key: 'description', - width: '15%', + title: 'Stat', + dataIndex: 'status', + key: 'status', + width: '5%', }, ]; const [trigerFilter, setTrigerFilter] = useState(false); - const defaultFilter = { search: '' }; + const defaultFilter = { criteria: '' }; const [formDataFilter, setFormDataFilter] = useState(defaultFilter); const [searchValue, setSearchValue] = useState(''); - const getAllEventAlarm = async (params) => { - return { - data: [], - }; - }; - const handleSearch = () => { - setFormDataFilter({ search: searchValue }); + setFormDataFilter({ criteria: searchValue }); setTrigerFilter((prev) => !prev); }; const handleSearchClear = () => { setSearchValue(''); - setFormDataFilter({ search: '' }); + setFormDataFilter({ criteria: '' }); setTrigerFilter((prev) => !prev); }; @@ -101,7 +102,7 @@ const ListHistoryEvent = memo(function ListHistoryEvent(props) {