fix: model logs loading

This commit is contained in:
jialin
2024-11-29 13:41:28 +08:00
parent 890287ce72
commit 435161854c
13 changed files with 104 additions and 26 deletions
+2 -2
View File
@@ -9,8 +9,8 @@ const options: any = {
animation: false,
grid: {
...grid,
right: -1,
top: -1,
right: 10,
top: 10,
bottom: 2,
left: 2,
containLabel: true,
@@ -86,7 +86,9 @@ const LogsViewer: React.FC<LogsViewerProps> = forwardRef((props, ref) => {
const getLastPage = useCallback(
(data: string) => {
const list = _.split(data.trim(), '\n');
console.log('list.length', list.length);
if (!enableScorllLoad) {
return list.join('\n');
}
if (list.length <= pageSize) {
setTotalPage(1);
@@ -101,7 +103,7 @@ const LogsViewer: React.FC<LogsViewerProps> = forwardRef((props, ref) => {
debounceLoading();
return lastPage;
},
[pageSize, setTotalPage, setPage, debounceLoading]
[pageSize, setTotalPage, setPage, debounceLoading, enableScorllLoad]
);
const getPrePage = useCallback(() => {
@@ -179,7 +181,7 @@ const LogsViewer: React.FC<LogsViewerProps> = forwardRef((props, ref) => {
setIsLoadend(true);
}
},
[loading, isLoadend, logs.length, pageSize]
[loading, isLoadend, logs.length, pageSize, enableScorllLoad]
);
const debouncedScroll = useCallback(
@@ -1,4 +1,4 @@
import { Slider } from 'antd';
import { Checkbox, Slider } from 'antd';
import SealInput from '../seal-input';
import SealSelect from '../seal-select';
@@ -8,12 +8,14 @@ const components: {
Slider: React.ComponentType<typeof Slider>;
TextArea: typeof SealInput.TextArea;
Input: typeof SealInput.Input;
Checkbox: typeof Checkbox;
} = {
InputNumber: SealInput.Number,
Select: SealSelect,
Slider: Slider as React.ComponentType<typeof Slider>,
TextArea: SealInput.TextArea,
Input: SealInput.Input
Input: SealInput.Input,
Checkbox: Checkbox
};
export default components;
+29 -10
View File
@@ -1,19 +1,38 @@
import { ParamsSchema } from '@/pages/playground/config/types';
import { useIntl } from '@umijs/max';
import React from 'react';
import React, { useCallback, useMemo } from 'react';
import componentsMap from './config/components';
const FieldComponent: React.FC<ParamsSchema> = (props) => {
const intl = useIntl();
const { type, label, attrs, style, ...rest } = props;
return React.createElement(componentsMap[type], {
...rest,
...attrs,
style: { ...style, width: '100%' },
label: label.isLocalized
? intl.formatMessage({ id: label.text })
: label.text
});
const { type, label, attrs, style, value, ...rest } = props;
const renderChild = useCallback(
(type: string) => {
switch (type) {
case 'Checkbox':
return <span>{intl.formatMessage({ id: label.text })}</span>;
default:
return null;
}
},
[intl, type]
);
const checkboxAttrs = useMemo(() => {
return type === 'Checkbox' ? { checked: value } : { value: value };
}, [type, value]);
return React.createElement(
componentsMap[type],
{
...rest,
...attrs,
...checkboxAttrs,
style: { ...style, width: '100%' },
label: label.isLocalized
? intl.formatMessage({ id: label.text })
: label.text
},
renderChild(type)
);
};
export default React.memo(FieldComponent);