From 6e89190b8268158e9fcf7e577ca113ac65aec5bd Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Wed, 3 May 2023 13:44:50 +0200 Subject: [PATCH 1/3] :sparkles: Folder filter on name and number --- src/front/Components/DesignSystem/SearchBar/index.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/front/Components/DesignSystem/SearchBar/index.tsx b/src/front/Components/DesignSystem/SearchBar/index.tsx index 66f8f693..1bef9e75 100644 --- a/src/front/Components/DesignSystem/SearchBar/index.tsx +++ b/src/front/Components/DesignSystem/SearchBar/index.tsx @@ -53,9 +53,12 @@ export default class SearchBar extends React.Component { } private filterFolders(event: React.ChangeEvent) { - const filteredFolders: IDashBoardFolder[] = this.props.folders.filter((folder) => - folder.folder_number.includes(event.target.value), - ); + const filteredFolders: IDashBoardFolder[] = this.props.folders.filter((folder) =>{ + const name = folder.name.toLowerCase(); + const number = folder.folder_number.toLowerCase(); + const value = event.target.value.toLowerCase(); + return name.includes(value) || number.includes(value); + }); return filteredFolders; } } From f5729af068b94a8d5dc9037f79a6861a3aa83d1f Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Wed, 3 May 2023 13:52:21 +0200 Subject: [PATCH 2/3] :sparkles: Filter now include clients --- .../DesignSystem/SearchBar/index.tsx | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/front/Components/DesignSystem/SearchBar/index.tsx b/src/front/Components/DesignSystem/SearchBar/index.tsx index 1bef9e75..7d4ccd32 100644 --- a/src/front/Components/DesignSystem/SearchBar/index.tsx +++ b/src/front/Components/DesignSystem/SearchBar/index.tsx @@ -1,9 +1,10 @@ -import React from "react"; -import classes from "./classes.module.scss"; import LoopIcon from "@Assets/Icons/loop.svg"; -import Image from "next/image"; -import Typography, { ITypo } from "../Typography"; import { IDashBoardFolder } from "@Front/Components/LayoutTemplates/DefaultNotaryDashboard"; +import Image from "next/image"; +import React from "react"; + +import Typography, { ITypo } from "../Typography"; +import classes from "./classes.module.scss"; type IProps = { folders: IDashBoardFolder[]; @@ -53,10 +54,24 @@ export default class SearchBar extends React.Component { } private filterFolders(event: React.ChangeEvent) { - const filteredFolders: IDashBoardFolder[] = this.props.folders.filter((folder) =>{ + const filteredFolders: IDashBoardFolder[] = this.props.folders.filter((folder) => { const name = folder.name.toLowerCase(); const number = folder.folder_number.toLowerCase(); const value = event.target.value.toLowerCase(); + + if (folder.office_folder_has_customers) { + const customersNames = folder.office_folder_has_customers?.reduce((acc: string[], customer) => { + return acc.concat( + `${customer.customer.contact.first_name.toLowerCase()} ${customer.customer.contact.last_name.toLowerCase()}`, + ); + }, []); + let namesIncludesValue = false; + customersNames.forEach((name) => { + if (name.includes(value)) namesIncludesValue = true; + }); + return name.includes(value) || number.includes(value) || namesIncludesValue; + } + return name.includes(value) || number.includes(value); }); return filteredFolders; From 2416bba52af512a6eb42ed5ba9af0f48afe50fb1 Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Wed, 3 May 2023 13:58:58 +0200 Subject: [PATCH 3/3] :bug: Better implementation --- .../Components/DesignSystem/SearchBar/index.tsx | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/front/Components/DesignSystem/SearchBar/index.tsx b/src/front/Components/DesignSystem/SearchBar/index.tsx index 7d4ccd32..9d7d8090 100644 --- a/src/front/Components/DesignSystem/SearchBar/index.tsx +++ b/src/front/Components/DesignSystem/SearchBar/index.tsx @@ -60,16 +60,10 @@ export default class SearchBar extends React.Component { const value = event.target.value.toLowerCase(); if (folder.office_folder_has_customers) { - const customersNames = folder.office_folder_has_customers?.reduce((acc: string[], customer) => { - return acc.concat( - `${customer.customer.contact.first_name.toLowerCase()} ${customer.customer.contact.last_name.toLowerCase()}`, - ); - }, []); - let namesIncludesValue = false; - customersNames.forEach((name) => { - if (name.includes(value)) namesIncludesValue = true; - }); - return name.includes(value) || number.includes(value) || namesIncludesValue; + const customerNames = folder.office_folder_has_customers.map((customer) => { + return `${customer.customer.contact.first_name.toLowerCase()} ${customer.customer.contact.last_name.toLowerCase()}`; + }).join(", "); + return name.includes(value) || number.includes(value) || customerNames.includes(value); } return name.includes(value) || number.includes(value);