Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into VickyStash/feature/51331-poor-con…
Browse files Browse the repository at this point in the history
…nection-simulation
  • Loading branch information
VickyStash committed Dec 16, 2024
2 parents 53b39c5 + b8579b1 commit da8a017
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5112,7 +5112,7 @@ const translations = {
tryAgain: 'Try again',
},
systemMessage: {
mergedWithCashTransaction: 'matched a receipt to this transaction.',
mergedWithCashTransaction: 'matched a receipt to this transaction',
},
subscription: {
authenticatePaymentCard: 'Authenticate payment card',
Expand Down
2 changes: 1 addition & 1 deletion src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5627,7 +5627,7 @@ const translations = {
tryAgain: 'Inténtalo de nuevo',
},
systemMessage: {
mergedWithCashTransaction: 'encontró un recibo para esta transacción.',
mergedWithCashTransaction: 'encontró un recibo para esta transacción',
},
subscription: {
authenticatePaymentCard: 'Autenticar tarjeta de pago',
Expand Down
10 changes: 4 additions & 6 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,11 @@ Onyx.connect({

/**
* Filter out the active policies, which will exclude policies with pending deletion
* and policies the current user doesn't belong to.
* These are policies that we can use to create reports with in NewDot.
*/
function getActivePolicies(policies: OnyxCollection<Policy> | null, currentUserLogin: string | undefined): Policy[] {
function getActivePolicies(policies: OnyxCollection<Policy> | null): Policy[] {
return Object.values(policies ?? {}).filter<Policy>(
(policy): policy is Policy =>
!!policy && policy.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && !!policy.name && !!policy.id && !!getPolicyRole(policy, currentUserLogin),
(policy): policy is Policy => !!policy && policy.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && !!policy.name && !!policy.id,
);
}
/**
Expand Down Expand Up @@ -638,7 +636,7 @@ function getPolicy(policyID: string | undefined): OnyxEntry<Policy> {

/** Return active policies where current user is an admin */
function getActiveAdminWorkspaces(policies: OnyxCollection<Policy> | null, currentUserLogin: string | undefined): Policy[] {
const activePolicies = getActivePolicies(policies, currentUserLogin);
const activePolicies = getActivePolicies(policies);
return activePolicies.filter((policy) => shouldShowPolicy(policy, NetworkStore.isOffline(), currentUserLogin) && isPolicyAdmin(policy, currentUserLogin));
}

Expand All @@ -654,7 +652,7 @@ function canSendInvoice(policies: OnyxCollection<Policy> | null, currentUserLogi
}

function hasWorkspaceWithInvoices(currentUserLogin: string | undefined): boolean {
const activePolicies = getActivePolicies(allPolicies, currentUserLogin);
const activePolicies = getActivePolicies(allPolicies);
return activePolicies.some((policy) => shouldShowPolicy(policy, NetworkStore.isOffline(), currentUserLogin) && policy.areInvoicesEnabled);
}

Expand Down
17 changes: 15 additions & 2 deletions src/libs/navigateAfterOnboarding.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import ROUTES from '@src/ROUTES';
import * as Report from './actions/Report';
import Navigation from './Navigation/Navigation';
import shouldOpenOnAdminRoom from './Navigation/shouldOpenOnAdminRoom';
import * as ReportUtils from './ReportUtils';

const navigateAfterOnboarding = (isSmallScreenWidth: boolean, canUseDefaultRooms: boolean | undefined, onboardingPolicyID?: string, activeWorkspaceID?: string) => {
const navigateAfterOnboarding = (
isSmallScreenWidth: boolean,
shouldUseNarrowLayout: boolean,
canUseDefaultRooms: boolean | undefined,
onboardingPolicyID?: string,
activeWorkspaceID?: string,
backTo?: string,
) => {
Navigation.dismissModal();

// When hasCompletedGuidedSetupFlow is true, OnboardingModalNavigator in AuthScreen is removed from the navigation stack.
Expand All @@ -16,7 +24,12 @@ const navigateAfterOnboarding = (isSmallScreenWidth: boolean, canUseDefaultRooms
const lastAccessedReport = ReportUtils.findLastAccessedReport(!canUseDefaultRooms, shouldOpenOnAdminRoom(), activeWorkspaceID);
const lastAccessedReportID = lastAccessedReport?.reportID;
// we don't want to navigate to newly creaded workspace after onboarding completed.
if (!lastAccessedReportID || lastAccessedReport.policyID === onboardingPolicyID || ReportUtils.isConciergeChatReport(lastAccessedReport)) {
if (!lastAccessedReportID || lastAccessedReport.policyID === onboardingPolicyID) {
// Only navigate to concierge chat when central pane is visible
// Otherwise stay on the chats screen.
if (!shouldUseNarrowLayout && !backTo) {
Report.navigateToConciergeChat();
}
return;
}

Expand Down
6 changes: 3 additions & 3 deletions src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ type OnboardingListItem = ListItem & {
keyForList: OnboardingAccounting;
};

function BaseOnboardingAccounting({shouldUseNativeStyles}: BaseOnboardingAccountingProps) {
function BaseOnboardingAccounting({shouldUseNativeStyles, route}: BaseOnboardingAccountingProps) {
const styles = useThemeStyles();
const theme = useTheme();
const StyleUtils = useStyleUtils();
const {translate} = useLocalize();

// We need to use isSmallScreenWidth, see navigateAfterOnboarding function comment
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
const {onboardingIsMediumOrLargerScreenWidth, isSmallScreenWidth} = useResponsiveLayout();
const {onboardingIsMediumOrLargerScreenWidth, isSmallScreenWidth, shouldUseNarrowLayout} = useResponsiveLayout();
const [onboardingValues] = useOnyx(ONYXKEYS.NVP_ONBOARDING);
const [onboardingPurposeSelected] = useOnyx(ONYXKEYS.ONBOARDING_PURPOSE_SELECTED);
const [onboardingPolicyID] = useOnyx(ONYXKEYS.ONBOARDING_POLICY_ID);
Expand Down Expand Up @@ -172,7 +172,7 @@ function BaseOnboardingAccounting({shouldUseNativeStyles}: BaseOnboardingAccount
Welcome.setOnboardingAdminsChatReportID();
Welcome.setOnboardingPolicyID();
});
navigateAfterOnboarding(isSmallScreenWidth, canUseDefaultRooms, onboardingPolicyID, activeWorkspaceID);
navigateAfterOnboarding(isSmallScreenWidth, shouldUseNarrowLayout, canUseDefaultRooms, onboardingPolicyID, activeWorkspaceID, route.params?.backTo);
}}
pressOnEnter
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import ROUTES from '@src/ROUTES';
import INPUT_IDS from '@src/types/form/DisplayNameForm';
import type {BaseOnboardingPersonalDetailsProps} from './types';

function BaseOnboardingPersonalDetails({currentUserPersonalDetails, shouldUseNativeStyles}: BaseOnboardingPersonalDetailsProps) {
function BaseOnboardingPersonalDetails({currentUserPersonalDetails, shouldUseNativeStyles, route}: BaseOnboardingPersonalDetailsProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const [onboardingPurposeSelected] = useOnyx(ONYXKEYS.ONBOARDING_PURPOSE_SELECTED);
Expand All @@ -41,7 +41,7 @@ function BaseOnboardingPersonalDetails({currentUserPersonalDetails, shouldUseNat

// We need to use isSmallScreenWidth, see navigateAfterOnboarding function comment
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
const {onboardingIsMediumOrLargerScreenWidth, isSmallScreenWidth} = useResponsiveLayout();
const {onboardingIsMediumOrLargerScreenWidth, isSmallScreenWidth, shouldUseNarrowLayout} = useResponsiveLayout();
const {inputCallbackRef} = useAutoFocusInput();
const [shouldValidateOnChange, setShouldValidateOnChange] = useState(false);
const isPrivateDomain = Session.isUserOnPrivateDomain();
Expand Down Expand Up @@ -70,9 +70,9 @@ function BaseOnboardingPersonalDetails({currentUserPersonalDetails, shouldUseNat
Welcome.setOnboardingAdminsChatReportID();
Welcome.setOnboardingPolicyID();

navigateAfterOnboarding(isSmallScreenWidth, canUseDefaultRooms, onboardingPolicyID, activeWorkspaceID);
navigateAfterOnboarding(isSmallScreenWidth, shouldUseNarrowLayout, canUseDefaultRooms, onboardingPolicyID, activeWorkspaceID, route.params?.backTo);
},
[onboardingPurposeSelected, onboardingAdminsChatReportID, onboardingPolicyID, activeWorkspaceID, canUseDefaultRooms, isSmallScreenWidth],
[onboardingPurposeSelected, onboardingAdminsChatReportID, onboardingPolicyID, route.params?.backTo, activeWorkspaceID, canUseDefaultRooms, isSmallScreenWidth, shouldUseNarrowLayout],
);

useEffect(() => {
Expand Down
24 changes: 13 additions & 11 deletions src/pages/home/report/ReportActionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -415,19 +415,21 @@ function ReportActionsList({

const scrollToBottomForCurrentUserAction = useCallback(
(isFromCurrentUser: boolean) => {
// If a new comment is added and it's from the current user scroll to the bottom otherwise leave the user positioned where
// they are now in the list.
if (!isFromCurrentUser) {
return;
}
if (!hasNewestReportActionRef.current) {
if (isInNarrowPaneModal) {
InteractionManager.runAfterInteractions(() => {
// If a new comment is added and it's from the current user scroll to the bottom otherwise leave the user positioned where
// they are now in the list.
if (!isFromCurrentUser) {
return;
}
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report.reportID));
return;
}
InteractionManager.runAfterInteractions(() => reportScrollManager.scrollToBottom());
if (!hasNewestReportActionRef.current) {
if (isInNarrowPaneModal) {
return;
}
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report.reportID));
return;
}
reportScrollManager.scrollToBottom();
});
},
[isInNarrowPaneModal, reportScrollManager, report.reportID],
);
Expand Down
4 changes: 2 additions & 2 deletions src/pages/workspace/WorkspaceNewRoomPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ function WorkspaceNewRoomPage() {

const workspaceOptions = useMemo(
() =>
PolicyUtils.getActivePolicies(policies, session?.email)
PolicyUtils.getActivePolicies(policies)
?.filter((policy) => policy.type !== CONST.POLICY.TYPE.PERSONAL)
.map((policy) => ({
label: policy.name,
value: policy.id,
}))
.sort((a, b) => localeCompare(a.label, b.label)) ?? [],
[policies, session?.email],
[policies],
);
const [policyID, setPolicyID] = useState<string>(() => {
if (!!activeWorkspaceOrDefaultID && workspaceOptions.some((option) => option.value === activeWorkspaceOrDefaultID)) {
Expand Down
14 changes: 0 additions & 14 deletions tests/unit/PolicyUtilsTest.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
import * as PolicyUtils from '@libs/PolicyUtils';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Policy} from '@src/types/onyx';
import createCollection from '../utils/collections/createCollection';
import createRandomPolicy from '../utils/collections/policies';

function toLocaleDigitMock(dot: string): string {
return dot;
}

describe('PolicyUtils', () => {
describe('getActivePolicies', () => {
it("getActivePolicies should filter out policies that the current user doesn't belong to", () => {
const policies = createCollection<Policy>(
(item) => `${ONYXKEYS.COLLECTION.POLICY}${item.id}`,
(index) => ({...createRandomPolicy(index + 1), ...(!index && {role: null})} as Policy),
2,
);
expect(PolicyUtils.getActivePolicies(policies, undefined)).toHaveLength(1);
});
});
describe('getRateDisplayValue', () => {
it('should return an empty string for NaN', () => {
const rate = PolicyUtils.getRateDisplayValue('invalid' as unknown as number, toLocaleDigitMock);
Expand Down

0 comments on commit da8a017

Please sign in to comment.