Skip to content

Commit

Permalink
feat: sort search result
Browse files Browse the repository at this point in the history
  • Loading branch information
ImenOuidou committed Aug 26, 2024
2 parents fbda6fa + b0d6978 commit ce2a6e1
Show file tree
Hide file tree
Showing 15 changed files with 155 additions and 63 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fce",
"version": "27.101.7",
"version": "27.103.0",
"description": "",
"author": "commit42",
"private": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
});

Expand Down
2 changes: 1 addition & 1 deletion src/client/src/components/HomePage/homePage.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/client/src/components/HomePage/sections.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const Summary = () => (
<div className="column is-5">
<div className="content">
<div className="text-title">
Je suis un agent en DREETS ou en DDETS ​
Je suis un agent en DREETS, en DDETS ou en DDPP{" "}
</div>

<LoginLink />
Expand All @@ -120,7 +120,7 @@ export const Summary = () => (
<div className="column is-5">
<div className="content">
<div className="text-title">
Je suis en agent en DDETS, nouvel utilisateur de FCE
Je suis en agent en DDETS ou en DDPP, nouvel utilisateur de FCE
</div>
<RequestAccessLink />
<div className="text-explicatif">
Expand Down
25 changes: 22 additions & 3 deletions src/client/src/containers/Search/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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();
Expand All @@ -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",
});
Expand All @@ -95,15 +106,23 @@ 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
),
});
};

const onSearch = () => {
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
),
});
};

Expand Down
12 changes: 12 additions & 0 deletions src/client/src/services/Store/actions/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 2 additions & 0 deletions src/client/src/services/Store/constants/ActionTypes.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
16 changes: 15 additions & 1 deletion src/client/src/services/Store/hooks/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
setSearchFilters,
setSearchPage as setSearchPageAction,
setSearchResults,
setSearchSortField as setSearchSortFieldAction,
setSearchSortOrder as setSearchSortOrderAction,
setSearchTerm as setSearchTermAction,
} from "../actions";

Expand All @@ -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();
Expand All @@ -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 }));
};
Expand Down
22 changes: 22 additions & 0 deletions src/client/src/services/Store/reducers/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -19,6 +23,8 @@ const initialState = {
sort: {
ascDirection: false,
field: null,
sortField: null,
sortOrder: null,
},
term: null,
};
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/client/src/utils/interactions/interactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
33 changes: 28 additions & 5 deletions src/client/src/utils/search-table/hooks.js
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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);
};
Expand Down
Loading

0 comments on commit ce2a6e1

Please sign in to comment.