Skip to content

Commit

Permalink
Merge pull request #50226 from bernhardoj/fix/50212-categories-settin…
Browse files Browse the repository at this point in the history
…gs-show-loading-when-open

Fix categories settings page always show loader when open the page
  • Loading branch information
jasperhuangg authored Oct 4, 2024
2 parents 063b8e6 + f13df4c commit 98da3ce
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/pages/workspace/withPolicyConnections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import usePrevious from '@hooks/usePrevious';
import {openPolicyAccountingPage} from '@libs/actions/PolicyConnections';
import ONYXKEYS from '@src/ONYXKEYS';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';
import withPolicy from './withPolicy';
import type {WithPolicyProps} from './withPolicy';

Expand All @@ -28,11 +29,10 @@ type WithPolicyConnectionsProps = WithPolicyProps & {
function withPolicyConnections<TProps extends WithPolicyConnectionsProps>(WrappedComponent: ComponentType<TProps>, shouldBlockView = true) {
function WithPolicyConnections(props: TProps) {
const {isOffline} = useNetwork();
const [hasConnectionsDataBeenFetched] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_HAS_CONNECTIONS_DATA_BEEN_FETCHED}${props.policy?.id ?? '-1'}`, {
initWithStoredValues: false,
});
const [hasConnectionsDataBeenFetched, hasConnectionsDataBeenFetchedResult] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_HAS_CONNECTIONS_DATA_BEEN_FETCHED}${props.policy?.id ?? '-1'}`);
const isOnyxDataLoading = isLoadingOnyxValue(hasConnectionsDataBeenFetchedResult);
const isConnectionDataFetchNeeded =
!isOffline && !!props.policy && (!!props.policy.areConnectionsEnabled || !isEmptyObject(props.policy.connections)) && !hasConnectionsDataBeenFetched;
!isOnyxDataLoading && !isOffline && !!props.policy && (!!props.policy.areConnectionsEnabled || !isEmptyObject(props.policy.connections)) && !hasConnectionsDataBeenFetched;

const [isFetchingData, setIsFetchingData] = useState(false);

Expand All @@ -55,7 +55,7 @@ function withPolicyConnections<TProps extends WithPolicyConnectionsProps>(Wrappe
openPolicyAccountingPage(props.policy.id);
}, [props.policy?.id, isConnectionDataFetchNeeded]);

if ((isConnectionDataFetchNeeded || isFetchingData) && shouldBlockView) {
if ((isConnectionDataFetchNeeded || isFetchingData || isOnyxDataLoading) && shouldBlockView) {
return <FullScreenLoadingIndicator />;
}

Expand Down

0 comments on commit 98da3ce

Please sign in to comment.