-
Notifications
You must be signed in to change notification settings - Fork 2
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
move dataset_split and task filter to system table header #528
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,10 @@ import { SystemModel } from "../../models"; | |
import { DeleteOutlined, EditOutlined } from "@ant-design/icons"; | ||
import { PrivateIcon, useUser } from ".."; | ||
import { generateLeaderboardURL } from "../../utils"; | ||
import type { FilterValue, SorterResult } from "antd/lib/table/interface"; | ||
import type { TablePaginationConfig } from "antd/lib/table"; | ||
import { FilterUpdate, SystemFilter } from "./SystemFilter"; | ||
import { TaskCategory } from "../../clients/openapi"; | ||
const { Text } = Typography; | ||
|
||
interface Props { | ||
|
@@ -30,6 +34,9 @@ interface Props { | |
setSelectedSystemIDs: React.Dispatch<React.SetStateAction<string[]>>; | ||
onActiveSystemChange: (ids: string[]) => void; | ||
showEditDrawer: (systemIDToEdit: string) => void; | ||
onFilterChange: (value: FilterUpdate) => void; | ||
filterValue: SystemFilter; | ||
taskCategories: TaskCategory[]; | ||
} | ||
|
||
export function SystemTableContent({ | ||
|
@@ -44,6 +51,9 @@ export function SystemTableContent({ | |
setSelectedSystemIDs, | ||
onActiveSystemChange, | ||
showEditDrawer, | ||
onFilterChange, | ||
filterValue, | ||
taskCategories, | ||
}: Props) { | ||
const { userInfo } = useUser(); | ||
const metricColumns: ColumnsType<SystemModel> = metricNames.map((metric) => ({ | ||
|
@@ -70,6 +80,12 @@ export function SystemTableContent({ | |
} | ||
} | ||
|
||
const taskFilterList = taskCategories.flatMap((category) => { | ||
return category.tasks.map((task) => { | ||
return { text: task.name, value: task.name }; | ||
}); | ||
}); | ||
|
||
const columns: ColumnsType<SystemModel> = [ | ||
{ | ||
dataIndex: "idx", | ||
|
@@ -100,6 +116,9 @@ export function SystemTableContent({ | |
fixed: "left", | ||
title: "Task", | ||
render: (value) => <Tag style={{ whiteSpace: "normal" }}>{value}</Tag>, | ||
filters: taskFilterList, | ||
filterMultiple: false, | ||
filteredValue: filterValue.task ? [filterValue.task] : null, | ||
}, | ||
{ | ||
dataIndex: "dataset_name", | ||
|
@@ -132,6 +151,13 @@ export function SystemTableContent({ | |
title: "Dataset Split", | ||
fixed: "left", | ||
align: "center", | ||
filterMultiple: false, | ||
filters: [ | ||
{ text: "train", value: "train" }, | ||
{ text: "validation", value: "validation" }, | ||
{ text: "test", value: "test" }, | ||
], | ||
filteredValue: filterValue.split ? [filterValue.split] : null, | ||
}, | ||
{ | ||
dataIndex: "source_language", | ||
|
@@ -220,6 +246,37 @@ export function SystemTableContent({ | |
}, | ||
}; | ||
|
||
const handleTableChange = ( | ||
_pagination: TablePaginationConfig, | ||
filters: Record<string, FilterValue | null>, | ||
_sorter: SorterResult<SystemModel> | SorterResult<SystemModel>[] | ||
) => { | ||
console.log(filters); | ||
for (const k in filters) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This for loop has a couple of minor bugs/typos. I think we can fix them and simplify the code to something like this
Note that I changed the following things:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you very much! This looks much clearer. I add another boolean flag before |
||
if ( | ||
k === "dataset.split" && | ||
((filters[k] === null && filterValue.split !== undefined) || // Reset filter | ||
(filters[k] !== null && | ||
(filters[k] as unknown as string) !== filterValue.split)) | ||
) { | ||
onFilterChange({ | ||
split: | ||
filters[k] === null ? undefined : (filters[k] as unknown as string), | ||
}); | ||
} else if ( | ||
k === "task" && | ||
((filters[k] === null && filterValue.split !== undefined) || // Reset filter | ||
(filters[k] !== null && | ||
(filters[k] as unknown as string) !== filterValue.split)) | ||
) { | ||
onFilterChange({ | ||
task: | ||
filters[k] === null ? undefined : (filters[k] as unknown as string), | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<Table | ||
|
@@ -237,6 +294,7 @@ export function SystemTableContent({ | |
onChange: (newPage, newPageSize) => | ||
onPageChange(newPage - 1, newPageSize), | ||
}} | ||
onChange={handleTableChange} | ||
sticky={false} | ||
loading={loading} | ||
scroll={{ x: 100 }} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please remove the console log?