style: start history selection
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
import useSetChunkRequest from '@/hooks/use-chunk-request';
|
import useSetChunkRequest from '@/hooks/use-chunk-request';
|
||||||
import { formatOrdinal } from '@/utils';
|
|
||||||
import { CloseOutlined, QuestionCircleOutlined } from '@ant-design/icons';
|
import { CloseOutlined, QuestionCircleOutlined } from '@ant-design/icons';
|
||||||
import { BaseSelect, LogsViewer } from '@gpustack/core-ui';
|
import { LogsViewer } from '@gpustack/core-ui';
|
||||||
import { useIntl } from '@umijs/max';
|
import { useIntl } from '@umijs/max';
|
||||||
import { Button, Modal, Tooltip } from 'antd';
|
import { Button, Modal, Tooltip } from 'antd';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import React, { useCallback, useEffect, useState } from 'react';
|
import React, { useCallback, useEffect, useState } from 'react';
|
||||||
import { MODELS_API } from '../apis';
|
import { MODELS_API } from '../apis';
|
||||||
|
|
||||||
|
import SealCascader from '@/components/seal-form/seal-cascader';
|
||||||
import { InstanceRealtimeLogStatus, InstanceStatusMap } from '../config';
|
import { InstanceRealtimeLogStatus, InstanceStatusMap } from '../config';
|
||||||
import useQueryModelInstanceRestartCount from '../services/use-query-instance-restart-count';
|
import useQueryModelInstanceRestartCount from '../services/use-query-instance-restart-count';
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ const ViewLogsModal: React.FC<ViewModalProps> = (props) => {
|
|||||||
const [isDownloading, setIsDownloading] = useState<boolean>(
|
const [isDownloading, setIsDownloading] = useState<boolean>(
|
||||||
status === InstanceStatusMap.Downloading
|
status === InstanceStatusMap.Downloading
|
||||||
);
|
);
|
||||||
const [record, setRecord] = useState<number>(0);
|
const [record, setRecord] = useState<number[]>([]);
|
||||||
const [params, setParams] = useState<any>({
|
const [params, setParams] = useState<any>({
|
||||||
follow: true
|
follow: true
|
||||||
});
|
});
|
||||||
@@ -85,7 +85,7 @@ const ViewLogsModal: React.FC<ViewModalProps> = (props) => {
|
|||||||
cancelRequest();
|
cancelRequest();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleOnChange = (value: number, option: any) => {
|
const handleOnChange = (value: number[], option: any) => {
|
||||||
if (!option) {
|
if (!option) {
|
||||||
setParams({
|
setParams({
|
||||||
follow: true
|
follow: true
|
||||||
@@ -114,20 +114,55 @@ const ViewLogsModal: React.FC<ViewModalProps> = (props) => {
|
|||||||
|
|
||||||
const optionRender = (option: any) => {
|
const optionRender = (option: any) => {
|
||||||
const { data = {} } = option || {};
|
const { data = {} } = option || {};
|
||||||
let label = formatOrdinal(data.value);
|
if (data.isParent) {
|
||||||
if (data.isCurrent) {
|
return <span style={{ fontWeight: 400 }}>{data.label}</span>;
|
||||||
label = intl.formatMessage({ id: 'models.instance.currentRun' });
|
|
||||||
}
|
}
|
||||||
if (data.isPrevious) {
|
return renderLabel(data.label, data.start_at);
|
||||||
label = intl.formatMessage({ id: 'models.instance.previousRun' });
|
|
||||||
}
|
|
||||||
return renderLabel(label, data.start_at);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const labelRender = (option: any) => {
|
const handleOnCountChange = (value: any[], selectedOptions: any[]) => {
|
||||||
const data = countOptions.find((item) => item.value === option.value);
|
const option = selectedOptions?.[1];
|
||||||
if (!data) return '';
|
handleOnChange(value, option);
|
||||||
return optionRender({ data });
|
};
|
||||||
|
|
||||||
|
const showCascader =
|
||||||
|
countOptions?.some((option) => option.children!?.length >= 2) ||
|
||||||
|
countOptions?.length > 1;
|
||||||
|
|
||||||
|
const renderPrefix = () => {
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
fontWeight: 400,
|
||||||
|
fontSize: 13,
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
marginRight: 8,
|
||||||
|
paddingRight: 8,
|
||||||
|
color: 'var(--ant-color-text-secondary)',
|
||||||
|
borderRight: '1px solid var(--ant-color-split)'
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{intl.formatMessage({ id: 'models.instance.startHistory' })}
|
||||||
|
<Tooltip
|
||||||
|
title={
|
||||||
|
<span>
|
||||||
|
<span className="font-600 m-r-8">
|
||||||
|
{intl.formatMessage({
|
||||||
|
id: 'models.instance.previousRun'
|
||||||
|
})}
|
||||||
|
:
|
||||||
|
</span>
|
||||||
|
{intl.formatMessage({
|
||||||
|
id: 'models.instance.startHistory.tips'
|
||||||
|
})}
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<QuestionCircleOutlined style={{ marginLeft: 4 }} />
|
||||||
|
</Tooltip>
|
||||||
|
</span>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderTitle = () => {
|
const renderTitle = () => {
|
||||||
@@ -136,53 +171,29 @@ const ViewLogsModal: React.FC<ViewModalProps> = (props) => {
|
|||||||
<span style={{ fontWeight: 'var(--font-weight-bold)' }}>
|
<span style={{ fontWeight: 'var(--font-weight-bold)' }}>
|
||||||
{intl.formatMessage({ id: 'common.button.viewlog' })}
|
{intl.formatMessage({ id: 'common.button.viewlog' })}
|
||||||
</span>
|
</span>
|
||||||
<span>
|
<span className="flex-center gap-8" style={{ height: 32 }}>
|
||||||
{countOptions.length > 1 && (
|
{showCascader && (
|
||||||
<BaseSelect
|
<SealCascader
|
||||||
allowClear
|
size="small"
|
||||||
value={record}
|
prefix={renderPrefix()}
|
||||||
onChange={handleOnChange}
|
required
|
||||||
prefix={
|
showSearch
|
||||||
<span
|
changeOnSelect={false}
|
||||||
style={{
|
expandTrigger="hover"
|
||||||
fontWeight: 400,
|
style={{ width: 400 }}
|
||||||
fontSize: 13,
|
multiple={false}
|
||||||
display: 'flex',
|
classNames={{
|
||||||
alignItems: 'center',
|
popup: {
|
||||||
marginRight: 8,
|
root: 'cascader-popup-wrapper gpu-selector'
|
||||||
paddingRight: 8,
|
}
|
||||||
color: 'var(--ant-color-text-secondary)',
|
|
||||||
borderRight: '1px solid var(--ant-color-split)'
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{intl.formatMessage({ id: 'models.instance.startHistory' })}
|
|
||||||
<Tooltip
|
|
||||||
title={
|
|
||||||
<span>
|
|
||||||
<span className="font-600 m-r-8">
|
|
||||||
{intl.formatMessage({
|
|
||||||
id: 'models.instance.previousRun'
|
|
||||||
})}
|
|
||||||
:
|
|
||||||
</span>
|
|
||||||
{intl.formatMessage({
|
|
||||||
id: 'models.instance.startHistory.tips'
|
|
||||||
})}
|
|
||||||
</span>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<QuestionCircleOutlined style={{ marginLeft: 4 }} />
|
|
||||||
</Tooltip>
|
|
||||||
</span>
|
|
||||||
}
|
|
||||||
options={countOptions}
|
|
||||||
labelRender={labelRender}
|
|
||||||
optionRender={optionRender}
|
|
||||||
style={{
|
|
||||||
width: 400,
|
|
||||||
marginRight: 16
|
|
||||||
}}
|
}}
|
||||||
></BaseSelect>
|
maxTagCount={1}
|
||||||
|
value={record}
|
||||||
|
options={countOptions}
|
||||||
|
getPopupContainer={(triggerNode) => triggerNode.parentNode}
|
||||||
|
optionNode={optionRender}
|
||||||
|
onChange={handleOnCountChange}
|
||||||
|
></SealCascader>
|
||||||
)}
|
)}
|
||||||
<Button
|
<Button
|
||||||
type="text"
|
type="text"
|
||||||
@@ -206,7 +217,10 @@ const ViewLogsModal: React.FC<ViewModalProps> = (props) => {
|
|||||||
fetchData(props.id).then((list) => {
|
fetchData(props.id).then((list) => {
|
||||||
const lastItem = list?.[0];
|
const lastItem = list?.[0];
|
||||||
if (lastItem) {
|
if (lastItem) {
|
||||||
setRecord(lastItem.value);
|
handleOnChange(
|
||||||
|
[lastItem.value, lastItem.children?.[0]?.value],
|
||||||
|
lastItem.children?.[0]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -4,6 +4,22 @@ import { useState } from 'react';
|
|||||||
import { queryModelInstanceRestartCount } from '../apis';
|
import { queryModelInstanceRestartCount } from '../apis';
|
||||||
import { InstanceRestartCount } from '../config/types';
|
import { InstanceRestartCount } from '../config/types';
|
||||||
|
|
||||||
|
interface RestartCountOption {
|
||||||
|
label: string;
|
||||||
|
value: number;
|
||||||
|
worker_id: number;
|
||||||
|
name: string;
|
||||||
|
isParent: boolean;
|
||||||
|
children?: {
|
||||||
|
value: number;
|
||||||
|
label: string;
|
||||||
|
start_at: string;
|
||||||
|
worker_id: number;
|
||||||
|
isCurrent: boolean;
|
||||||
|
isPrevious: boolean;
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
|
||||||
export default function useQueryModelInstanceRestartCount() {
|
export default function useQueryModelInstanceRestartCount() {
|
||||||
const { detailData, loading, cancelRequest, fetchData } =
|
const { detailData, loading, cancelRequest, fetchData } =
|
||||||
useQueryData<InstanceRestartCount>({
|
useQueryData<InstanceRestartCount>({
|
||||||
@@ -11,28 +27,38 @@ export default function useQueryModelInstanceRestartCount() {
|
|||||||
key: 'modelInstanceRestartCount'
|
key: 'modelInstanceRestartCount'
|
||||||
});
|
});
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
const [dataList, setDataList] = useState<RestartCountOption[]>([]);
|
||||||
const [dataList, setDataList] = useState<
|
|
||||||
{ value: number; label: React.ReactNode; worker_id: number }[]
|
|
||||||
>([]);
|
|
||||||
|
|
||||||
const fetchRestartCount = async (instance_id: number) => {
|
const fetchRestartCount = async (instance_id: number) => {
|
||||||
const res = await fetchData(instance_id);
|
const res = await fetchData(instance_id);
|
||||||
const workerId = res?.workers?.[0]?.worker_id || 0;
|
|
||||||
const workerItem = res?.workers?.[0];
|
const list =
|
||||||
const dataList =
|
res.workers?.map((worker) => {
|
||||||
workerItem?.restarts?.map((restart, index) => {
|
|
||||||
return {
|
return {
|
||||||
value: restart.restart_count,
|
value: worker.worker_id,
|
||||||
label: restart.restart_count,
|
label: worker.name,
|
||||||
start_at: restart.started_at,
|
worker_id: worker.worker_id,
|
||||||
worker_id: workerId,
|
name: worker.name,
|
||||||
isCurrent: index === 0,
|
isParent: true,
|
||||||
isPrevious: index === 1
|
children:
|
||||||
|
worker.restarts?.map((restart, index) => {
|
||||||
|
return {
|
||||||
|
value: restart.restart_count,
|
||||||
|
label:
|
||||||
|
index === 0
|
||||||
|
? intl.formatMessage({ id: 'models.instance.currentRun' })
|
||||||
|
: intl.formatMessage({ id: 'models.instance.previousRun' }),
|
||||||
|
start_at: restart.started_at,
|
||||||
|
worker_id: worker.worker_id,
|
||||||
|
isCurrent: index === 0,
|
||||||
|
isPrevious: index === 1
|
||||||
|
};
|
||||||
|
}) || []
|
||||||
};
|
};
|
||||||
}) || [];
|
}) || [];
|
||||||
setDataList(dataList);
|
|
||||||
return dataList;
|
setDataList(list);
|
||||||
|
return list;
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
countOptions: dataList,
|
countOptions: dataList,
|
||||||
|
|||||||
Reference in New Issue
Block a user