lavoce #10
@@ -19,6 +19,7 @@ const TableList = memo(function TableList({
|
|||||||
cardColor,
|
cardColor,
|
||||||
fieldColor,
|
fieldColor,
|
||||||
firstLoad = true,
|
firstLoad = true,
|
||||||
|
columnDynamic = false,
|
||||||
}) {
|
}) {
|
||||||
const [gridLoading, setGridLoading] = useState(false);
|
const [gridLoading, setGridLoading] = useState(false);
|
||||||
|
|
||||||
@@ -31,6 +32,8 @@ const TableList = memo(function TableList({
|
|||||||
total_page: 1,
|
total_page: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [columnsDynamic, setColumnsDynamic] = useState(columns);
|
||||||
|
|
||||||
const [viewMode, setViewMode] = useState('table');
|
const [viewMode, setViewMode] = useState('table');
|
||||||
|
|
||||||
const { useBreakpoint } = Grid;
|
const { useBreakpoint } = Grid;
|
||||||
@@ -57,6 +60,49 @@ const TableList = memo(function TableList({
|
|||||||
const param = new URLSearchParams({ ...paging, ...queryParams });
|
const param = new URLSearchParams({ ...paging, ...queryParams });
|
||||||
const resData = await getData(param);
|
const resData = await getData(param);
|
||||||
|
|
||||||
|
if (columnDynamic && resData) {
|
||||||
|
const columnsApi = resData[columnDynamic] ?? '';
|
||||||
|
|
||||||
|
// Pisahkan string menjadi array kolom
|
||||||
|
const colArray = columnsApi.split(',').map((c) => c.trim());
|
||||||
|
|
||||||
|
// Kolom default datetime di awal
|
||||||
|
const defaultColumns = [
|
||||||
|
{
|
||||||
|
title: 'No',
|
||||||
|
key: 'no',
|
||||||
|
width: '5%',
|
||||||
|
align: 'center',
|
||||||
|
render: (_, __, index) => index + 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Datetime',
|
||||||
|
dataIndex: 'datetime',
|
||||||
|
key: 'datetime',
|
||||||
|
width: '15%',
|
||||||
|
// render: (value) => dayjs(value).format('YYYY-MM-DD HH:mm:ss'),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
// Buat kolom numerik dengan format 4 angka di belakang koma
|
||||||
|
const numericColumns = colArray.map((colName) => ({
|
||||||
|
title: colName,
|
||||||
|
dataIndex: colName,
|
||||||
|
key: colName,
|
||||||
|
align: 'right',
|
||||||
|
width: 'auto',
|
||||||
|
render: (value) => {
|
||||||
|
if (typeof value === 'number') {
|
||||||
|
return value.toFixed(4);
|
||||||
|
}
|
||||||
|
return value ?? '-';
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Gabungkan default + API columns
|
||||||
|
setColumnsDynamic([...defaultColumns, ...numericColumns]);
|
||||||
|
}
|
||||||
|
|
||||||
setData(resData?.data ?? []);
|
setData(resData?.data ?? []);
|
||||||
|
|
||||||
const pagingData = resData?.paging;
|
const pagingData = resData?.paging;
|
||||||
@@ -71,6 +117,8 @@ const TableList = memo(function TableList({
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setGridLoading(false);
|
||||||
|
|
||||||
if (resData) {
|
if (resData) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
setGridLoading(false);
|
setGridLoading(false);
|
||||||
@@ -109,7 +157,7 @@ const TableList = memo(function TableList({
|
|||||||
cardColor={cardColor}
|
cardColor={cardColor}
|
||||||
fieldColor={fieldColor}
|
fieldColor={fieldColor}
|
||||||
data={data}
|
data={data}
|
||||||
column={columns}
|
column={columnsDynamic}
|
||||||
header={header}
|
header={header}
|
||||||
showPreviewModal={showPreviewModal}
|
showPreviewModal={showPreviewModal}
|
||||||
showEditModal={showEditModal}
|
showEditModal={showEditModal}
|
||||||
@@ -119,7 +167,7 @@ const TableList = memo(function TableList({
|
|||||||
<Row gutter={24} style={{ marginTop: '16px' }}>
|
<Row gutter={24} style={{ marginTop: '16px' }}>
|
||||||
<Table
|
<Table
|
||||||
rowSelection={rowSelection || null}
|
rowSelection={rowSelection || null}
|
||||||
columns={columns}
|
columns={columnsDynamic}
|
||||||
dataSource={data.map((item, index) => ({ ...item, key: index }))}
|
dataSource={data.map((item, index) => ({ ...item, key: index }))}
|
||||||
pagination={false}
|
pagination={false}
|
||||||
loading={gridLoading}
|
loading={gridLoading}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ const ListHistoryAlarm = memo(function ListHistoryAlarm(props) {
|
|||||||
case 1:
|
case 1:
|
||||||
return (
|
return (
|
||||||
<span>
|
<span>
|
||||||
{record.lim_low + 1} : {record.lim_high - 1}
|
{record.lim_low} : {record.lim_high}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
case 2:
|
case 2:
|
||||||
@@ -51,13 +51,13 @@ const ListHistoryAlarm = memo(function ListHistoryAlarm(props) {
|
|||||||
case 3:
|
case 3:
|
||||||
return (
|
return (
|
||||||
<span>
|
<span>
|
||||||
{record.lim_low_crash + 1} : {record.lim_low - 1}
|
{record.lim_low_crash} : {record.lim_low}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
case 4:
|
case 4:
|
||||||
return (
|
return (
|
||||||
<span>
|
<span>
|
||||||
{record.lim_high + 1} : {record.lim_high_crash - 1}
|
{record.lim_high} : {record.lim_high_crash}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
case 5:
|
case 5:
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ import { Button, Row, Col, Card, Input, DatePicker, Select, Typography } from 'a
|
|||||||
import TableList from '../../../../components/Global/TableList';
|
import TableList from '../../../../components/Global/TableList';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import { FileTextOutlined } from '@ant-design/icons';
|
import { FileTextOutlined } from '@ant-design/icons';
|
||||||
import { getAllHistoryValueReport } from '../../../../api/history-value';
|
import {
|
||||||
|
getAllHistoryValueReport,
|
||||||
|
getAllHistoryValueReportPivot,
|
||||||
|
} from '../../../../api/history-value';
|
||||||
import { getAllPlantSection } from '../../../../api/master-plant-section';
|
import { getAllPlantSection } from '../../../../api/master-plant-section';
|
||||||
|
|
||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
@@ -29,19 +32,19 @@ const ListReport = memo(function ListReport(props) {
|
|||||||
key: 'tag_name',
|
key: 'tag_name',
|
||||||
width: '70%',
|
width: '70%',
|
||||||
},
|
},
|
||||||
{
|
// {
|
||||||
title: 'Value',
|
// title: 'Value',
|
||||||
dataIndex: 'val',
|
// dataIndex: 'val',
|
||||||
key: 'val',
|
// key: 'val',
|
||||||
width: '10%',
|
// width: '10%',
|
||||||
render: (_, record) => Number(record.val).toFixed(4),
|
// render: (_, record) => Number(record.val).toFixed(4),
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
title: 'Stat',
|
// title: 'Stat',
|
||||||
dataIndex: 'status',
|
// dataIndex: 'status',
|
||||||
key: 'status',
|
// key: 'status',
|
||||||
width: '10%',
|
// width: '10%',
|
||||||
},
|
// },
|
||||||
];
|
];
|
||||||
|
|
||||||
const dateNow = dayjs();
|
const dateNow = dayjs();
|
||||||
@@ -49,21 +52,21 @@ const ListReport = memo(function ListReport(props) {
|
|||||||
|
|
||||||
const [trigerFilter, setTrigerFilter] = useState(false);
|
const [trigerFilter, setTrigerFilter] = useState(false);
|
||||||
|
|
||||||
|
const [plantSubSection, setPlantSubSection] = useState(0);
|
||||||
|
const [plantSubSectionList, setPlantSubSectionList] = useState([]);
|
||||||
|
const [startDate, setStartDate] = useState(dateNow);
|
||||||
|
const [endDate, setEndDate] = useState(dateNow);
|
||||||
|
const [periode, setPeriode] = useState(10);
|
||||||
|
|
||||||
const defaultFilter = {
|
const defaultFilter = {
|
||||||
criteria: '',
|
criteria: '',
|
||||||
plant_sub_section_id: 0,
|
plant_sub_section_id: 0,
|
||||||
from: dateNowFormated,
|
from: dateNowFormated,
|
||||||
to: dateNowFormated,
|
to: dateNowFormated,
|
||||||
interval: 10,
|
interval: periode,
|
||||||
};
|
};
|
||||||
const [formDataFilter, setFormDataFilter] = useState(defaultFilter);
|
const [formDataFilter, setFormDataFilter] = useState(defaultFilter);
|
||||||
|
|
||||||
const [plantSubSection, setPlantSubSection] = useState(0);
|
|
||||||
const [plantSubSectionList, setPlantSubSectionList] = useState([]);
|
|
||||||
const [startDate, setStartDate] = useState(dateNow);
|
|
||||||
const [endDate, setEndDate] = useState(dateNow);
|
|
||||||
const [periode, setPeriode] = useState(5);
|
|
||||||
|
|
||||||
const handleSearch = () => {
|
const handleSearch = () => {
|
||||||
const formattedDateStart = startDate.format('YYYY-MM-DD');
|
const formattedDateStart = startDate.format('YYYY-MM-DD');
|
||||||
const formattedDateEnd = endDate.format('YYYY-MM-DD');
|
const formattedDateEnd = endDate.format('YYYY-MM-DD');
|
||||||
@@ -199,9 +202,13 @@ const ListReport = memo(function ListReport(props) {
|
|||||||
<Col xs={24} sm={24} md={24} lg={24} xl={24} style={{ marginTop: '16px' }}>
|
<Col xs={24} sm={24} md={24} lg={24} xl={24} style={{ marginTop: '16px' }}>
|
||||||
<TableList
|
<TableList
|
||||||
firstLoad={false}
|
firstLoad={false}
|
||||||
getData={getAllHistoryValueReport}
|
mobile
|
||||||
|
cardColor={'#d38943ff'}
|
||||||
|
header={'datetime'}
|
||||||
|
getData={getAllHistoryValueReportPivot}
|
||||||
queryParams={formDataFilter}
|
queryParams={formDataFilter}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
|
columnDynamic={'columns'}
|
||||||
triger={trigerFilter}
|
triger={trigerFilter}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
|
|||||||
@@ -62,10 +62,10 @@ const ReportTrending = memo(function ReportTrending(props) {
|
|||||||
: [],
|
: [],
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// setTrendingValue(cleanedData);
|
setTrendingValue(cleanedData);
|
||||||
} else {
|
} else {
|
||||||
// 🔹 Jika tidak ada data dari API
|
// 🔹 Jika tidak ada data dari API
|
||||||
// setTrendingValue([]);
|
setTrendingValue([]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user