Skip to content
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

Feature/school 725/add search parameter #151

Merged
merged 23 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c83bde5
Merge pull request #18 from LamArt/dev
zavarin-michael Jul 24, 2023
2a661d1
Merge pull request #22 from LamArt/dev
zavarin-michael Jul 24, 2023
49832d3
Merge pull request #46 from LamArt/dev
zavarin-michael Aug 8, 2023
27e3f4c
Merge pull request #48 from LamArt/dev
zavarin-michael Aug 8, 2023
219e7ba
Merge pull request #50 from LamArt/dev
zavarin-michael Aug 8, 2023
ef4e2a5
Merge pull request #51 from LamArt/dev
zavarin-michael Aug 8, 2023
56bfc82
Merge pull request #57 from LamArt/dev
zavarin-michael Aug 25, 2023
a727284
Merge pull request #84 from LamArt/dev
zavarin-michael Sep 12, 2023
7cbeb05
Merge pull request #94 from LamArt/dev
zavarin-michael Oct 18, 2023
e60b7cf
Merge pull request #99 from LamArt/dev
zavarin-michael Oct 26, 2023
12cd3a7
Merge pull request #109 from LamArt/dev
zavarin-michael Mar 18, 2024
1f7a0a3
Merge pull request #119 from LamArt/dev
zavarin-michael Mar 18, 2024
56cd9a7
Merge pull request #138 from open-schools/dev
zavarin-michael Jun 7, 2024
0d9f1fe
Merge pull request #146 from open-schools/dev
zavarin-michael Jun 24, 2024
30570a3
Merge branch 'refs/heads/main' into dev
nenichv Jul 11, 2024
ddca603
Merge remote-tracking branch 'origin/dev' into dev
nenichv Jul 11, 2024
66e7856
add search parameter in query/ticket/employee tables
nenichv Jul 11, 2024
ea2d023
delete localstorage, add query state in input search
nenichv Jul 12, 2024
cf253b0
Merge remote-tracking branch 'origin/dev' into dev
nenichv Jul 15, 2024
99a54f7
fix
nenichv Jul 15, 2024
a7eaa11
Merge remote-tracking branch 'origin/dev' into dev
nenichv Jul 17, 2024
3657815
Merge branch 'refs/heads/dev' into feature/SCHOOL-725/add-search-para…
nenichv Jul 17, 2024
77cdc8b
fix conflict
nenichv Jul 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions apps/schools/domains/circle/components/circleList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import { getVarsForAddressColumn } from '@domains/common/utils/geo'
import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums'
import { defaultPaginationTablePage, defaultPaginationTablePageSize } from '@domains/common/constants/Table'
import { scrollToTop } from '@domains/common/utils/scrollInDirection'
import {useQueryState} from "next-usequerystate";

export function CircleList() {
const [searchRequestText, setSearchRequestText] = useState('')
const [searchRequestText, setSearchRequestText] = useQueryState('search')
const { organizationId } = useOrganization()

const [paginationParams, setPaginationParams] = useState({
Expand All @@ -27,7 +28,7 @@ export function CircleList() {

const { data: circles, isFetching: isFetching } = useGetAllCirclesQuery({
organization_id: organizationId,
or_search: createSearchTextForRequest(searchRequestText, searchStudentsColumns),
or_search: createSearchTextForRequest(searchRequestText || '', searchStudentsColumns),
page: paginationParams.page,
page_size: paginationParams.pageSize,
})
Expand All @@ -41,7 +42,7 @@ export function CircleList() {
data={circles}
isLoading={isFetching}
handleRunTask={() => router.push(RoutePath[AppRoutes.CIRCLE_CREATE])}
searchTrigger={searchRequestText}
searchTrigger={searchRequestText || ''}
>
<div className={styles.header}>
<Typography.Title level={1}>Кружки</Typography.Title>
Expand Down Expand Up @@ -94,8 +95,8 @@ export function CircleList() {
},
}}
customWidths={[60, 25, 15]}
searchRequestText={searchRequestText}
setSearchRequestText={setSearchRequestText}
searchRequestText={searchRequestText || ''}
setSearchRequestText={(text) => setSearchRequestText(text)}
rowClassName={styles.tableRowPointer}
/>
</EmptyWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ import { getVarsForAddressColumn } from '@domains/common/utils/geo'
import { StatusesEnum } from '@domains/common/constants/Enums'
import { ErrorType } from '@store/commonApi'
import { AppRoutes, DynamicAppRoutes, DynamicRoutePath, RoutePath } from '@domains/common/constants/routerEnums'
import {useQueryState} from "next-usequerystate";

const CurrentCircle = () => {
const [isModalVisible, setIsModalVisible] = useState(false)
const [searchRequestText, setSearchRequestText] = useState('')
const [searchRequestText, setSearchRequestText] = useQueryState('search')
const [mutation, isDeleteFinished] = useDeleteCircleMutation()
const uuid = getUuidFromUrl()
const router = useRouter()
Expand All @@ -40,7 +41,7 @@ const CurrentCircle = () => {
const { data: circle, error: circleError } = useGetCircleQuery({ circle_id: uuid[0] })
const { data: students, isLoading } = useGetCircleStudentsQuery({
circle_id: uuid[0],
or_search: createSearchTextForRequest(searchRequestText, searchColumns),
or_search: createSearchTextForRequest(searchRequestText || '', searchColumns),
})
const { data: queryData } = useGetCurrentCircleQuery({ circle_id: uuid[0], organization_id: organizationId })

Expand Down Expand Up @@ -135,8 +136,8 @@ const CurrentCircle = () => {
isLoading={isLoading}
needNumbering={true}
searchFields={['student_name', 'student_phone', 'parent_names', 'parent_phones']}
searchRequestText={searchRequestText}
setSearchRequestText={setSearchRequestText}
searchRequestText={searchRequestText || ''}
setSearchRequestText={(text) => setSearchRequestText(text)}
/>
</div>
<Col span={24} className={styles.buttonBar}>
Expand Down
7 changes: 4 additions & 3 deletions apps/schools/domains/common/components/searchInput/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React, { useState, ChangeEvent } from 'react'
import React, { ChangeEvent } from 'react'
import { Input } from '@domains/common/components/input'
import { CloseCircleOutlined, SearchOutlined } from '@ant-design/icons'
import styles from './styles/styles.module.scss'
import { useQueryState } from 'next-usequerystate'

interface SearchInputProps {
onSearchChange: (value: string) => void
}

const SearchInput: React.FC<SearchInputProps> = ({ onSearchChange }) => {
const [inputText, setInputText] = useState('')
const [inputText, setInputText] = useQueryState('search')

const handleInputChange = (event: ChangeEvent<HTMLInputElement>) => {
const value = event.target.value
Expand All @@ -21,7 +22,7 @@ const SearchInput: React.FC<SearchInputProps> = ({ onSearchChange }) => {
onChange={handleInputChange}
customType={'inputSearch'}
placeholder={'Поиск'}
value={inputText}
value={inputText || ''}
children={
<>
<SearchOutlined className={styles.search} />
Expand Down
5 changes: 3 additions & 2 deletions apps/schools/domains/common/components/table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { typeTable } from '@domains/common/constants/Table'
import { CustomTableProps } from '@domains/common/components/table/interfaces'
import { calculateAverageWidth } from '@domains/common/utils/calculateAverageWidth'
import { ColumnType } from 'antd/lib/table/interface'
import { useQueryState } from "next-usequerystate";

export const Table = <RowType, DataItemType>(props: CustomTableProps<RowType, DataItemType>) => {
const {
Expand Down Expand Up @@ -64,7 +65,7 @@ export const Table = <RowType, DataItemType>(props: CustomTableProps<RowType, Da
]

const [isTableLoading, setIsTableLoading] = useState(false)
const [inputText, setInputText] = useState('')
const [inputText, setInputText] = useQueryState('search')
const [dataSource, setDataSource] = useState<any[]>([])
const router = useRouter()

Expand Down Expand Up @@ -134,7 +135,7 @@ export const Table = <RowType, DataItemType>(props: CustomTableProps<RowType, Da
}}
customType={'inputSearch'}
placeholder={'Поиск'}
value={inputText}
value={inputText || ''}
children={
<>
<SearchOutlined className={styles.search} />
Expand Down
6 changes: 5 additions & 1 deletion apps/schools/domains/common/components/table/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ReturnedData } from '@domains/common/redux/interfaces'
import { TableProps } from 'antd'
import { ColumnFilterItem } from 'antd/lib/table/interface'
import { Key } from 'antd/es/table/interface'
import {Options} from "next-usequerystate";

export interface CustomFieldsProps {
[key: string]: React.FC<{
Expand Down Expand Up @@ -30,7 +31,10 @@ export interface CustomTableProps<RowType, DataItemType> extends TableProps<any>
customFields?: CustomFieldsProps
searchRequestText: string
needNumbering?: boolean
setSearchRequestText: React.Dispatch<React.SetStateAction<string>>
setSearchRequestText: <Shallow>(
value: string | ((old: string | null) => string | null) | null,
options?: Options<Shallow> | undefined,
) => Promise<URLSearchParams>
mainRoute: string
sortFields?: string[]
customFilterFields?: CustomFilterFieldsProps<RowType>
Expand Down
15 changes: 8 additions & 7 deletions apps/schools/domains/employee/components/employeeList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import { searchColumns } from '@domains/employee/components/employeeList/constan
import { AppRoutes, RoutePath } from '@domains/common/constants/routerEnums'
import { defaultPaginationTablePage, defaultPaginationTablePageSize } from '@domains/common/constants/Table'
import { scrollToTop } from '@domains/common/utils/scrollInDirection'
import { useQueryState } from 'next-usequerystate'

export function EmployeeList() {
const [searchRequestText, setSearchRequestText] = useState('')
const { organizationId } = useOrganization()
const [searchRequest, setSearchRequest] = useQueryState('search')

const [paginationParams, setPaginationParams] = useState({
page: defaultPaginationTablePage,
Expand All @@ -25,7 +26,7 @@ export function EmployeeList() {

const { data, isFetching } = useGetAllEmployeesQuery({
organization: organizationId,
or_search: createSearchTextForRequest(searchRequestText, searchColumns),
or_search: createSearchTextForRequest(searchRequest || '', searchColumns),
page: paginationParams.page,
page_size: paginationParams.pageSize,
})
Expand Down Expand Up @@ -58,17 +59,17 @@ export function EmployeeList() {
setPaginationParams({
page,
pageSize,
})
scrollToTop()
});
scrollToTop();
},
}}
data={data}
isLoading={isFetching}
mainRoute={RoutePath[AppRoutes.EMPLOYEE_LIST]}
searchFields={searchColumns}
searchRequestText={searchRequestText}
setSearchRequestText={setSearchRequestText}
searchRequestText={searchRequest || ''}
setSearchRequestText={(text) => setSearchRequest(text)}
/>
</>
)
}
}
14 changes: 6 additions & 8 deletions apps/schools/domains/query/components/queryList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { scrollToTop } from '@domains/common/utils/scrollInDirection'

export function QueryList() {
const { organizationId } = useOrganization()
const [searchRequestText, setSearchRequestText] = useState('')
const [searchRequest, setSearchRequest] = useQueryState('search')
const [isTableLoading, setIsTableLoading] = useState(false)

const [statuses, setStatuses] = useQueryState(
Expand Down Expand Up @@ -77,7 +77,7 @@ export function QueryList() {

const { data: queries, isFetching: isQueriesFetching } = useGetAllJoinCircleQueriesQuery({
circle__organization__id: organizationId,
or_search: createSearchTextForRequest(searchRequestText, searchStudentsColumns),
or_search: createSearchTextForRequest(searchRequest || '', searchStudentsColumns),
page: paginationParams.page,
page_size: paginationParams.pageSize,
})
Expand All @@ -95,9 +95,7 @@ export function QueryList() {

const handleSearchChange = useCallback((value: string) => {
setIsTableLoading(true)
setTimeout(() => {
setSearchRequestText(value)
}, 1000)
setSearchRequest(value)
}, [])

return (
Expand All @@ -107,7 +105,7 @@ export function QueryList() {
pageTitle={'Заявки'}
data={queries}
isLoading={isQueriesFetching}
searchTrigger={searchRequestText}
searchTrigger={searchRequest || ''}
>
<div className={styles.header}>
<Typography.Title level={1}>Заявки</Typography.Title>
Expand Down Expand Up @@ -202,8 +200,8 @@ export function QueryList() {
},
}}
sortFields={['created_at']}
searchRequestText={searchRequestText}
setSearchRequestText={setSearchRequestText}
searchRequestText={searchRequest || ''}
setSearchRequestText={(text) => setSearchRequest(text)}
onChange={(pagination, filters, sorter) => {
const localStatuses = [...(filters['status'] ?? [])] as string[]
setStatuses(localStatuses.length === 0 ? null : localStatuses)
Expand Down
17 changes: 9 additions & 8 deletions apps/schools/domains/student/components/studentList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useState } from 'react'
import React, { useCallback, useState } from 'react'
import { Typography } from 'antd'
import router from 'next/router'
import styles from './styles/styles.module.scss'
Expand All @@ -17,6 +17,7 @@ import { scrollToTop } from '@domains/common/utils/scrollInDirection'
import { handlePaginationChange } from '@domains/common/handlers/paginationChange'
import { calculateResults } from '@domains/student/handlers/resultsCalculate'
import { getTotalPages } from '@domains/common/utils/getTotalPages'
import { useQueryState } from "next-usequerystate"

export function StudentList() {
const [queryPaginationParams, setQueryPaginationParams] = useState({
Expand All @@ -30,20 +31,20 @@ export function StudentList() {
},
})

const [searchRequestText, setSearchRequestText] = useState('')
const [searchRequestText, setSearchRequestText] = useQueryState('search')
const { organizationId } = useOrganization()

const { data: invites, isLoading: isLoadingInvites } = useGetAllStudentInvitationsQuery({
circle__organization__id: organizationId,
status: StatusesEnum.SENT,
or_search: createSearchTextForRequest(searchRequestText, searchInvitesColumns),
or_search: createSearchTextForRequest(searchRequestText || '', searchInvitesColumns),
page: queryPaginationParams.invites.page,
page_size: queryPaginationParams.invites.pageSize,
})

const { data: students, isFetching: isFetchingStudents } = useGetAllStudentsQuery({
circle__organization: organizationId,
or_search: createSearchTextForRequest(searchRequestText, searchStudentsColumns),
or_search: createSearchTextForRequest(searchRequestText || '', searchStudentsColumns),
page: queryPaginationParams.students.page,
page_size: queryPaginationParams.students.pageSize,
})
Expand Down Expand Up @@ -90,7 +91,7 @@ export function StudentList() {
data={data}
isLoading={isFetchingStudents || isLoadingInvites}
handleRunTask={() => router.push(RoutePath[AppRoutes.STUDENT_CREATE])}
searchTrigger={searchRequestText}
searchTrigger={searchRequestText || ''}
>
<div className={styles.header}>
<Typography.Title level={1}>Обучающиеся</Typography.Title>
Expand Down Expand Up @@ -127,9 +128,9 @@ export function StudentList() {
isLoading={isLoadingInvites || isFetchingStudents}
mainRoute={RoutePath[AppRoutes.STUDENT_LIST]}
searchFields={['student_name', 'student_phone', 'parent_phone', 'circle_name']}
searchRequestText={searchRequestText}
setSearchRequestText={setSearchRequestText}
searchRequestText={searchRequestText || ''}
setSearchRequestText={(text) => setSearchRequestText(text)}
/>
</EmptyWrapper>
)
}
}
20 changes: 8 additions & 12 deletions apps/schools/domains/ticket/components/ticketList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ type HandleChange = (

export function TicketList() {
const [inputText, setInputText] = useState('')
const [searchRequestText, setSearchRequestText] = useState('')
const [isTableLoading, setIsTableLoading] = useState(false)
const { organizationId } = useOrganization()
const [searchRequest, setSearchRequest] = useQueryState('search')

const [statuses, setStatuses] = useQueryState(
'statuses',
Expand Down Expand Up @@ -77,7 +77,7 @@ export function TicketList() {

const { data: tickets, isFetching: isTicketsFetching } = useGetAllTicketsQuery({
organization_id: organizationId,
or_search: createSearchTextForRequest(searchRequestText, searchTicketsColumns),
or_search: createSearchTextForRequest(searchRequest || '', searchTicketsColumns),
page: paginationParams.page,
page_size: paginationParams.pageSize,
})
Expand All @@ -93,18 +93,14 @@ export function TicketList() {
if (typeof text === 'string') {
setIsTableLoading(true)
setInputText(text)
setTimeout(() => {
setSearchRequestText(text)
}, 1000)
setSearchRequest(text)
} else {
setIsTableLoading(true)
setInputText(text.target.value)
setTimeout(() => {
setSearchRequestText(text.target.value)
}, 1000)
setSearchRequest(text.target.value)
}
},
[setIsTableLoading, setInputText, setSearchRequestText],
[setIsTableLoading, setInputText, setSearchRequest],
)

const handleChange: HandleChange = useCallback(
Expand All @@ -122,7 +118,7 @@ export function TicketList() {
pageTitle={'Обращения'}
data={tickets}
isLoading={isTicketsFetching}
searchTrigger={searchRequestText}
searchTrigger={searchRequest || ''}
>
<div className={styles.header}>
<Typography.Title level={1}>Обращения</Typography.Title>
Expand Down Expand Up @@ -209,8 +205,8 @@ export function TicketList() {
},
}}
sortFields={['created_at']}
searchRequestText={searchRequestText}
setSearchRequestText={setSearchRequestText}
searchRequestText={searchRequest || ''}
setSearchRequestText={(text) => setSearchRequest(text)}
onChange={handleChange}
/>
</div>
Expand Down
Loading