From 6132ded5427d81b772a36a967d532ec1971215d6 Mon Sep 17 00:00:00 2001 From: JihengLi Date: Fri, 12 Apr 2024 11:22:00 -0500 Subject: [PATCH] Add search, sort, and filter functions to manage application tab in organizer --- .../ManageUsersTab/manageRoleForm.tsx | 67 +++++++++++++++++-- 1 file changed, 61 insertions(+), 6 deletions(-) diff --git a/components/Organizer/ManageUsersTab/manageRoleForm.tsx b/components/Organizer/ManageUsersTab/manageRoleForm.tsx index a7e6c981..dc580e33 100644 --- a/components/Organizer/ManageUsersTab/manageRoleForm.tsx +++ b/components/Organizer/ManageUsersTab/manageRoleForm.tsx @@ -1,8 +1,9 @@ -import { Form, Button, Select, Row, Col, message } from 'antd'; +import { Form, Button, Select, Row, Col, message, Input } from 'antd'; import Text from 'antd/lib/typography/Text'; import { useContext, useState } from 'react'; import { ThemeContext, getAccentColor, getThemedClass } from '../../../theme/themeProvider'; import styles from '../../../styles/ManageUsersTab.module.css'; +import Highlighter from 'react-highlight-words'; const { Option } = Select; @@ -25,22 +26,76 @@ export default function ManageRoleForm({ onSubmit, formData }: ManageFormProps) }; const { accentColor, baseTheme } = useContext(ThemeContext); - const [modified, setModified] = useState([]); - - // TODO: probably add search + const [nameFilter, setNameFilter] = useState(''); + const [roleFilter, setRoleFilter] = useState(''); + const [sortOrder, setSortOrder] = useState('ascend'); const [form] = Form.useForm(); + const filteredData = formData + .filter(item => { + const name = item.name.toLowerCase().includes(nameFilter.toLowerCase()); + const role = roleFilter ? item.userType === roleFilter : true; + return name && role; + }) + .sort((a, b) => { + if (sortOrder === 'ascend') { + return a.name.localeCompare(b.name); + } else { + return b.name.localeCompare(a.name); + } + }); + + const changeSortOrder = () => { + const newSortOrder = sortOrder === 'ascend' ? 'descend' : 'ascend'; + setSortOrder(newSortOrder); + }; + return (
- {formData.map(config => ( +
+ setNameFilter(e.target.value)} + style={{ width: 200, marginRight: 8 }} + /> + + + +
+ {filteredData.map(config => ( - {config.name} +