Skip to content

Commit

Permalink
Merge pull request #54865 from ishpaul777/fix/tooltip-blockers
Browse files Browse the repository at this point in the history
[CP Staging] Add loading state to ProductTrainingContextProvider

(cherry picked from commit 8f3fe5f)

(CP triggered by mountiny)
  • Loading branch information
Beamanator authored and OSBotify committed Jan 7, 2025
1 parent 2383509 commit 6942d54
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/components/ProductTrainingContext/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ const ProductTrainingContext = createContext<ProductTrainingContextType>({
});

function ProductTrainingContextProvider({children}: ChildrenProps) {
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {initialValue: true});
const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRYNEWDOT);
const hasBeenAddedToNudgeMigration = !!tryNewDot?.nudgeMigration?.timestamp;
const [isOnboardingCompleted = true, isOnboardingCompletedMetadata] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {
selector: hasCompletedGuidedSetupFlowSelector,
});

const [dismissedProductTraining] = useOnyx(ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING);
const {shouldUseNarrowLayout} = useResponsiveLayout();

Expand Down Expand Up @@ -77,7 +79,7 @@ function ProductTrainingContextProvider({children}: ChildrenProps) {

const shouldTooltipBeVisible = useCallback(
(tooltipName: ProductTrainingTooltipName) => {
if (isLoadingOnyxValue(isOnboardingCompletedMetadata)) {
if (isLoadingOnyxValue(isOnboardingCompletedMetadata) || isLoadingApp) {
return false;
}

Expand Down Expand Up @@ -105,7 +107,7 @@ function ProductTrainingContextProvider({children}: ChildrenProps) {
shouldUseNarrowLayout,
});
},
[dismissedProductTraining, hasBeenAddedToNudgeMigration, isOnboardingCompleted, isOnboardingCompletedMetadata, shouldUseNarrowLayout, isModalVisible],
[dismissedProductTraining, hasBeenAddedToNudgeMigration, isOnboardingCompleted, isOnboardingCompletedMetadata, shouldUseNarrowLayout, isModalVisible, isLoadingApp],
);

const registerTooltip = useCallback(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {useIsFocused} from '@react-navigation/native';
import lodashDebounce from 'lodash/debounce';
import noop from 'lodash/noop';
import React, {memo, useCallback, useEffect, useMemo, useRef, useState} from 'react';
Expand Down Expand Up @@ -135,10 +136,11 @@ function ReportActionCompose({
const personalDetails = usePersonalDetails();
const [blockedFromConcierge] = useOnyx(ONYXKEYS.NVP_BLOCKED_FROM_CONCIERGE);
const [shouldShowComposeInput = true] = useOnyx(ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT);
const isScreenFocused = useIsFocused();

const {renderProductTrainingTooltip, hideProductTrainingTooltip, shouldShowProductTrainingTooltip} = useProductTrainingContext(
CONST.PRODUCT_TRAINING_TOOLTIP_NAMES.WORKSAPCE_CHAT_CREATE,
shouldShowEducationalTooltip,
shouldShowEducationalTooltip && isScreenFocused,
);

/**
Expand Down
13 changes: 13 additions & 0 deletions tests/ui/components/ProductTrainingContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe('ProductTrainingContextProvider', () => {
// Set up test environment before each test
wrapOnyxWithWaitForBatchedUpdates(Onyx);
Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false});
Onyx.merge(ONYXKEYS.IS_LOADING_APP, false);
signUpWithTestUser();
});

Expand All @@ -61,6 +62,18 @@ describe('ProductTrainingContextProvider', () => {
mockUseResponsiveLayout.mockReturnValue({...DEFAULT_USE_RESPONSIVE_LAYOUT_VALUE, shouldUseNarrowLayout: false});

describe('Basic Tooltip Registration', () => {
it('should not register tooltips when app is loading', async () => {
// When app is loading
Onyx.merge(ONYXKEYS.IS_LOADING_APP, true);
await waitForBatchedUpdatesWithAct();

const testTooltip = CONST.PRODUCT_TRAINING_TOOLTIP_NAMES.GLOBAL_CREATE_TOOLTIP;
const {result} = renderHook(() => useProductTrainingContext(testTooltip), {wrapper});

// Then tooltip should not show
expect(result.current.shouldShowProductTrainingTooltip).toBe(false);
});

it('should not register tooltips when onboarding is not completed', async () => {
// When onboarding is not completed
Onyx.merge(ONYXKEYS.NVP_ONBOARDING, {hasCompletedGuidedSetupFlow: false});
Expand Down

0 comments on commit 6942d54

Please sign in to comment.