Skip to content

Commit

Permalink
feat(SearchinProfolesManagment): add search by name
Browse files Browse the repository at this point in the history
  • Loading branch information
Katrin-kudryash committed Dec 5, 2024
1 parent 5df01ff commit 7258426
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -41,6 +42,7 @@ const ClickableRow = forwardRef<HTMLDivElement, React.ComponentProps<any>>((prop

export const AccessCoordinationList = () => {
const sessionUser = useSessionUser();
const userListFilter = useUserListFilter();

const { DataTable, DataTableColumn } = getTableComponents<tableData[]>();

Expand All @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"Access coordination": "",
"Requests": "",
"To decrees": "",
"From decrees": ""
"From decrees": "",
"Search in the table": ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"Access coordination": "Согласование доступов",
"Requests": "Заявки",
"To decrees": "Выходы в декрет",
"From decrees": "Выходы из декрета"
"From decrees": "Выходы из декрета",
"Search in the table": "Поиск в таблице"
}
Original file line number Diff line number Diff line change
@@ -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 (
<LayoutMain>
<div className={s.Wrapper}>
Expand Down Expand Up @@ -49,6 +52,14 @@ export const ProfilesManagementLayout = ({ children }: { children: React.ReactNo
},
]}
/>
<FiltersSearchContainer>
<GlobalSearch
placeholder={tr('Search in the table')}
defaultValue={userListFilter.values.search}
onChange={userListFilter.setSearch}
outline
/>
</FiltersSearchContainer>
</div>
{children}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -53,6 +54,7 @@ const CancelForm = ({ id, onClose }: EditOrCancelFormProps) => {

export const ScheduledDeactivationList = () => {
const { DataTable, DataTableColumn } = getTableComponents<tableData[]>();
const userListFilter = useUserListFilter();

const sessionUser = useSessionUser();

Expand All @@ -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) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -35,7 +36,7 @@ const ClickableRow = forwardRef<HTMLDivElement, React.ComponentProps<any>>((prop

export const UserCreateRequestsPage = () => {
const sessionUser = useSessionUser();

const userListFilter = useUserListFilter();
const dateTitleRef = useRef(null);

const { DataTable, DataTableColumn } = getTableComponents<tableData[]>();
Expand All @@ -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) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -37,6 +38,7 @@ export const UserDecreeRequestsPage: FC<UserDecreeRequestsPageProps> = ({ type }
const dateTitleRef = useRef(null);
const router = useRouter();

const userListFilter = useUserListFilter();
const { DataTable, DataTableColumn } = getTableComponents<tableData[]>();

const [sorting, setSorting] = useState<React.ComponentProps<typeof DataTable>['sorting']>([
Expand All @@ -50,6 +52,7 @@ export const UserDecreeRequestsPage: FC<UserDecreeRequestsPageProps> = ({ 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) => ({
Expand Down
7 changes: 6 additions & 1 deletion src/modules/scheduledDeactivationMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }];
Expand All @@ -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: {
Expand Down
1 change: 1 addition & 0 deletions src/modules/scheduledDeactivationSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof getScheduledDeactivationListSchema>;

0 comments on commit 7258426

Please sign in to comment.