From 7258426bc1dc0aa39d01e866562e098d27307138 Mon Sep 17 00:00:00 2001 From: Katrinputrina Date: Tue, 3 Dec 2024 18:12:31 +0300 Subject: [PATCH] feat(SearchinProfolesManagment): add search by name --- .../AccessCoordinationList.tsx | 3 +++ .../ProfilesManagementLayout.i18n/en.json | 3 ++- .../ProfilesManagementLayout.i18n/ru.json | 3 ++- .../ProfilesManagementLayout.tsx | 13 ++++++++++++- .../ScheduledDeactivationList.tsx | 3 +++ .../UserCreateRequestsPage.tsx | 4 +++- .../UserDecreeRequestsPage.tsx | 3 +++ src/modules/scheduledDeactivationMethods.ts | 7 ++++++- src/modules/scheduledDeactivationSchemas.ts | 1 + 9 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/components/AccessCoordinationList/AccessCoordinationList.tsx b/src/components/AccessCoordinationList/AccessCoordinationList.tsx index 2b3ce21d..00abc5a1 100644 --- a/src/components/AccessCoordinationList/AccessCoordinationList.tsx +++ b/src/components/AccessCoordinationList/AccessCoordinationList.tsx @@ -7,6 +7,7 @@ import { RequestFormActions } from '../RequestFormActions/RequestFormActions'; import { ProfilesManagementLayout } from '../ProfilesManagementLayout/ProfilesManagementLayout'; import { getOrgUnitTitle } from '../../utils/organizationUnit'; import { useSessionUser } from '../../hooks/useSessionUser'; +import { useUserListFilter } from '../../hooks/useUserListFilter'; import s from './AccessCoordinationList.module.css'; import { tr } from './AccessCoordinationList.i18n'; @@ -41,6 +42,7 @@ const ClickableRow = forwardRef>((prop export const AccessCoordinationList = () => { const sessionUser = useSessionUser(); + const userListFilter = useUserListFilter(); const { DataTable, DataTableColumn } = getTableComponents(); @@ -58,6 +60,7 @@ export const AccessCoordinationList = () => { name: sorting.find(({ key }) => key === 'name')?.dir, createdAt: sorting.find(({ key }) => key === 'createdAt')?.dir, }, + search: userListFilter.values.search, }); const onEdit = (id: string, type: string) => { diff --git a/src/components/ProfilesManagementLayout/ProfilesManagementLayout.i18n/en.json b/src/components/ProfilesManagementLayout/ProfilesManagementLayout.i18n/en.json index e85edd84..e0c14c8a 100644 --- a/src/components/ProfilesManagementLayout/ProfilesManagementLayout.i18n/en.json +++ b/src/components/ProfilesManagementLayout/ProfilesManagementLayout.i18n/en.json @@ -4,5 +4,6 @@ "Access coordination": "", "Requests": "", "To decrees": "", - "From decrees": "" + "From decrees": "", + "Search in the table": "" } diff --git a/src/components/ProfilesManagementLayout/ProfilesManagementLayout.i18n/ru.json b/src/components/ProfilesManagementLayout/ProfilesManagementLayout.i18n/ru.json index cadac11e..3cf2388d 100644 --- a/src/components/ProfilesManagementLayout/ProfilesManagementLayout.i18n/ru.json +++ b/src/components/ProfilesManagementLayout/ProfilesManagementLayout.i18n/ru.json @@ -4,5 +4,6 @@ "Access coordination": "Согласование доступов", "Requests": "Заявки", "To decrees": "Выходы в декрет", - "From decrees": "Выходы из декрета" + "From decrees": "Выходы из декрета", + "Search in the table": "Поиск в таблице" } diff --git a/src/components/ProfilesManagementLayout/ProfilesManagementLayout.tsx b/src/components/ProfilesManagementLayout/ProfilesManagementLayout.tsx index a5dcc0ca..37fb7506 100644 --- a/src/components/ProfilesManagementLayout/ProfilesManagementLayout.tsx +++ b/src/components/ProfilesManagementLayout/ProfilesManagementLayout.tsx @@ -1,16 +1,19 @@ import React from 'react'; -import { Text } from '@taskany/bricks/harmony'; +import { GlobalSearch, Text } from '@taskany/bricks/harmony'; +import { FiltersSearchContainer } from '@taskany/bricks'; import { TabsSwitch } from '../TabsSwitch/TabsSwitch'; import { pages } from '../../hooks/useRouter'; import { LayoutMain } from '../LayoutMain/LayoutMain'; import { useSessionUser } from '../../hooks/useSessionUser'; +import { useUserListFilter } from '../../hooks/useUserListFilter'; import { tr } from './ProfilesManagementLayout.i18n'; import s from './ProfilesManagementLayout.module.css'; export const ProfilesManagementLayout = ({ children }: { children: React.ReactNode }) => { const sessionUser = useSessionUser(); + const userListFilter = useUserListFilter(); return (
@@ -49,6 +52,14 @@ export const ProfilesManagementLayout = ({ children }: { children: React.ReactNo }, ]} /> + + +
{children} diff --git a/src/components/ScheduledDeactivationList/ScheduledDeactivationList.tsx b/src/components/ScheduledDeactivationList/ScheduledDeactivationList.tsx index 0dc67192..e2b9369c 100644 --- a/src/components/ScheduledDeactivationList/ScheduledDeactivationList.tsx +++ b/src/components/ScheduledDeactivationList/ScheduledDeactivationList.tsx @@ -9,6 +9,7 @@ import { ScheduledDeactivationEditMenu } from '../ScheduledDeactivationEditMenu/ import { useSessionUser } from '../../hooks/useSessionUser'; import { ScheduleDeactivationForm } from '../ScheduleDeactivationForm/ScheduleDeactivationForm'; import { CancelScheduleDeactivation } from '../CancelScheduleDeactivation/CancelScheduleDeactivation'; +import { useUserListFilter } from '../../hooks/useUserListFilter'; import { tr } from './ScheduledDeactivationList.i18n'; import s from './ScheduledDeactivationList.module.css'; @@ -53,6 +54,7 @@ const CancelForm = ({ id, onClose }: EditOrCancelFormProps) => { export const ScheduledDeactivationList = () => { const { DataTable, DataTableColumn } = getTableComponents(); + const userListFilter = useUserListFilter(); const sessionUser = useSessionUser(); @@ -65,6 +67,7 @@ export const ScheduledDeactivationList = () => { name: sorting.find(({ key }) => key === 'name')?.dir, deactivateDate: sorting.find(({ key }) => key === 'deactivateDate')?.dir, }, + search: userListFilter.values.search, }); const data: tableData[] = scheduledDeactivations.map((deactivation) => ({ diff --git a/src/components/UserCreateRequestsPage/UserCreateRequestsPage.tsx b/src/components/UserCreateRequestsPage/UserCreateRequestsPage.tsx index a0c7e46d..26a523a1 100644 --- a/src/components/UserCreateRequestsPage/UserCreateRequestsPage.tsx +++ b/src/components/UserCreateRequestsPage/UserCreateRequestsPage.tsx @@ -8,6 +8,7 @@ import { pages, useRouter } from '../../hooks/useRouter'; import { RequestFormActions } from '../RequestFormActions/RequestFormActions'; import { ProfilesManagementLayout } from '../ProfilesManagementLayout/ProfilesManagementLayout'; import { useSessionUser } from '../../hooks/useSessionUser'; +import { useUserListFilter } from '../../hooks/useUserListFilter'; import { tr } from './UserCreateRequestsPage.i18n'; import s from './UserCreateRequestsPage.module.css'; @@ -35,7 +36,7 @@ const ClickableRow = forwardRef>((prop export const UserCreateRequestsPage = () => { const sessionUser = useSessionUser(); - + const userListFilter = useUserListFilter(); const dateTitleRef = useRef(null); const { DataTable, DataTableColumn } = getTableComponents(); @@ -51,6 +52,7 @@ export const UserCreateRequestsPage = () => { name: sorting.find(({ key }) => key === 'name')?.dir, date: sorting.find(({ key }) => key === 'date')?.dir, }, + search: userListFilter.values.search, }); const data: tableData[] = userRequests.map((request) => ({ diff --git a/src/components/UserDecreeRequestsPage/UserDecreeRequestsPage.tsx b/src/components/UserDecreeRequestsPage/UserDecreeRequestsPage.tsx index ea1ce88e..29cb46c3 100644 --- a/src/components/UserDecreeRequestsPage/UserDecreeRequestsPage.tsx +++ b/src/components/UserDecreeRequestsPage/UserDecreeRequestsPage.tsx @@ -6,6 +6,7 @@ import { pages, useRouter } from '../../hooks/useRouter'; import { RequestFormActions } from '../RequestFormActions/RequestFormActions'; import { ProfilesManagementLayout } from '../ProfilesManagementLayout/ProfilesManagementLayout'; import { useSessionUser } from '../../hooks/useSessionUser'; +import { useUserListFilter } from '../../hooks/useUserListFilter'; import { tr } from './UserDecreeRequestsPage.i18n'; import s from './UserDecreeRequestsPage.module.css'; @@ -37,6 +38,7 @@ export const UserDecreeRequestsPage: FC = ({ type } const dateTitleRef = useRef(null); const router = useRouter(); + const userListFilter = useUserListFilter(); const { DataTable, DataTableColumn } = getTableComponents(); const [sorting, setSorting] = useState['sorting']>([ @@ -50,6 +52,7 @@ export const UserDecreeRequestsPage: FC = ({ type } name: sorting.find(({ key }) => key === 'name')?.dir, date: sorting.find(({ key }) => key === 'date')?.dir, }, + search: userListFilter.values.search, }); const data: tableData[] = userRequests.map((request) => ({ diff --git a/src/modules/scheduledDeactivationMethods.ts b/src/modules/scheduledDeactivationMethods.ts index 18a08ea4..ba6b5ba4 100644 --- a/src/modules/scheduledDeactivationMethods.ts +++ b/src/modules/scheduledDeactivationMethods.ts @@ -109,8 +109,9 @@ export const scheduledDeactivationMethods = { return scheduledDeactivation; }, - getList: async ({ creatorId, orderBy: order }: GetScheduledDeactivationList) => { + getList: async ({ creatorId, orderBy: order, search }: GetScheduledDeactivationList) => { let orderBy: Prisma.ScheduledDeactivationOrderByWithRelationAndSearchRelevanceInput[] = []; + const where: Prisma.ScheduledDeactivationWhereInput = {}; if (order?.name) { orderBy = [{ user: { name: order.name } }]; @@ -120,6 +121,10 @@ export const scheduledDeactivationMethods = { orderBy = [{ deactivateDate: order.deactivateDate }]; } + if (search) { + where.user = { name: { contains: search, mode: 'insensitive' } }; + } + return prisma.scheduledDeactivation.findMany({ where: { creatorId, canceled: false }, include: { diff --git a/src/modules/scheduledDeactivationSchemas.ts b/src/modules/scheduledDeactivationSchemas.ts index 74aeb115..6e4538ff 100644 --- a/src/modules/scheduledDeactivationSchemas.ts +++ b/src/modules/scheduledDeactivationSchemas.ts @@ -94,6 +94,7 @@ export const getScheduledDeactivationListSchema = z.object({ name: z.enum(['asc', 'desc']).optional(), }) .optional(), + search: z.string().optional(), }); export type GetScheduledDeactivationList = z.infer;