diff --git a/CHANGELOG.md b/CHANGELOG.md index 85a306bd..b29e2922 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +# [27.103.0](https://github.com/SocialGouv/fce/compare/v27.102.0...v27.103.0) (2024-08-09) + + +### Features + +* add DDPP for home page ([#352](https://github.com/SocialGouv/fce/issues/352)) ([c97e947](https://github.com/SocialGouv/fce/commit/c97e94702c04e6dd23d8dd91cd54a5ef990fe06c)) + +# [27.102.0](https://github.com/SocialGouv/fce/compare/v27.101.7...v27.102.0) (2024-08-08) + + +### Features + +* Ajout des dates de contrôles du pôle C au niveau de la fiche établissement ([#342](https://github.com/SocialGouv/fce/issues/342)) ([6e4c86e](https://github.com/SocialGouv/fce/commit/6e4c86eec9cb2c5981359beb285d8119896756d9)) + ## [27.101.7](https://github.com/SocialGouv/fce/compare/v27.101.6...v27.101.7) (2024-07-04) diff --git a/package.json b/package.json index ffe92fec..32b577a2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fce", - "version": "27.101.7", + "version": "27.103.0", "description": "", "author": "commit42", "private": true, diff --git a/src/client/src/components/DataSheets/Sections/Enterprise/Direccte/Interactions.gql.js b/src/client/src/components/DataSheets/Sections/Enterprise/Direccte/Interactions.gql.js index be30d166..f1ce8629 100644 --- a/src/client/src/components/DataSheets/Sections/Enterprise/Direccte/Interactions.gql.js +++ b/src/client/src/components/DataSheets/Sections/Enterprise/Direccte/Interactions.gql.js @@ -36,10 +36,10 @@ const interactionsQuery = gql` libellecommune2etablissement } } - interactions_C: fce_interactions_pole_c(where: { siren: { _eq: $siren } }) { - siret - date - unite + interactions_C: fce_interactions_pole_c(where: { SIRNE: { _eq: $siren } }) { + siret: SIRET + date: DATE_DERNIER_CONTROLE + unite: LIB_UC etablissement: interactions_pole_c_siret { etatadministratifetablissement siret diff --git a/src/client/src/components/DataSheets/Sections/Establishment/Dashboard/Dashboard.gql.js b/src/client/src/components/DataSheets/Sections/Establishment/Dashboard/Dashboard.gql.js index 290f3bb4..059dbe76 100644 --- a/src/client/src/components/DataSheets/Sections/Establishment/Dashboard/Dashboard.gql.js +++ b/src/client/src/components/DataSheets/Sections/Establishment/Dashboard/Dashboard.gql.js @@ -43,11 +43,11 @@ const dashboardQuery = gql` siret } fce_interactions_pole_c( - where: { siret: { _eq: $siret } } - order_by: { mois: desc } + where: { SIRET: { _eq: $siret } } + order_by: { DATE_DERNIER_CONTROLE: desc } limit: 1 ) { - date + date: DATE_DERNIER_CONTROLE } fce_interactions_pole_t( where: { siret: { _eq: $siret } } diff --git a/src/client/src/components/DataSheets/Sections/Establishment/Direccte/Controles.gql.js b/src/client/src/components/DataSheets/Sections/Establishment/Direccte/Controles.gql.js index 59c974c7..107dec42 100644 --- a/src/client/src/components/DataSheets/Sections/Establishment/Direccte/Controles.gql.js +++ b/src/client/src/components/DataSheets/Sections/Establishment/Direccte/Controles.gql.js @@ -6,20 +6,20 @@ import { mapQueryResult } from "../../../../../utils/graphql/graphql"; import { // normalizeInteractions3E, // normalizeInteractions3ESRC, - // normalizeInteractionsC, + normalizeInteractionsC, normalizeInteractionsT, } from "../../../../../utils/interactions/interactions"; const controlesQuery = gql` query getControles($siret: String!) { - # fce_interactions_pole_c(where: { siret: { _eq: $siret } }) { - # unite - # siret - # date - # interactions_pole_c_siret { - # denominationusuelleetablissement - # } - # } + fce_interactions_pole_c(where: { SIRET: { _eq: $siret } }) { + siret: SIRET + date: DATE_DERNIER_CONTROLE + unite: LIB_UC + interactions_pole_c_siret { + denominationusuelleetablissement + } + } fce_interactions_pole_t(where: { siret: { _eq: $siret } }) { date intervenant @@ -49,14 +49,14 @@ const controlesQuery = gql` const normalizeResponsesToInteraction = ({ // fce_interactions_pole_3e, // fce_interactions_pole_3e_src, - // fce_interactions_pole_c, + fce_interactions_pole_c, fce_interactions_pole_t, }) => ({ // interactions_pole_3e: normalizeInteractions3E(fce_interactions_pole_3e), // interactions_pole_3e_src: normalizeInteractions3ESRC( // fce_interactions_pole_3e_src // ), - // interactions_pole_c: normalizeInteractionsC(fce_interactions_pole_c), + interactions_pole_c: normalizeInteractionsC(fce_interactions_pole_c), interactions_pole_t: normalizeInteractionsT(fce_interactions_pole_t), }); diff --git a/src/client/src/components/HomePage/homePage.scss b/src/client/src/components/HomePage/homePage.scss index 1ca8cf9b..8eca913d 100644 --- a/src/client/src/components/HomePage/homePage.scss +++ b/src/client/src/components/HomePage/homePage.scss @@ -78,7 +78,7 @@ &__action-links-container { flex-wrap: wrap; background-color: transparent; - padding: $spacing-2 $spacing-6; + padding: $spacing-2 $spacing-4; font-family: $marianne; @media (max-width: 600px) { padding: $spacing-2 !important; diff --git a/src/client/src/components/HomePage/sections.js b/src/client/src/components/HomePage/sections.js index 205d82b1..7d3345c2 100644 --- a/src/client/src/components/HomePage/sections.js +++ b/src/client/src/components/HomePage/sections.js @@ -99,7 +99,7 @@ export const Summary = () => (
- Je suis un agent en DREETS ou en DDETS ​ + Je suis un agent en DREETS, en DDETS ou en DDPP{" "}
@@ -120,7 +120,7 @@ export const Summary = () => (
- Je suis en agent en DDETS, nouvel utilisateur de FCE​ + Je suis en agent en DDETS ou en DDPP, nouvel utilisateur de FCE
diff --git a/src/client/src/containers/Search/Search.js b/src/client/src/containers/Search/Search.js index 2102c2af..0c3541e4 100644 --- a/src/client/src/containers/Search/Search.js +++ b/src/client/src/containers/Search/Search.js @@ -2,6 +2,7 @@ import { groupBy, omit } from "lodash"; import { prop } from "lodash/fp"; import moment from "moment"; import React, { useEffect } from "react"; +import { useSelector } from "react-redux"; import SearchView from "../../components/Search"; import Http from "../../services/Http"; @@ -44,6 +45,12 @@ const formatLocationFilter = (filters, sortDirection, sortField) => { const Search = () => { const [searchQuery, setSearchQuery] = useSearchTerms(); const [searchPage, setSearchPage] = useSearchPage(); + const sortFieldFromStore = useSelector( + (state) => state?.search?.sort?.sortField + ); + const sortOrderFromStore = useSelector( + (state) => state?.search?.sort?.sortOrder + ); const { filters, addFilter, removeFilter, removeFilters } = useSearchFilters(); @@ -70,7 +77,11 @@ const Search = () => { const response = await Http.get("/downloadXlsx", { params: { q: trimmedQuery, - ...formatLocationFilter(filters), + ...formatLocationFilter( + filters, + sortOrderFromStore != null ? sortDirection : null, + sortFieldFromStore != null ? sortField : null + ), }, responseType: "blob", }); @@ -95,7 +106,11 @@ const Search = () => { setSearchPage(nextCurrentPage); makeQuery(searchQuery, { page: { current: nextCurrentPage - 1, size: PAGE_SIZE }, - params: formatLocationFilter(filters), + params: formatLocationFilter( + filters, + sortOrderFromStore != null ? sortDirection : null, + sortFieldFromStore != null ? sortField : null + ), }); }; @@ -103,7 +118,11 @@ const Search = () => { setSearchPage(1); makeQuery(searchQuery, { page: { current: 0, size: PAGE_SIZE }, - params: formatLocationFilter(filters, sortDirection, sortField), + params: formatLocationFilter( + filters, + sortOrderFromStore != null ? sortDirection : null, + sortFieldFromStore != null ? sortField : null + ), }); }; diff --git a/src/client/src/services/Store/actions/search.js b/src/client/src/services/Store/actions/search.js index fc9f5e19..9cde6ef9 100644 --- a/src/client/src/services/Store/actions/search.js +++ b/src/client/src/services/Store/actions/search.js @@ -6,6 +6,18 @@ export const setSearchTerm = (term) => (dispatch) => { type: types.SET_SEARCH_TERM, }); }; +export const setSearchSortOrder = (sortOrder) => (dispatch) => { + dispatch({ + sortOrder, + type: types.SET_SEARCH_SORT_ORDER, + }); +}; +export const setSearchSortField = (sortField) => (dispatch) => { + dispatch({ + sortField, + type: types.SET_SEARCH_SORT_FIELD, + }); +}; export const setSearchPage = (page) => (dispatch) => { dispatch({ diff --git a/src/client/src/services/Store/constants/ActionTypes.js b/src/client/src/services/Store/constants/ActionTypes.js index 2a8fd2fd..e0654210 100644 --- a/src/client/src/services/Store/constants/ActionTypes.js +++ b/src/client/src/services/Store/constants/ActionTypes.js @@ -1,4 +1,6 @@ export const SET_SEARCH_TERM = "SET_SEARCH_TERM"; +export const SET_SEARCH_SORT_ORDER = "SET_SEARCH_SORT_ORDER"; +export const SET_SEARCH_SORT_FIELD = "SET_SEARCH_SORT_FIELD"; export const SET_SEARCH_PAGE = "SET_SEARCH_PAGE"; export const SET_SEARCH_FILTERS = "SET_SEARCH_FILTERS"; export const SET_SEARCH_SORT = "SET_SEARCH_SORT"; diff --git a/src/client/src/services/Store/hooks/search.js b/src/client/src/services/Store/hooks/search.js index 5464c867..95560a8d 100644 --- a/src/client/src/services/Store/hooks/search.js +++ b/src/client/src/services/Store/hooks/search.js @@ -8,6 +8,8 @@ import { setSearchFilters, setSearchPage as setSearchPageAction, setSearchResults, + setSearchSortField as setSearchSortFieldAction, + setSearchSortOrder as setSearchSortOrderAction, setSearchTerm as setSearchTermAction, } from "../actions"; @@ -23,6 +25,18 @@ export const useSearchTerms = () => { return [searchTerm, setSearchTerm]; }; +export const useSearchSortTerms = () => { + const dispatch = useDispatch(); + const searchSortTerm = useSelector((state) => getSearchState(state).sort); + const setSearchSortOrder = (term) => { + dispatch(setSearchSortOrderAction(term)); + }; + const setSearchSortField = (term) => { + dispatch(setSearchSortFieldAction(term)); + }; + + return [searchSortTerm, setSearchSortOrder, setSearchSortField]; +}; export const useSearchPage = () => { const dispatch = useDispatch(); @@ -39,12 +53,12 @@ export const useSearchFilters = () => { const dispatch = useDispatch(); const savedFilters = useSelector((state) => getSearchState(state).filters); // cache busting mechanism + const validFilters = savedFilters.etats ? savedFilters : { etats: ["A"], }; - const addFilter = (key, value) => { dispatch(setSearchFilters({ ...savedFilters, [key]: value })); }; diff --git a/src/client/src/services/Store/reducers/search.js b/src/client/src/services/Store/reducers/search.js index b93a1385..01f8554d 100644 --- a/src/client/src/services/Store/reducers/search.js +++ b/src/client/src/services/Store/reducers/search.js @@ -4,12 +4,16 @@ import { SET_SEARCH_PAGE, SET_SEARCH_RESULTS, SET_SEARCH_SORT, + SET_SEARCH_SORT_FIELD, + SET_SEARCH_SORT_ORDER, SET_SEARCH_TERM, } from "../constants/ActionTypes"; const initialState = { filters: { etats: ["A"], + sortField: null, + sortOrder: null, }, page: 1, results: { @@ -19,6 +23,8 @@ const initialState = { sort: { ascDirection: false, field: null, + sortField: null, + sortOrder: null, }, term: null, }; @@ -30,6 +36,22 @@ const search = (state = initialState, action) => { ...state, term: action.term, }; + case SET_SEARCH_SORT_ORDER: + return { + ...state, + sort: { + ...state.sort, + sortOrder: action.sortOrder, + }, + }; + case SET_SEARCH_SORT_FIELD: + return { + ...state, + sort: { + ...state.sort, + sortField: action.sortField, + }, + }; case SET_SEARCH_PAGE: return { diff --git a/src/client/src/utils/interactions/interactions.js b/src/client/src/utils/interactions/interactions.js index ac525483..ce2bd2d4 100644 --- a/src/client/src/utils/interactions/interactions.js +++ b/src/client/src/utils/interactions/interactions.js @@ -12,7 +12,7 @@ const interactionsSources = { interactions_pole_3e: "EOS", interactions_pole_3e_src: "MDF", interactions_pole_c: "SORA", - interactions_pole_t: "Wiki'T", + interactions_pole_t: "interactions_pole_t", }; export const getInteractionSource = (pole) => { diff --git a/src/client/src/utils/search-table/hooks.js b/src/client/src/utils/search-table/hooks.js index eac3087b..10ddb564 100644 --- a/src/client/src/utils/search-table/hooks.js +++ b/src/client/src/utils/search-table/hooks.js @@ -1,5 +1,8 @@ import { omit } from "lodash"; -import { useState } from "react"; +import { useEffect, useState } from "react"; +import { useSelector } from "react-redux"; + +import { useSearchSortTerms } from "../../services/Store/hooks/search"; export const useFilters = (defaultValue) => { const [filters, setFilters] = useState(defaultValue); @@ -20,25 +23,45 @@ export const useFilters = (defaultValue) => { }; export const useSort = () => { - const [sortDirection, setSortDirection] = useState("desc"); - const [sortField, setSortField] = useState("siret"); + const [setSearchSortOrder, setSearchSortField] = useSearchSortTerms(); + const sortFieldFromStore = useSelector((state) => state?.sort?.sortField); + const sortOrderFromStore = useSelector((state) => state?.sort?.sortOrder); + const [sortDirection, setSortDirection] = useState(sortOrderFromStore); + const [sortField, setSortField] = useState(sortFieldFromStore); const { addFilter } = useFilters(); + + useEffect(() => { + if (sortFieldFromStore == null && sortOrderFromStore == null) { + setSortField(sortFieldFromStore); + setSortDirection(sortOrderFromStore); + } + }, [sortFieldFromStore, sortOrderFromStore]); + const toggleSortField = (field) => { if (field !== sortField) { - setSortDirection("desc"); + setSearchSortField(field); setSortField(field); addFilter("sortField", field); addFilter("sortDirection", "desc"); - + setSortDirection("desc"); + setSearchSortOrder("desc"); return; } if (sortDirection === "desc") { setSortDirection("asc"); + setSearchSortOrder("asc"); addFilter("sortDirection", "asc"); return; } + if (sortDirection === "asc") { + setSortDirection("desc"); + setSearchSortOrder("desc"); + addFilter("sortDirection", "desc"); + + return; + } setSortField(null); }; diff --git a/src/server/src/utils/elastic.js b/src/server/src/utils/elastic.js index 7e21fe01..f0115a42 100644 --- a/src/server/src/utils/elastic.js +++ b/src/server/src/utils/elastic.js @@ -1,5 +1,4 @@ import config from "config"; - import { Client } from "@elastic/elasticsearch"; import codesNaf from "@socialgouv/codes-naf"; @@ -22,10 +21,7 @@ const filtersFieldMap = { const getCodeNafLibelle = (code) => codesNafLabelIndex.get( - code - .replace(/[A-z]+$/, "") - .padEnd(5, "0") - .slice(0, 5) + code.replace(/[A-z]+$/, "").padEnd(5, "0").slice(0, 5) ); const codesNafLabelIndex = codesNaf.reduce( @@ -45,27 +41,14 @@ const makeQuery = ({ query, siege, dirigeant, ...filters }) => { query: { bool: { must: [ - { - match: { - "dirigeants.nom": { - query: dirigeant.nom, - }, - }, - }, - { - match: { - "dirigeants.prenom": { - query: dirigeant.prenom, - }, - }, - }, + { match: { "dirigeants.nom": dirigeant.nom } }, + { match: { "dirigeants.prenom": dirigeant.prenom } }, ], }, }, }, }); - } - if (dirigeant.nom && !dirigeant.prenom) { + } else if (dirigeant.nom) { dirigeantConditions.push({ nested: { path: "dirigeants", @@ -74,8 +57,7 @@ const makeQuery = ({ query, siege, dirigeant, ...filters }) => { }, }, }); - } - if (dirigeant.prenom && !dirigeant.nom) { + } else if (dirigeant.prenom) { dirigeantConditions.push({ nested: { path: "dirigeants", @@ -86,6 +68,7 @@ const makeQuery = ({ query, siege, dirigeant, ...filters }) => { }); } } + return { ...(query ? { min_score: 20 } : {}), query: { @@ -110,7 +93,6 @@ const makeQuery = ({ query, siege, dirigeant, ...filters }) => { ] : [] ), - ...(query ? [ { @@ -129,7 +111,6 @@ const makeQuery = ({ query, siege, dirigeant, ...filters }) => { boost: 100, }, }, - { multi_match: { query, @@ -141,7 +122,6 @@ const makeQuery = ({ query, siege, dirigeant, ...filters }) => { minimum_should_match: "100%", }, }, - ...(siretOrSirenQuery ? [ { @@ -221,8 +201,8 @@ export const getElasticQueryParams = (req) => { const dirigeant = req.query["dirigeant"] ? JSON.parse(req.query["dirigeant"]) : null; - const sortField = req.query["sortField"] || "etatAdministratifEtablissement"; - const sortOrder = req.query["sortOrder"] || "asc"; // Default sorting order + const sortField = req.query["sortField"]; + const sortOrder = req.query["sortOrder"]; let etats = req.query["etats"] || []; const siege = (req.query["siege"] || "").trim(); @@ -248,15 +228,18 @@ export const getElasticQueryParams = (req) => { }; export const requestElastic = async (params, { from, size }) => { - console.log(params); const body = makeQuery(params); - body.sort = [ - { - [params.sortField]: { - order: params.sortOrder, + + // Ajouter le tri après avoir construit la requête de filtrage + if (params.sortField && params.sortOrder) { + body.sort = [ + { + [params.sortField]: { + order: params.sortOrder, + }, }, - }, - ]; + ]; + } const { body: {