diff --git a/src/pages/_components/filter-form.tsx b/src/pages/_components/filter-form.tsx new file mode 100644 index 00000000..9c2c233b --- /dev/null +++ b/src/pages/_components/filter-form.tsx @@ -0,0 +1,121 @@ +import OverlayScroller from '@/components/overlay-scroller'; +import { FilterOutlined } from '@ant-design/icons'; +import { useIntl } from '@umijs/max'; +import { Button, Form, Popover } from 'antd'; +import React, { useState } from 'react'; +import styled from 'styled-components'; + +const Container = styled.div` + padding: 8px; + padding-right: 0px; + .title { + font-weight: 500; + margin-bottom: 12px; + } + .btn-wrapper { + display: flex; + justify-content: space-between; + align-items: center; + padding-top: 24px; + padding-right: 8px; + } + .buttons { + display: flex; + gap: 8px; + justify-content: flex-end; + } +`; + +const FilterForm: React.FC< + React.PropsWithChildren & { + width?: number; + contentHeight?: number; + initialValues?: any; + hasFilters?: boolean; + onClose?: () => void; + onValuesChange?: (ChangeValues: any, allValues: any) => void; + } +> = ({ + children, + width = 300, + contentHeight = 400, + initialValues = {}, + hasFilters = false, + onClose, + onValuesChange +}) => { + const intl = useIntl(); + const [open, setOpen] = useState(false); + const [form] = Form.useForm(); + + const handleToggle = () => { + setOpen(!open); + }; + + const handleOpenChange = (isOpen: boolean) => { + setOpen(isOpen); + }; + + const handleOnReset = () => { + form.resetFields(Object.keys(initialValues)); + onValuesChange?.({}, initialValues); + setOpen(false); + }; + + const handleOnClose = () => { + setOpen(false); + onClose?.(); + }; + + return ( + + + + {children} + + + + + {intl.formatMessage({ id: 'common.button.reset' })} + + + + {intl.formatMessage({ id: 'common.button.close' })} + + + + + } + onOpenChange={handleOpenChange} + styles={{ + container: { + padding: 8 + }, + root: { + width: width + } + }} + > + }> + + ); +}; + +export default FilterForm; diff --git a/src/pages/benchmark/hooks/use-benchmark-columns.tsx b/src/pages/benchmark/hooks/use-benchmark-columns.tsx index 6c27fa16..f7c72b83 100644 --- a/src/pages/benchmark/hooks/use-benchmark-columns.tsx +++ b/src/pages/benchmark/hooks/use-benchmark-columns.tsx @@ -43,6 +43,7 @@ const useBenchmarkColumns = (params: { ), dataIndex: 'operations', + width: 100, render: (value: string, record: ListItem) => ( ) diff --git a/src/pages/benchmark/hooks/use-column-settings.tsx b/src/pages/benchmark/hooks/use-column-settings.tsx index e722cef5..995e3a2e 100644 --- a/src/pages/benchmark/hooks/use-column-settings.tsx +++ b/src/pages/benchmark/hooks/use-column-settings.tsx @@ -429,7 +429,7 @@ const useColumnSettings = (options: { ) => void; onStatusChange: (value?: any) => void; onDeleteInstanceFromCache?: (instanceId: number) => void; + onFilterChange?: (filters: any) => void; sortOrder: string[]; queryParams: { page: number; @@ -126,6 +127,7 @@ const Models: React.FC = ({ onTableSort, onStatusChange, onDeleteInstanceFromCache, + onFilterChange, sortOrder, deleteIds, dataSource, @@ -623,20 +625,18 @@ const Models: React.FC = ({ onChange={handleCategoryChange} options={modelCategories.filter((item) => item.value)} > - {page !== 'clusters' && ( - - )} + = ({ options={statusOptions} onChange={handleStatusChange} > + {/* */} []; + initialValues?: any; + onValuesChange?: (values: any) => void; +} + +const FilterFormContent: React.FC = ({ + clusterList, + initialValues, + onValuesChange +}) => { + const intl = useIntl(); + const form = Form.useFormInstance(); + const { labelRender, optionRender, statusOptions } = useFilterStatus(); + + const handleOnValuesChange = (changedValues: any, allValues: any) => { + const query = _.pickBy(allValues, (value: any) => !!value); + onValuesChange?.(query); + }; + + return ( + + + + item.value)} + > + + + + + + + + + + ); +}; + +export default FilterFormContent; diff --git a/src/pages/llmodels/hooks/use-filter-status.tsx b/src/pages/llmodels/hooks/use-filter-status.tsx index df8720ba..28de1650 100644 --- a/src/pages/llmodels/hooks/use-filter-status.tsx +++ b/src/pages/llmodels/hooks/use-filter-status.tsx @@ -15,10 +15,10 @@ const Dot = ({ color }: { color: string }) => { ); }; -const useFilterStatus = (options: { - onStatusChange: (value?: any) => void; +const useFilterStatus = (options?: { + onStatusChange?: (value?: any) => void; }) => { - const { onStatusChange } = options; + const { onStatusChange } = options || {}; const intl = useIntl(); const statusOptions = [ @@ -49,7 +49,7 @@ const useFilterStatus = (options: { const current = statusOptions.find((option) => option.value === item.value); return ( - + {current && } {item.label} ); @@ -65,7 +65,7 @@ const useFilterStatus = (options: { }; const handleStatusChange = (value: string | undefined) => { - onStatusChange(value); + onStatusChange?.(value); }; return { diff --git a/src/pages/llmodels/index.tsx b/src/pages/llmodels/index.tsx index aaedc70a..fc6ad2a7 100644 --- a/src/pages/llmodels/index.tsx +++ b/src/pages/llmodels/index.tsx @@ -339,6 +339,17 @@ const Models: React.FC<{ clusterId?: number }> = ({ clusterId }) => { }); }; + const handleOnFilterChange = (filters: any) => { + handleQueryChange({ + page: 1, + ...filters + }); + createModelsChunkRequest({ + search: queryParams.search, + ...filters + }); + }; + const handleDeleteInstanceFromCache = (id: number) => { cacheInsDataListRef.current = cacheInsDataListRef.current.filter( (item) => item.id !== id @@ -451,6 +462,7 @@ const Models: React.FC<{ clusterId?: number }> = ({ clusterId }) => { onStop={handleSearchBySilent} onStart={handleSearchBySilent} onTableSort={handleOnSortChange} + onFilterChange={handleOnFilterChange} onDeleteInstanceFromCache={handleDeleteInstanceFromCache} sortOrder={sortOrder} queryParams={queryParams}