Skip to content

Commit

Permalink
Merge pull request #415 from MTES-MCT/fix/refresh-controls-list
Browse files Browse the repository at this point in the history
Fix/refresh controls list
  • Loading branch information
tristan-gueguen authored Oct 2, 2023
2 parents 8e0b945 + d36f81f commit 33de22d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
11 changes: 9 additions & 2 deletions web/controller/components/history/ControllerHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ export function ControllerHistory() {
const [period, setPeriod] = React.useState("day");
const [controls, loadControls, loadingControls] = useLoadControls();

React.useEffect(() => {
const _loadControls = () => {
loadControls({
controllerId: controllerUserInfo.id,
...controlFilters
});
};

React.useEffect(() => {
_loadControls();
}, [controlFilters]);
return [
<Header key={0} />,
Expand All @@ -62,7 +66,10 @@ export function ControllerHistory() {
<ControllerControlDrawer
controlId={controlOnFocus?.id}
controlType={controlOnFocus?.type}
onClose={() => setControlOnFocus(null)}
onClose={() => {
_loadControls();
setControlOnFocus(null);
}}
/>
<Typography sx={{ typography: { xs: "h3", sm: "h1" } }}>
Historique des contrôles
Expand Down
11 changes: 9 additions & 2 deletions web/controller/components/home/ControllerHome.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,16 @@ export function ControllerHome() {

const [controlsType, setControlsType] = React.useState("");

React.useEffect(() => {
const _loadControls = () => {
loadControls({
controllerId: controllerUserInfo.id,
limit: 10,
controlsType
});
};

React.useEffect(() => {
_loadControls();
}, [controlsType]);

React.useEffect(() => {
Expand All @@ -99,7 +103,10 @@ export function ControllerHome() {
<ControllerControlDrawer
controlId={controlOnFocus?.id}
controlType={controlOnFocus?.type}
onClose={() => setControlOnFocus(null)}
onClose={() => {
_loadControls();
setControlOnFocus(null);
}}
/>
<ControllerControlNewNoLic
isOpen={openNewNoLic}
Expand Down
15 changes: 14 additions & 1 deletion web/controller/components/list/ControlsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export function ControlsList({
clickOnRow,
period = "day"
}) {
const [expandedDates, setExpandedDates] = React.useState([]);
const controlsByPeriod = useMemo(() => {
const controlsGroupedByPeriod = groupBy(controls, control =>
getGroupByKey(new Date(control.creationTime * 1000), period)
Expand Down Expand Up @@ -103,7 +104,19 @@ export function ControlsList({
/>
) : (
controlsByPeriod.map(histo => (
<Accordion key={`entries_${histo.date}`} disableGutters elevation={0}>
<Accordion
key={`entries_${histo.date}`}
disableGutters
elevation={0}
expanded={expandedDates.includes(histo.date)}
onChange={(_, expanded) =>
setExpandedDates(prev =>
expanded
? [...prev, histo.date]
: prev.filter(item => item !== histo.date)
)
}
>
<AccordionSummary
aria-controls="panel1d-content"
id="panel1d-header"
Expand Down

0 comments on commit 33de22d

Please sign in to comment.