diff --git a/src/components/seal-table/components/cell-content.tsx b/src/components/seal-table/components/cell-content.tsx index d97eb123..7b127341 100644 --- a/src/components/seal-table/components/cell-content.tsx +++ b/src/components/seal-table/components/cell-content.tsx @@ -135,7 +135,11 @@ const CellContent: React.FC = (props) => { ...row, [dataIndex]: current }, - dataIndex + { + dataIndex, + newValue: current, + oldValue: row[dataIndex] + } ); setIsEditing(false); }; diff --git a/src/components/seal-table/components/table-cell.tsx b/src/components/seal-table/components/table-cell.tsx index 9a5ff53e..af4db35f 100644 --- a/src/components/seal-table/components/table-cell.tsx +++ b/src/components/seal-table/components/table-cell.tsx @@ -1,11 +1,6 @@ -import { CheckOutlined, FormOutlined, UndoOutlined } from '@ant-design/icons'; -import { useIntl } from '@umijs/max'; -import { Button, Input, InputNumber, Tooltip } from 'antd'; import classNames from 'classnames'; -import _ from 'lodash'; -import React, { useContext, useEffect } from 'react'; +import React from 'react'; import styled from 'styled-components'; -import RowContext from '../row-context'; import { SealColumnProps } from '../types'; import CellContent from './cell-content'; @@ -33,146 +28,8 @@ const CellWrapper = styled.div` } `; -interface EditButtonsProps { - isEditing: boolean; - editable?: any; - handleSubmit: () => void; - handleUndo: () => void; - handleEdit: () => void; -} - -interface CellContentProps { - isEditing: boolean; - current: any; - editable: any; - onChange: (val: any) => void; - row?: any; - render?: (text: any, record: any) => React.ReactNode; -} - -const EditButtons: React.FC = (props) => { - const intl = useIntl(); - const { isEditing, editable, handleSubmit, handleUndo, handleEdit } = props; - if (!editable) { - return null; - } - - if (isEditing) { - return ( - - - - - - - - - ); - } - return ( - - {editable.title || ''} - ) - } - > - - - - ); -}; - -const Content: React.FC = (props) => { - const { editable, current, isEditing, row, render, onChange } = props; - if (isEditing && editable) { - const isNumType = - typeof editable === 'object' && editable?.valueType === 'number'; - return isNumType ? ( - - ) : ( - onChange(e.target.value)} /> - ); - } - - if (render) { - return render(current, row); - } - return current; -}; - const TableCell: React.FC = (props) => { - const { row, onCell } = useContext(RowContext); const { dataIndex, render, align, editable } = props; - const [isEditing, setIsEditing] = React.useState(false); - const [current, setCurrent] = React.useState(row[dataIndex]); - const cachedValue = React.useRef(null); - - const handleEdit = () => { - setIsEditing(true); - }; - - const handleSubmit = async () => { - cachedValue.current = current; - await onCell?.( - { - ...row, - [dataIndex]: current - }, - dataIndex - ); - setIsEditing(false); - }; - - const handleUndo = () => { - setCurrent(cachedValue.current); - setIsEditing(false); - }; - - const handleValueChange = (val: any) => { - setCurrent(val); - }; - - useEffect(() => { - cachedValue.current = row[dataIndex]; - setCurrent(row[dataIndex]); - }, [row[dataIndex]]); return ( = (props) => { right: align === 'right' })} > - {/* - - - */} ; - onCell?: (record: any, dataIndex: string) => any; + onCell?: ( + record: any, + data: { dataIndex: string; newValue: any; oldValue: any } + ) => any; } const RowContext = React.createContext({} as RowContextType); diff --git a/src/pages/llmodels/components/table-list.tsx b/src/pages/llmodels/components/table-list.tsx index 43c2a50b..4a0ba1ca 100644 --- a/src/pages/llmodels/components/table-list.tsx +++ b/src/pages/llmodels/components/table-list.tsx @@ -218,14 +218,17 @@ const Models: React.FC = ({ setSortOrder(order); }; - const handleOnCell = useCallback(async (record: any) => { + const handleOnCell = useMemoizedFn(async (record: any, extra: any) => { try { await updateModel(getFormattedData(record)); message.success(intl.formatMessage({ id: 'common.message.success' })); + if (extra.newValue > extra.oldValue) { + updateExpandedRowKeys([record.id, ...expandedRowKeys]); + } } catch (error) { // ignore } - }, []); + }); const handleStartModel = async (row: ListItem) => { await updateModel(getFormattedData(row, { replicas: 1 })); @@ -236,23 +239,23 @@ const Models: React.FC = ({ removeExpandedRowKey([row.id]); }; - const handleModalOk = useCallback( - async (data: FormData) => { - try { - await updateModel({ - data, - id: currentData.current?.id as number - }); - setOpenAddModal(false); - message.success(intl.formatMessage({ id: 'common.message.success' })); - setTimeout(() => { - handleSearch(); - }, 150); - restoreScrollHeight(); - } catch (error) {} - }, - [handleSearch] - ); + const handleModalOk = async (data: FormData) => { + try { + await updateModel({ + data, + id: currentData.current?.id as number + }); + setOpenAddModal(false); + message.success(intl.formatMessage({ id: 'common.message.success' })); + if (data.replicas > currentData.current?.replicas) { + updateExpandedRowKeys([currentData.current?.id, ...expandedRowKeys]); + } + setTimeout(() => { + handleSearch(); + }, 150); + restoreScrollHeight(); + } catch (error) {} + }; const handleModalCancel = useCallback(() => { setOpenAddModal(false); diff --git a/src/pages/users/components/add-modal.tsx b/src/pages/users/components/add-modal.tsx index 65acc65e..90a4b077 100644 --- a/src/pages/users/components/add-modal.tsx +++ b/src/pages/users/components/add-modal.tsx @@ -102,6 +102,10 @@ const AddModal: React.FC = ({ name="is_admin" rules={[{ required: false }]}> {UserRolesOptions.map((item) => { return (