chore: custom table sort
This commit is contained in:
@@ -1,10 +1,30 @@
|
|||||||
|
import { CaretDownOutlined, CaretUpOutlined } from '@ant-design/icons';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import '../styles/header.less';
|
import '../styles/header.less';
|
||||||
import { TableHeaderProps } from '../types';
|
import { TableHeaderProps } from '../types';
|
||||||
|
|
||||||
const TableHeader: React.FC<TableHeaderProps> = (props) => {
|
const TableHeader: React.FC<TableHeaderProps> = (props) => {
|
||||||
const { title, style, align, firstCell, lastCell } = props;
|
const {
|
||||||
|
title,
|
||||||
|
style,
|
||||||
|
align,
|
||||||
|
firstCell,
|
||||||
|
lastCell,
|
||||||
|
sortOrder,
|
||||||
|
onSort,
|
||||||
|
sorter,
|
||||||
|
dataIndex,
|
||||||
|
defaultSortOrder
|
||||||
|
} = props;
|
||||||
|
|
||||||
|
const handleOnSort = () => {
|
||||||
|
if (sortOrder === 'ascend') {
|
||||||
|
onSort?.(dataIndex, 'descend');
|
||||||
|
} else {
|
||||||
|
onSort?.(dataIndex, 'ascend');
|
||||||
|
}
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{ ...style }}
|
style={{ ...style }}
|
||||||
@@ -13,10 +33,29 @@ const TableHeader: React.FC<TableHeaderProps> = (props) => {
|
|||||||
'table-header-center': align === 'center',
|
'table-header-center': align === 'center',
|
||||||
'table-header-right': align === 'right',
|
'table-header-right': align === 'right',
|
||||||
'table-header-first': firstCell,
|
'table-header-first': firstCell,
|
||||||
'table-header-last': lastCell
|
'table-header-last': lastCell,
|
||||||
|
'table-header-sorter': sorter
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<div className="table-header-cell">{title}</div>
|
{sorter ? (
|
||||||
|
<span className="sorter-header" onClick={handleOnSort}>
|
||||||
|
<span className="table-header-cell">{title}</span>
|
||||||
|
<span className="sorter">
|
||||||
|
<CaretUpOutlined
|
||||||
|
className={classNames('sorter-up', {
|
||||||
|
'sorter-active': sortOrder === 'ascend'
|
||||||
|
})}
|
||||||
|
></CaretUpOutlined>
|
||||||
|
<CaretDownOutlined
|
||||||
|
className={classNames('sorter-down', {
|
||||||
|
'sorter-active': sortOrder === 'descend'
|
||||||
|
})}
|
||||||
|
></CaretDownOutlined>
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<div className="table-header-cell">{title}</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ const SealTable: React.FC<SealTableProps & { pagination: PaginationProps }> = (
|
|||||||
rowKey,
|
rowKey,
|
||||||
childParentKey,
|
childParentKey,
|
||||||
onExpand,
|
onExpand,
|
||||||
|
onSort,
|
||||||
expandedRowKeys,
|
expandedRowKeys,
|
||||||
loading,
|
loading,
|
||||||
expandable,
|
expandable,
|
||||||
@@ -117,12 +118,25 @@ const SealTable: React.FC<SealTableProps & { pagination: PaginationProps }> = (
|
|||||||
<Row className="row">
|
<Row className="row">
|
||||||
{React.Children.map(props.children, (child, i) => {
|
{React.Children.map(props.children, (child, i) => {
|
||||||
const { props: columnProps } = child as any;
|
const { props: columnProps } = child as any;
|
||||||
const { title, align, span, headerStyle } =
|
const {
|
||||||
columnProps as SealColumnProps;
|
title,
|
||||||
|
dataIndex,
|
||||||
|
align,
|
||||||
|
span,
|
||||||
|
headerStyle,
|
||||||
|
sortOrder,
|
||||||
|
sorter,
|
||||||
|
defaultSortOrder
|
||||||
|
} = columnProps as SealColumnProps;
|
||||||
if (React.isValidElement(child)) {
|
if (React.isValidElement(child)) {
|
||||||
return (
|
return (
|
||||||
<Col span={span} key={i}>
|
<Col span={span} key={i}>
|
||||||
<TableHeader
|
<TableHeader
|
||||||
|
onSort={onSort}
|
||||||
|
sorter={sorter}
|
||||||
|
dataIndex={dataIndex}
|
||||||
|
sortOrder={sortOrder}
|
||||||
|
defaultSortOrder={defaultSortOrder}
|
||||||
title={title}
|
title={title}
|
||||||
style={headerStyle}
|
style={headerStyle}
|
||||||
firstCell={i === 0}
|
firstCell={i === 0}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
.table-header {
|
.table-header {
|
||||||
|
min-height: 20px;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
@@ -8,16 +9,56 @@
|
|||||||
&-last {
|
&-last {
|
||||||
border-right: none;
|
border-right: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
&-cell {
|
&-cell {
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
&-left {
|
&-left {
|
||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
}
|
}
|
||||||
|
|
||||||
&-right {
|
&-right {
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
}
|
}
|
||||||
|
|
||||||
&-center {
|
&-center {
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sorter-header {
|
||||||
|
display: flex;
|
||||||
|
flex: 1;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
.sorter {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
margin-left: 4px;
|
||||||
|
|
||||||
|
.anticon {
|
||||||
|
font-size: 10px;
|
||||||
|
color: rgba(0, 0, 0, 29%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sorter-up {
|
||||||
|
margin-bottom: -0.125em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sorter-down {
|
||||||
|
margin-top: -0.125em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sorter-active {
|
||||||
|
color: var(--ant-color-primary);
|
||||||
|
|
||||||
|
.anticon {
|
||||||
|
color: var(--ant-color-primary);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,9 +8,17 @@ export interface SealColumnProps {
|
|||||||
span: number;
|
span: number;
|
||||||
align?: 'left' | 'center' | 'right';
|
align?: 'left' | 'center' | 'right';
|
||||||
headerStyle?: React.CSSProperties;
|
headerStyle?: React.CSSProperties;
|
||||||
|
sorter?: boolean;
|
||||||
|
defaultSortOrder?: 'ascend' | 'descend';
|
||||||
|
sortOrder?: 'ascend' | 'descend' | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TableHeaderProps {
|
export interface TableHeaderProps {
|
||||||
|
sorter?: boolean;
|
||||||
|
defaultSortOrder?: 'ascend' | 'descend';
|
||||||
|
sortOrder?: 'ascend' | 'descend' | null;
|
||||||
|
dataIndex: string;
|
||||||
|
onSort?: (dataIndex: string, order: 'ascend' | 'descend') => void;
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
title: string;
|
title: string;
|
||||||
style?: React.CSSProperties;
|
style?: React.CSSProperties;
|
||||||
@@ -34,6 +42,7 @@ export interface SealTableProps {
|
|||||||
pollingChildren?: boolean;
|
pollingChildren?: boolean;
|
||||||
watchChildren?: boolean;
|
watchChildren?: boolean;
|
||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
|
onSort?: (dataIndex: string, order: 'ascend' | 'descend') => void;
|
||||||
onExpand?: (expanded: boolean, record: any, rowKey: any) => void;
|
onExpand?: (expanded: boolean, record: any, rowKey: any) => void;
|
||||||
renderChildren?: (data: any) => React.ReactNode;
|
renderChildren?: (data: any) => React.ReactNode;
|
||||||
loadChildren?: (record: any) => Promise<any[]>;
|
loadChildren?: (record: any) => Promise<any[]>;
|
||||||
|
|||||||
+6
-1
@@ -32,7 +32,7 @@ html {
|
|||||||
--ant-color-fill-secondary: rgba(0, 0, 0, 6%);
|
--ant-color-fill-secondary: rgba(0, 0, 0, 6%);
|
||||||
--table-td-radius: 8px;
|
--table-td-radius: 8px;
|
||||||
--checkbox-border-radius: 4px;
|
--checkbox-border-radius: 4px;
|
||||||
--ant-table-cell-padding-inline: 8px;
|
--ant-table-cell-padding-inline: 16px;
|
||||||
--ant-table-cell-padding-block: 8px;
|
--ant-table-cell-padding-block: 8px;
|
||||||
--ant-table-header-border-radius: 8px;
|
--ant-table-header-border-radius: 8px;
|
||||||
--ant-table-header-split-color: #f0f0f0;
|
--ant-table-header-split-color: #f0f0f0;
|
||||||
@@ -149,6 +149,11 @@ body {
|
|||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ant-slider:hover .ant-slider-handle::after {
|
||||||
|
box-shadow: 0 0 0 var(--ant-slider-handle-line-width)
|
||||||
|
var(--ant-slider-track-hover-bg);
|
||||||
|
}
|
||||||
|
|
||||||
.ant-select-selector {
|
.ant-select-selector {
|
||||||
.ant-select-selection-item {
|
.ant-select-selection-item {
|
||||||
font-weight: var(--font-weight-normal);
|
font-weight: var(--font-weight-normal);
|
||||||
|
|||||||
@@ -110,9 +110,9 @@ const Models: React.FC<ModelsProps> = ({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleTableChange = (pagination: any, filters: any, sorter: any) => {
|
const handleOnSort = (dataIndex: string, order: any) => {
|
||||||
console.log('handleTableChange=======', pagination, filters, sorter);
|
console.log('handleTableChange=======', dataIndex, order);
|
||||||
setSortOrder(sorter.order);
|
setSortOrder(order);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAddModal = () => {
|
const handleAddModal = () => {
|
||||||
@@ -326,7 +326,7 @@ const Models: React.FC<ModelsProps> = ({
|
|||||||
rowKey="id"
|
rowKey="id"
|
||||||
childParentKey="model_id"
|
childParentKey="model_id"
|
||||||
expandable={true}
|
expandable={true}
|
||||||
onChange={handleTableChange}
|
onSort={handleOnSort}
|
||||||
pollingChildren={false}
|
pollingChildren={false}
|
||||||
watchChildren={true}
|
watchChildren={true}
|
||||||
loadChildren={getModelInstances}
|
loadChildren={getModelInstances}
|
||||||
@@ -384,8 +384,7 @@ const Models: React.FC<ModelsProps> = ({
|
|||||||
key="created_at"
|
key="created_at"
|
||||||
defaultSortOrder="descend"
|
defaultSortOrder="descend"
|
||||||
sortOrder={sortOrder}
|
sortOrder={sortOrder}
|
||||||
showSorterTooltip={false}
|
sorter={false}
|
||||||
sorter={true}
|
|
||||||
render={(text, row) => {
|
render={(text, row) => {
|
||||||
return dayjs(text).format('YYYY-MM-DD HH:mm:ss');
|
return dayjs(text).format('YYYY-MM-DD HH:mm:ss');
|
||||||
}}
|
}}
|
||||||
@@ -394,6 +393,7 @@ const Models: React.FC<ModelsProps> = ({
|
|||||||
span={4}
|
span={4}
|
||||||
title={intl.formatMessage({ id: 'common.table.operation' })}
|
title={intl.formatMessage({ id: 'common.table.operation' })}
|
||||||
key="operation"
|
key="operation"
|
||||||
|
dataIndex="operation"
|
||||||
render={(text, record) => {
|
render={(text, record) => {
|
||||||
return !record.transition ? (
|
return !record.transition ? (
|
||||||
<DropdownButtons
|
<DropdownButtons
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
|
|||||||
const [codeValue, setCodeValue] = useState('');
|
const [codeValue, setCodeValue] = useState('');
|
||||||
const [lang, setLang] = useState('shell');
|
const [lang, setLang] = useState('shell');
|
||||||
|
|
||||||
const BaseURL = `${window.location.origin}/v1-openai/chat/completions`;
|
const BaseURL = `${window.location.origin}/v1-openai`;
|
||||||
|
|
||||||
const langOptions = [
|
const langOptions = [
|
||||||
{ label: 'Curl', value: 'shell' },
|
{ label: 'Curl', value: 'shell' },
|
||||||
@@ -69,14 +69,14 @@ const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
|
|||||||
const systemList = systemMessage
|
const systemList = systemMessage
|
||||||
? [{ role: 'system', content: systemMessage }]
|
? [{ role: 'system', content: systemMessage }]
|
||||||
: [];
|
: [];
|
||||||
const code = `import OpenAI from "openai";\nconst openai = new OpenAI();\n\nconst baseURL = "${BaseURL}"\n\nasync function main(){\nconst params = ${JSON.stringify(
|
const code = `const OpenAI = require("openai");\n\nconst openai = new OpenAI({\n"apiKey": $\{GUPSTACK_API_KEY},\n"baseURL": "${BaseURL}"\n});\n\n\nasync function main(){\nconst params = ${JSON.stringify(
|
||||||
{
|
{
|
||||||
...parameters,
|
...parameters,
|
||||||
messages: [...systemList, ...messageList]
|
messages: [...systemList, ...messageList]
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
2
|
2
|
||||||
)};\nconst chatCompletion = await openai.chat.completions.create(params);\nfor await (const chunk of chatCompletion) {\n process.stdout.write(chunk.choices[0]?.delta?.content || '');\n}\n}\nmain();`;
|
)};\nconst chatCompletion = await openai.chat.completions.create(params);\nfor await (const chunk of chatCompletion) {\n process.stdout.write(chunk.choices[0]?.message?.content || '');\n}\n}\nmain();`;
|
||||||
setCodeValue(code);
|
setCodeValue(code);
|
||||||
} else if (lang === 'python') {
|
} else if (lang === 'python') {
|
||||||
const formattedParams = _.keys(parameters).reduce(
|
const formattedParams = _.keys(parameters).reduce(
|
||||||
@@ -95,7 +95,7 @@ const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
|
|||||||
const systemList = systemMessage
|
const systemList = systemMessage
|
||||||
? [{ role: 'system', content: systemMessage }]
|
? [{ role: 'system', content: systemMessage }]
|
||||||
: [];
|
: [];
|
||||||
const code = `from openai import OpenAI\nclient = OpenAI()\n\nbaseURL = ${BaseURL}\n\ncompletion = client.chat.completions.create(\n${formattedParams} messages=${JSON.stringify([...systemList, ...messageList], null, 2)})\nprint(completion.choices[0].message)`;
|
const code = `from openai import OpenAI\n\nbaseURL = ${BaseURL}\n\nclient = OpenAI(\nbase_url=baseURL, \napi_key="$\{GUPSTACK_API_KEY}"\n)\n\ncompletion = client.chat.completions.create(\n${formattedParams} messages=${JSON.stringify([...systemList, ...messageList], null, 2)})\nprint(completion.choices[0].message.content)`;
|
||||||
setCodeValue(code);
|
setCodeValue(code);
|
||||||
}
|
}
|
||||||
formatCode();
|
formatCode();
|
||||||
@@ -118,9 +118,10 @@ const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
|
|||||||
minimap: {
|
minimap: {
|
||||||
enabled: false
|
enabled: false
|
||||||
},
|
},
|
||||||
|
readOnly: true,
|
||||||
formatOnType: true,
|
formatOnType: true,
|
||||||
formatOnPaste: true,
|
formatOnPaste: true,
|
||||||
fontWeight: '700',
|
fontWeight: 700,
|
||||||
scrollbar: {
|
scrollbar: {
|
||||||
verticalSliderSize: 8
|
verticalSliderSize: 8
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ const GPUList: React.FC = () => {
|
|||||||
dataIndex="temperature"
|
dataIndex="temperature"
|
||||||
key="Temperature"
|
key="Temperature"
|
||||||
render={(text, record: GPUDeviceItem) => {
|
render={(text, record: GPUDeviceItem) => {
|
||||||
return <span>{_.round(text, 1)}</span>;
|
return <span>{text ? _.round(text, 1) : '-'}</span>;
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Column
|
<Column
|
||||||
|
|||||||
Reference in New Issue
Block a user