Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: expand rows in models after operating #370

Merged
merged 1 commit into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions src/components/seal-table/components/table-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ const TableRow: React.FC<
allSubChildren?: any[];
}>(TableContext);
const { setChunkRequest } = useSetChunkRequest();
const [expanded, setExpanded] = useState(false);
// const [checked, setChecked] = useState(false);
const [childrenData, setChildrenData] = useState<any[]>([]);
const [loading, setLoading] = useState(false);
const [firstLoad, setFirstLoad] = useState(true);
Expand Down Expand Up @@ -73,6 +71,10 @@ const TableRow: React.FC<
};
}, []);

const expanded = useMemo(() => {
return expandedRowKeys?.includes(record[rowKey]);
}, [expandedRowKeys]);

const checked = useMemo(() => {
return rowSelection?.selectedRowKeys?.includes(record[rowKey]);
}, [rowSelection?.selectedRowKeys, record, rowKey]);
Expand Down Expand Up @@ -160,7 +162,6 @@ const TableRow: React.FC<
};

const handleRowExpand = async () => {
setExpanded(!expanded);
onExpand?.(!expanded, record, record[rowKey]);

if (pollTimer.current) {
Expand Down Expand Up @@ -200,14 +201,6 @@ const TableRow: React.FC<
}
};

useEffect(() => {
if (expandedRowKeys?.includes(record[rowKey])) {
setExpanded(true);
} else {
setExpanded(false);
}
}, [expandedRowKeys]);

useEffect(() => {
const handleVisibilityChange = async () => {
if (document.visibilityState === 'hidden') {
Expand Down
163 changes: 107 additions & 56 deletions src/layouts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ export default (props: any) => {
updateCheck.latest_version?.indexOf('0.0.0') === -1 &&
updateCheck.latest_version?.indexOf('rc') === -1
);
}, [updateCheck, version, initialState]);
}, [
updateCheck.latest_version,
version.version,
initialState?.currentUser?.is_admin
]);

useEffect(() => {
const body = document.querySelector('body');
Expand Down Expand Up @@ -279,9 +283,107 @@ export default (props: any) => {

return dom;
},
[intl, version, updateCheck]
[intl, showUpgrade]
);

const itemRender = useCallback((route, _, routes) => {
const { breadcrumbName, title, path } = route;
const label = title || breadcrumbName;
const last = routes[routes.length - 1];
if (last) {
if (last.path === path || last.linkPath === path) {
return <span>{label}</span>;
}
}
return <Link to={path}>{label}</Link>;
}, []);

const menuItemRender = useCallback(
(menuItemProps, defaultDom) => {
if (menuItemProps.isUrl || menuItemProps.children) {
return defaultDom;
}
if (menuItemProps.path && location.pathname !== menuItemProps.path) {
return (
<Link
to={menuItemProps.path.replace('/*', '')}
target={menuItemProps.target}
>
{defaultDom}
</Link>
);
}
return <>{defaultDom}</>;
},
[location.pathname]
);

const onPageChange = useCallback(
(route) => {
const { location } = history;
const { pathname } = location;

initRouteCacheValue(pathname);
dropRouteCache(pathname);

// if user is not change password, redirect to change password page
if (
location.pathname !== loginPath &&
userInfo?.require_password_change
) {
history.push(loginPath);
return;
}

// if user is not logged in, redirect to login page
if (!initialState?.currentUser && location.pathname !== loginPath) {
history.push(loginPath);
} else if (location.pathname === '/') {
const pathname = initialState?.currentUser?.is_admin
? '/dashboard'
: '/playground';
history.push(pathname);
}
},
[userInfo?.require_password_change, initialState?.currentUser]
);

useEffect(() => {
// 先清除旧的性能标记
performance.clearMarks();
performance.clearMeasures();

// 记录开始时间
performance.mark('route-start');

requestAnimationFrame(() => {
// 记录结束时间
performance.mark('route-end');

// 确保 `route-start` 存在后再测量
if (performance.getEntriesByName('route-start').length > 0) {
performance.measure('route-change', 'route-start', 'route-end');

const measure = performance.getEntriesByName('route-change')[0];
console.log(
`[Performance] Route change to ${location.pathname} took ${measure.duration.toFixed(2)}ms`
);

// 清理标记
performance.clearMarks();
performance.clearMeasures();
} else {
console.warn('Missing performance mark: route-start');
}
});
}, [location.pathname]);

const onRenderCallback = (id, phase, actualDuration) => {
console.log(
`[Profiler] Route: ${id} - Phase: ${phase} - Render time: ${actualDuration.toFixed(2)}ms`
);
};

return (
<div>
<div className="background"></div>
Expand Down Expand Up @@ -311,65 +413,14 @@ export default (props: any) => {
}}
menuHeaderRender={renderMenuHeader}
collapsed={collapsed}
onPageChange={(route) => {
const { location } = history;
const { pathname } = location;

initRouteCacheValue(pathname);
dropRouteCache(pathname);

// if user is not change password, redirect to change password page
if (
location.pathname !== loginPath &&
userInfo?.require_password_change
) {
history.push(loginPath);

return;
}

// if user is not logged in, redirect to login page
if (!initialState?.currentUser && location.pathname !== loginPath) {
history.push(loginPath);
} else if (location.pathname === '/') {
const pathname = initialState?.currentUser?.is_admin
? '/dashboard'
: '/playground';
history.push(pathname);
}
}}
onPageChange={onPageChange}
formatMessage={formatMessage}
menu={{
locale: true
}}
logo={collapsed ? SLogoIcon : LogoIcon}
menuItemRender={(menuItemProps, defaultDom) => {
if (menuItemProps.isUrl || menuItemProps.children) {
return defaultDom;
}
if (menuItemProps.path && location.pathname !== menuItemProps.path) {
return (
<Link
to={menuItemProps.path.replace('/*', '')}
target={menuItemProps.target}
>
{defaultDom}
</Link>
);
}
return <>{defaultDom}</>;
}}
itemRender={(route, _, routes) => {
const { breadcrumbName, title, path } = route;
const label = title || breadcrumbName;
const last = routes[routes.length - 1];
if (last) {
if (last.path === path || last.linkPath === path) {
return <span>{label}</span>;
}
}
return <Link to={path}>{label}</Link>;
}}
menuItemRender={menuItemRender}
itemRender={itemRender}
disableContentMargin
fixSiderbar
fixedHeader
Expand Down
3 changes: 1 addition & 2 deletions src/pages/llmodels/components/table-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,6 @@ const Models: React.FC<ModelsProps> = ({

const handleEdit = async (row: ListItem) => {
const initialValues = generateFormValues(row, gpuDeviceList.current);
console.log('initialValues:', initialValues, row);
setUpdateFormInitials({
gpuOptions: gpuDeviceList.current,
data: initialValues,
Expand Down Expand Up @@ -818,7 +817,7 @@ const Models: React.FC<ModelsProps> = ({
)
}
];
}, [sortOrder, intl]);
}, [sortOrder, intl, handleSelect]);

const handleOnClick = async () => {
if (isLoading) {
Expand Down
3 changes: 1 addition & 2 deletions src/pages/playground/components/ground-embedding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import 'overlayscrollbars/overlayscrollbars.css';
import { Resizable } from 're-resizable';
import {
forwardRef,
memo,
useCallback,
useEffect,
useImperativeHandle,
Expand Down Expand Up @@ -728,4 +727,4 @@ const GroundEmbedding: React.FC<MessageProps> = forwardRef((props, ref) => {
);
});

export default memo(GroundEmbedding);
export default GroundEmbedding;
9 changes: 4 additions & 5 deletions src/pages/playground/components/ground-images.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import _ from 'lodash';
import 'overlayscrollbars/overlayscrollbars.css';
import React, {
forwardRef,
memo,
useCallback,
useImperativeHandle,
useMemo,
Expand Down Expand Up @@ -183,8 +182,8 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {

form.current?.form?.setFieldValue('seed', params.seed);
console.log('params:', params, parameters);
submitMessage(params);
setRouteCache(routeCachekey['/playground/text-to-image'], true);
await submitMessage(params);
} catch (error) {
// console.log('error:', error);
} finally {
Expand All @@ -193,9 +192,9 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
}
};

const handleCloseViewCode = () => {
const handleCloseViewCode = useCallback(() => {
setShow(false);
};
}, []);

return (
<div className="ground-left-wrapper">
Expand Down Expand Up @@ -343,4 +342,4 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
);
});

export default memo(GroundImages);
export default GroundImages;
3 changes: 1 addition & 2 deletions src/pages/playground/components/ground-left.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import classNames from 'classnames';
import 'overlayscrollbars/overlayscrollbars.css';
import {
forwardRef,
memo,
useEffect,
useImperativeHandle,
useMemo,
Expand Down Expand Up @@ -211,4 +210,4 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
);
});

export default memo(GroundLeft);
export default GroundLeft;
3 changes: 1 addition & 2 deletions src/pages/playground/components/ground-reranker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import _ from 'lodash';
import 'overlayscrollbars/overlayscrollbars.css';
import {
forwardRef,
memo,
useCallback,
useEffect,
useImperativeHandle,
Expand Down Expand Up @@ -610,4 +609,4 @@ const GroundReranker: React.FC<MessageProps> = forwardRef((props, ref) => {
);
});

export default memo(GroundReranker);
export default GroundReranker;
6 changes: 2 additions & 4 deletions src/pages/playground/components/ground-stt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import classNames from 'classnames';
import 'overlayscrollbars/overlayscrollbars.css';
import {
forwardRef,
memo,
useCallback,
useEffect,
useImperativeHandle,
Expand All @@ -37,11 +36,10 @@ import ViewCommonCode from './view-common-code';

interface MessageProps {
modelList: Global.BaseOption<string>[];
loaded?: boolean;
ref?: any;
}

const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
const GroundSTT: React.FC<MessageProps> = forwardRef((props, ref) => {
const intl = useIntl();
const { modelList } = props;
const messageId = useRef<number>(0);
Expand Down Expand Up @@ -474,4 +472,4 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
);
});

export default memo(GroundLeft);
export default GroundSTT;
5 changes: 2 additions & 3 deletions src/pages/playground/components/ground-tts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import _ from 'lodash';
import 'overlayscrollbars/overlayscrollbars.css';
import {
forwardRef,
memo,
useCallback,
useEffect,
useImperativeHandle,
Expand All @@ -37,7 +36,7 @@ interface MessageProps {
ref?: any;
}

const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
const GroundTTS: React.FC<MessageProps> = forwardRef((props, ref) => {
const { modelList } = props;
const messageId = useRef<number>(0);
const [messageList, setMessageList] = useState<
Expand Down Expand Up @@ -423,4 +422,4 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
);
});

export default memo(GroundLeft);
export default GroundTTS;
Loading
Loading