Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reset table selection when navigating away from index page #9140

Merged
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { useEffect, useState } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
import {
matchPath,
useLocation,
useNavigate,
useParams,
} from 'react-router-dom';
import { useRecoilValue } from 'recoil';

import {
Expand All @@ -8,6 +13,8 @@ import {
} from '@/analytics/hooks/useEventTracker';
import { useRequestFreshCaptchaToken } from '@/captcha/hooks/useRequestFreshCaptchaToken';
import { isCaptchaScriptLoadedState } from '@/captcha/states/isCaptchaScriptLoadedState';
import { CoreObjectNamePlural } from '@/object-metadata/types/CoreObjectNamePlural';
import { useResetTableRowSelection } from '@/object-record/record-table/hooks/internal/useResetTableRowSelection';
import { TableHotkeyScope } from '@/object-record/record-table/types/TableHotkeyScope';
import { AppBasePath } from '@/types/AppBasePath';
import { AppPath } from '@/types/AppPath';
Expand Down Expand Up @@ -38,6 +45,11 @@ export const PageChangeEffect = () => {

const eventTracker = useEventTracker();

const objectNamePlural =
samyakpiya marked this conversation as resolved.
Show resolved Hide resolved
useParams().objectNamePlural ?? CoreObjectNamePlural.Person;

const resetTableSelections = useResetTableRowSelection(objectNamePlural);

useEffect(() => {
cleanRecoilState();
}, [cleanRecoilState]);
Expand All @@ -56,6 +68,17 @@ export const PageChangeEffect = () => {
}
}, [navigate, pageChangeEffectNavigateLocation]);

useEffect(() => {
const isLeavingRecordIndexPage = !!matchPath(
AppPath.RecordIndexPage,
previousLocation,
);

if (isLeavingRecordIndexPage) {
resetTableSelections();
}
}, [isMatchingLocation, previousLocation, resetTableSelections]);

useEffect(() => {
switch (true) {
case isMatchingLocation(AppPath.RecordIndexPage): {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export const RecordIndexPage = () => {
<RecordIndexContainerContextStoreObjectMetadataEffect />
<RecordIndexContainerContextStoreNumberOfSelectedRecordsEffect />
<MainContextStoreComponentInstanceIdSetterEffect />

<RecordIndexContainer />
</StyledIndexContainer>
</PageBody>
Expand Down
Loading