- 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: {