From 4f862049716070ef5082b93bfdd68796849e5ac9 Mon Sep 17 00:00:00 2001 From: Imen Chermiti <127976664+ImenOuidou@users.noreply.github.com> Date: Wed, 1 Nov 2023 21:43:15 +0100 Subject: [PATCH] feat: Feat new design (#301) * feat: new design fixes * feat: new design fixes * feat: new design fixes --- .../ListEtablishments/ListEstablishment.jsx | 137 +--------------- .../Establishments.jsx | 142 +--------------- .../EstablishmentTable/EstablishmentTable.jsx | 153 ++++++++++++++++++ .../PaginationTable/PaginationTable.jsx | 44 +++-- .../components/SearchAwesomeTable/Pager.js | 71 -------- .../SearchAwesomeTable/SearchAwesomeTable.js | 8 +- 6 files changed, 198 insertions(+), 357 deletions(-) create mode 100644 src/client/src/components/DataSheets/Sections/SharedComponents/EstablishmentTable/EstablishmentTable.jsx delete mode 100644 src/client/src/components/SearchAwesomeTable/Pager.js diff --git a/src/client/src/components/DataSheets/Sections/Establishment/ListEtablishments/ListEstablishment.jsx b/src/client/src/components/DataSheets/Sections/Establishment/ListEtablishments/ListEstablishment.jsx index c73dc3c6..bbca6b6a 100644 --- a/src/client/src/components/DataSheets/Sections/Establishment/ListEtablishments/ListEstablishment.jsx +++ b/src/client/src/components/DataSheets/Sections/Establishment/ListEtablishments/ListEstablishment.jsx @@ -1,130 +1,25 @@ import React, { useState } from "react"; -import { Link, useHistory } from "react-router-dom"; -import { isActiveEstablishment } from "../../../../../helpers/Search"; -import { - formatSiret, - getLibelletFromCodeNaf, - joinNoFalsy, -} from "../../../../../helpers/utils"; -import Config from "../../../../../services/Config"; import { getEtablissements } from "../../../../../utils/entreprise/entreprise"; -import { isActive } from "../../../../../utils/establishment/establishment"; -import BadgeWithIcon from "../../../../shared/Badge/BadgeWithIcon.jsx"; -import Value from "../../../../shared/Value"; import { getEtablissementsCount } from "../../../Sidebar/Sidebar.gql"; import BlocTitle from "../../SharedComponents/BlocTitle/BlocTitle.jsx"; import { useEstablishmentData } from "../../SharedComponents/EstablishmentContext.jsx"; -import NonBorderedTable from "../../SharedComponents/NonBorderedTable/NonBorderedTable"; -import PaginationTable from "../../SharedComponents/PaginationTable/PaginationTable.jsx"; +import EstablishmentTable from "../../SharedComponents/EstablishmentTable/EstablishmentTable.jsx"; const ListEstablishment = () => { const { loading, data: entreprise, error } = useEstablishmentData(); - const history = useHistory(); + const [accordionOpen, setAccordionOpen] = useState(true); - const [currentPage, setCurrentPage] = useState(1); if (loading || error) { return null; } - const rowsPerPage = 10; - // Calculate the total number of pages - const totalPages = Math.ceil( - entreprise?.entreprise_nbr_etablissements_siren?.nb_eta / rowsPerPage - ); - - // Calculate the starting and ending index for the current page - const startIndex = (currentPage - 1) * rowsPerPage; - const endIndex = Math.min( - startIndex + rowsPerPage, - entreprise?.entreprise_nbr_etablissements_siren?.nb_eta - ); const etablissements = entreprise ? getEtablissements(entreprise) : []; - const staffSizeRanges = { - ...Config.get("inseeSizeRanges"), - "0 salarié": "0 salarié", - }; + const etablissementsCount = entreprise ? getEtablissementsCount(entreprise) : 0; - const handlePageClick = (page) => { - if (page >= 1 && page <= totalPages) { - setCurrentPage(page); - } - }; - const renderTableBody = () => { - const data = - etablissementsCount > rowsPerPage - ? etablissements?.slice(startIndex, endIndex) - : etablissements; - - return data?.map((etablissement) => { - const isEtablissementActive = isActive(etablissement); - const stateClass = isEtablissementActive - ? "icon--success" - : "icon--danger"; - const stateText = isEtablissementActive ? "ouvert" : "fermé"; - return ( - history.push(`/establishment/${etablissement?.siret}`)} - > - - - - - - - - - - - - - - - - - - - {`${etablissement?.activiteprincipaleetablissement || ""} - ${ - getLibelletFromCodeNaf( - etablissement?.activiteprincipaleetablissement - ) || "" - }`} - - ); - }); - }; return (
@@ -139,28 +34,10 @@ const ListEstablishment = () => {
{etablissementsCount > 0 && (
- - - - SIRET - État - Code postal - Effectif (DSN) - Raison social / Nom - Activité - - - {renderTableBody()} - - {etablissementsCount > rowsPerPage && ( -
- -
- )} +
)}
diff --git a/src/client/src/components/DataSheets/Sections/ListEstablishmentsResult/Establishments.jsx b/src/client/src/components/DataSheets/Sections/ListEstablishmentsResult/Establishments.jsx index 8629faa6..b4eb2c95 100644 --- a/src/client/src/components/DataSheets/Sections/ListEstablishmentsResult/Establishments.jsx +++ b/src/client/src/components/DataSheets/Sections/ListEstablishmentsResult/Establishments.jsx @@ -1,162 +1,34 @@ import "./ListEstablishmentsResult.scss"; -import React, { useState } from "react"; -import { useHistory } from "react-router"; -import { Link } from "react-router-dom"; +import React from "react"; -import { isActiveEstablishment } from "../../../../helpers/Search/Search.js"; -import { formatSiret } from "../../../../helpers/utils/format.js"; -import { - getLibelletFromCodeNaf, - joinNoFalsy, -} from "../../../../helpers/utils/utils.js"; -import Config from "../../../../services/Config/Config.js"; import { getEtablissements } from "../../../../utils/entreprise/entreprise.js"; -import { isActive } from "../../../../utils/establishment/establishment.js"; -import BadgeWithIcon from "../../../shared/Badge/BadgeWithIcon.jsx"; import Value from "../../../shared/Value/Value.js"; import { getEtablissementsCount } from "../../Sidebar/Sidebar.gql.js"; import { useEstablishmentData } from "../SharedComponents/EstablishmentContext.jsx"; -import NonBorderedTable from "../SharedComponents/NonBorderedTable/NonBorderedTable.js"; -import PaginationTable from "../SharedComponents/PaginationTable/PaginationTable.jsx"; +import EstablishmentTable from "../SharedComponents/EstablishmentTable/EstablishmentTable.jsx"; export const Establishments = () => { const { loading, data: entreprise, error } = useEstablishmentData(); - const history = useHistory(); - const [currentPage, setCurrentPage] = useState(1); if (loading || error) { return null; } - - const rowsPerPage = 10; - // Calculate the total number of pages - const totalPages = Math.ceil( - entreprise?.entreprise_nbr_etablissements_siren?.nb_eta / rowsPerPage - ); - - // Calculate the starting and ending index for the current page - const startIndex = (currentPage - 1) * rowsPerPage; - const endIndex = Math.min( - startIndex + rowsPerPage, - entreprise?.entreprise_nbr_etablissements_siren?.nb_eta - ); - const etablissements = entreprise ? getEtablissements(entreprise) : []; - const staffSizeRanges = { - ...Config.get("inseeSizeRanges"), - "0 salarié": "0 salarié", - }; - - const handlePageClick = (page) => { - if (page >= 1 && page <= totalPages) { - setCurrentPage(page); - } - }; - const etablissementsCount = entreprise ? getEtablissementsCount(entreprise) : 0; - const renderTableBody = () => { - const data = - etablissementsCount > rowsPerPage - ? etablissements?.slice(startIndex, endIndex) - : etablissements; - return data?.map((etablissement) => { - const isEtablissementActive = isActive(etablissement); - const stateClass = isEtablissementActive - ? "icon--success" - : "icon--danger"; - const stateText = isEtablissementActive ? "ouvert" : "fermé"; - return ( - history.push(`/establishment/${etablissement?.siret}`)} - > - - - - - - - - + const etablissements = entreprise ? getEtablissements(entreprise) : []; - - - - - - - - - - {`${etablissement?.activiteprincipaleetablissement || ""} - ${ - getLibelletFromCodeNaf( - etablissement?.activiteprincipaleetablissement - ) || "" - }`} - - ); - }); - }; return (

Liste des etablissements ( )

-
- - - - SIRET - État - Code postal - Effectif (DSN) - Raison social / Nom - Activité - - - {renderTableBody()} - - {etablissementsCount > rowsPerPage && ( -
- -
- )} -
+
); }; diff --git a/src/client/src/components/DataSheets/Sections/SharedComponents/EstablishmentTable/EstablishmentTable.jsx b/src/client/src/components/DataSheets/Sections/SharedComponents/EstablishmentTable/EstablishmentTable.jsx new file mode 100644 index 00000000..e283ed8f --- /dev/null +++ b/src/client/src/components/DataSheets/Sections/SharedComponents/EstablishmentTable/EstablishmentTable.jsx @@ -0,0 +1,153 @@ +import PropTypes from "prop-types"; +import React, { useState } from "react"; +import { Link, useHistory } from "react-router-dom"; + +import { isActiveEstablishment } from "../../../../../helpers/Search/Search.js"; +import { formatSiret } from "../../../../../helpers/utils/format.js"; +import { + getLibelletFromCodeNaf, + joinNoFalsy, +} from "../../../../../helpers/utils/utils.js"; +import Config from "../../../../../services/Config/Config.js"; +import { isActive } from "../../../../../utils/establishment/establishment.js"; +import BadgeWithIcon from "../../../../shared/Badge/BadgeWithIcon.jsx"; +import Value from "../../../../shared/Value/Value.js"; +import { getEtablissementsCount } from "../../../Sidebar/Sidebar.gql.js"; +import NonBorderedTable from "../NonBorderedTable/NonBorderedTable.js"; +import PaginationTable from "../PaginationTable/PaginationTable.jsx"; + +const EstablishmentTable = ({ etablissements, entreprise }) => { + const history = useHistory(); + const [currentPage, setCurrentPage] = useState(1); + + const staffSizeRanges = { + ...Config.get("inseeSizeRanges"), + "0 salarié": "0 salarié", + }; + const rowsPerPage = 10; + // Calculate the total number of pages + const totalPages = Math.ceil( + entreprise?.entreprise_nbr_etablissements_siren?.nb_eta / rowsPerPage + ); + + // Calculate the starting and ending index for the current page + const startIndex = (currentPage - 1) * rowsPerPage; + const endIndex = Math.min( + startIndex + rowsPerPage, + entreprise?.entreprise_nbr_etablissements_siren?.nb_eta + ); + + const handlePageClick = (page) => { + if (page >= 1 && page <= totalPages) { + setCurrentPage(page); + } + }; + + const etablissementsCount = entreprise + ? getEtablissementsCount(entreprise) + : 0; + const renderTableBody = () => { + const data = + etablissementsCount > rowsPerPage + ? etablissements?.slice(startIndex, endIndex) + : etablissements; + return data?.map((etablissement) => { + const isEtablissementActive = isActive(etablissement); + const stateClass = isEtablissementActive + ? "icon--success" + : "icon--danger"; + const stateText = isEtablissementActive ? "ouvert" : "fermé"; + return ( + history.push(`/establishment/${etablissement?.siret}`)} + > + + + + + + + + + + + + + + + + + + + {`${etablissement?.activiteprincipaleetablissement || ""} - ${ + getLibelletFromCodeNaf( + etablissement?.activiteprincipaleetablissement + ) || "" + }`} + + ); + }); + }; + return ( +
+ + + + SIRET + État + Code postal + Effectif (DSN) + Raison social / Nom + Activité + + + {renderTableBody()} + + {etablissementsCount > rowsPerPage && ( +
+ +
+ )}{" "} +
+ ); +}; + +EstablishmentTable.propTypes = { + entreprise: PropTypes.object.isRequired, + etablissements: PropTypes.array.isRequired, +}; +export default EstablishmentTable; diff --git a/src/client/src/components/DataSheets/Sections/SharedComponents/PaginationTable/PaginationTable.jsx b/src/client/src/components/DataSheets/Sections/SharedComponents/PaginationTable/PaginationTable.jsx index 16d8b2ac..aadefb27 100644 --- a/src/client/src/components/DataSheets/Sections/SharedComponents/PaginationTable/PaginationTable.jsx +++ b/src/client/src/components/DataSheets/Sections/SharedComponents/PaginationTable/PaginationTable.jsx @@ -4,7 +4,12 @@ import React from "react"; import LeftArrow from "../../../../shared/Icons/LeftArrow.jsx"; import RightArrow from "../../../../shared/Icons/RightArrow.jsx"; -const PaginationTable = ({ currentPage, totalPages, handlePageClick }) => { +const PaginationTable = ({ + currentPage, + displayButtons = false, + totalPages, + handlePageClick, +}) => { const renderPaginationButtons = () => { const buttons = []; const firstPage = 1; @@ -59,28 +64,33 @@ const PaginationTable = ({ currentPage, totalPages, handlePageClick }) => { }; return (
- + {displayButtons && ( + + )} {renderPaginationButtons()} - + {displayButtons && ( + + )}
); }; PaginationTable.propTypes = { currentPage: PropTypes.number.isRequired, + displayButtons: PropTypes.bool, handlePageClick: PropTypes.func.isRequired, totalPages: PropTypes.string.isRequired, }; diff --git a/src/client/src/components/SearchAwesomeTable/Pager.js b/src/client/src/components/SearchAwesomeTable/Pager.js deleted file mode 100644 index 5afacde1..00000000 --- a/src/client/src/components/SearchAwesomeTable/Pager.js +++ /dev/null @@ -1,71 +0,0 @@ -import PropTypes from "prop-types"; -import React from "react"; - -const Pager = ({ currentPage, max, handlePageChange }) => { - const renderPaginationButtons = () => { - const buttons = []; - const firstPage = 1; - const lastPage = max; - - const addPageButton = (page) => { - if (!buttons.some((button) => button.key === page.toString())) { - buttons.push( - - ); - } - }; - - if (currentPage > 1) { - addPageButton(firstPage); - } - - if (currentPage > 4 && lastPage > 5) { - buttons.push( - - ); - } - - const startPage = Math.max(currentPage - 2, 1); - const endPage = Math.min(startPage + 4, lastPage); - - for (let page = startPage; page <= endPage; page++) { - addPageButton(page); - } - - if (currentPage < lastPage - 3 && lastPage > 5) { - buttons.push( - - ); - } - - if (currentPage < lastPage && lastPage > 5) { - addPageButton(lastPage); - } - - return buttons; - }; - - return ( -
-
{renderPaginationButtons()}
-
- ); -}; - -Pager.propTypes = { - currentPage: PropTypes.number.isRequired, - handlePageChange: PropTypes.func.isRequired, - max: PropTypes.number.isRequired, -}; - -export default Pager; diff --git a/src/client/src/components/SearchAwesomeTable/SearchAwesomeTable.js b/src/client/src/components/SearchAwesomeTable/SearchAwesomeTable.js index 58c62995..45f96032 100644 --- a/src/client/src/components/SearchAwesomeTable/SearchAwesomeTable.js +++ b/src/client/src/components/SearchAwesomeTable/SearchAwesomeTable.js @@ -5,10 +5,10 @@ import PropTypes from "prop-types"; import React from "react"; import { withRouter } from "react-router"; +import PaginationTable from "../DataSheets/Sections/SharedComponents/PaginationTable/PaginationTable.jsx"; import LeftArrow from "../shared/Icons/LeftArrow.jsx"; import RightArrow from "../shared/Icons/RightArrow.jsx"; import LoadSpinner from "../shared/LoadSpinner"; -import Pager from "./Pager"; const SearchAwesomeTable = ({ showPagination = false, @@ -83,10 +83,10 @@ const SearchAwesomeTable = ({ {prevText} -