From a834d79b7dfa8441521e73682df417f60a96b648 Mon Sep 17 00:00:00 2001 From: jialin Date: Mon, 15 Jul 2024 10:16:07 +0800 Subject: [PATCH] fix: list local date --- src/components/seal-table/components/table-row.tsx | 14 ++++++-------- src/global.tsx | 4 ++++ src/hooks/use-update-chunk-list.ts | 9 +++++---- src/pages/llmodels/components/instance-item.tsx | 4 +++- src/pages/llmodels/components/table-list.tsx | 14 +++++++++++--- src/pages/llmodels/config/types.ts | 2 ++ src/pages/llmodels/index.tsx | 7 ++++--- 7 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/components/seal-table/components/table-row.tsx b/src/components/seal-table/components/table-row.tsx index 0363f33e..bc50c639 100644 --- a/src/components/seal-table/components/table-row.tsx +++ b/src/components/seal-table/components/table-row.tsx @@ -4,7 +4,7 @@ import { DownOutlined, RightOutlined } from '@ant-design/icons'; import { Button, Checkbox, Col, Empty, Row, Spin } from 'antd'; import classNames from 'classnames'; import _ from 'lodash'; -import React, { useCallback, useEffect, useRef, useState } from 'react'; +import React, { useEffect, useRef, useState } from 'react'; import RowContext from '../row-context'; import { RowContextProps, SealTableProps } from '../types'; @@ -38,13 +38,12 @@ const TableRow: React.FC< const childrenDataRef = useRef([]); childrenDataRef.current = childrenData; - console.log('table row====', record.name, firstLoad, expanded); + console.log('table row====', childrenData, record.name, firstLoad, expanded); const { updateChunkedList, cacheDataListRef } = useUpdateChunkedList({ dataList: childrenData, setDataList: setChildrenData // callback: (list) => renderChildren?.(list) }); - useEffect(() => { if (rowSelection) { const { selectedRowKeys } = rowSelection; @@ -70,13 +69,12 @@ const TableRow: React.FC< clearInterval(pollTimer.current); } chunkRequestRef.current?.current?.cancel?.(); - cacheDataListRef.current = []; }; }, []); - const renderChildrenData = useCallback(() => { + const renderChildrenData = () => { return renderChildren?.(childrenData); - }, [childrenData]); + }; const handlePolling = async () => { if (pollingChildren) { @@ -93,8 +91,8 @@ const TableRow: React.FC< console.log('first load=====', firstLoad); try { setLoading(true); - // const data = await loadChildren?.(record); - // setChildrenData(data || []); + const data = await loadChildren?.(record); + setChildrenData(data || []); setLoading(false); } catch (error) { setChildrenData([]); diff --git a/src/global.tsx b/src/global.tsx index 0bd6267d..7e0677dd 100644 --- a/src/global.tsx +++ b/src/global.tsx @@ -1,6 +1,10 @@ // 应用前置、全局运行的逻辑时 会在这里执行 import dayjs from 'dayjs'; +import localizedFormat from 'dayjs/plugin/localizedFormat'; +import timezone from 'dayjs/plugin/timezone'; import utc from 'dayjs/plugin/utc'; +dayjs.extend(localizedFormat); dayjs.extend(utc); +dayjs.extend(timezone); diff --git a/src/hooks/use-update-chunk-list.ts b/src/hooks/use-update-chunk-list.ts index d7707ff3..94ca0cd2 100644 --- a/src/hooks/use-update-chunk-list.ts +++ b/src/hooks/use-update-chunk-list.ts @@ -17,7 +17,7 @@ export function useUpdateChunkedList(options: { mapFun?: (args: any) => any; computedID?: (d: object) => string; }) { - const cacheDataListRef = useRef([]); + const cacheDataListRef = useRef(options.dataList || []); const updateChunkedList = ( data: ChunkedCollection, dataList: { id: string | number }[] @@ -57,7 +57,7 @@ export function useUpdateChunkedList(options: { console.log('create=========', updateIndex, dataList, collections); }); cacheDataListRef.current = [...newDataList, ...cacheDataListRef.current]; - options.setDataList?.(cacheDataListRef.current); + options.setDataList?.([...cacheDataListRef.current]); } // DELETE if (data?.type === WatchEventType.DELETE) { @@ -69,7 +69,7 @@ export function useUpdateChunkedList(options: { ); // console.log('updateChunkedList=====delete', updatedList); // return updatedList; - options.setDataList?.(() => cacheDataListRef.current); + options.setDataList?.([...cacheDataListRef.current]); } // UPDATE if (data?.type === WatchEventType.UPDATE) { @@ -87,7 +87,8 @@ export function useUpdateChunkedList(options: { cacheDataListRef.current.push(updateItem); } }); - options.setDataList?.(() => cacheDataListRef.current); + console.log('updateChunkedList=====update', cacheDataListRef.current); + options.setDataList?.([...cacheDataListRef.current]); } if (options?.callback) { options?.callback(cacheDataListRef.current); diff --git a/src/pages/llmodels/components/instance-item.tsx b/src/pages/llmodels/components/instance-item.tsx index 41534fb9..2c086662 100644 --- a/src/pages/llmodels/components/instance-item.tsx +++ b/src/pages/llmodels/components/instance-item.tsx @@ -121,7 +121,9 @@ const InstanceItem: React.FC = ({ - {dayjs.utc(item.created_at).format('YYYY-MM-DD HH:mm:ss')} + {dayjs(item.created_at) + .local() + .format('YYYY-MM-DD HH:mm:ss')} diff --git a/src/pages/llmodels/components/table-list.tsx b/src/pages/llmodels/components/table-list.tsx index c0632809..e013595b 100644 --- a/src/pages/llmodels/components/table-list.tsx +++ b/src/pages/llmodels/components/table-list.tsx @@ -360,18 +360,26 @@ const Models: React.FC = ({ key="replicas" align="center" span={4} + render={(text, record: ListItem) => { + return ( + + {record.ready_replicas} / {record.replicas} + + ); + }} /> { - return dayjs.utc(val).format('YYYY-MM-DD HH:mm:ss'); + render={(text, row) => { + console.log('val=time===', text, row.name, row, row.created_at); + return dayjs(text).local().format('YYYY-MM-DD HH:mm:ss'); }} /> { cancelToken: axiosToken.token }); console.log('res=======', res); - if (!firstLoad) { - setDataSource(res.items); - } + // if (!firstLoad) { + // setDataSource(res.items); + // } + setDataSource(res.items); setTotal(res.pagination.total); } catch (error) { setDataSource([]);