Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/hooks/useAutoCreateTrackWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ function useAutoCreateTrackWorkspace() {
isSelfTourViewed,
hasActiveAdminPolicies,
personalTrackGoal: onboardingPurposeSelected === CONST.ONBOARDING_CHOICES.TRACK_PERSONAL && !!personalTrackGoal ? personalTrackGoal : undefined,
shouldShowTrackAdminRoomInLHN: onboardingPurposeSelected === CONST.ONBOARDING_CHOICES.TRACK_WORKSPACE,
})
: {adminsChatReportID: onboardingAdminsChatReportID, policyID: onboardingPolicyID};

Expand Down
1 change: 1 addition & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9700,6 +9700,7 @@ function reasonForReportToBeInOptionList({
!isConciergeChatReport(report, conciergeReportID) &&
!isSystemChatReport &&
!isSelfDMWithVisiblePreference &&
!(getReportMetadata(report.reportID)?.isTrackOnboardingAdminRoom && isAdminRoom(report) && !isReportArchived) &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, if the user clears the cache, will the admin room be gone?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, clearing the cache removes the local visibility marker, causing #admins to disappear from the LHN.

canHideReport
) {
return null;
Expand Down
8 changes: 8 additions & 0 deletions src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ function shouldDisplayReportInLHN({
const parentReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID}`];
const hasErrorsOtherThanFailedReceipt = hasReportErrorsOtherThanFailedReceipt(report, chatReport, doesReportHaveViolations, transactionViolations, transactions, reportAttributes);
const isReportInAccessible = report?.errorFields?.notFound;
const isTrackOnboardingAdminRoom = getReportMetadata(report.reportID)?.isTrackOnboardingAdminRoom && isAdminRoom(report);

if (isTrackOnboardingAdminRoom && isReportArchived) {
return {shouldDisplay: false};
}

if (isOneTransactionThread(report, parentReport, parentReportAction, isOffline)) {
return {shouldDisplay: false};
}
Expand All @@ -346,6 +352,8 @@ function shouldDisplayReportInLHN({
isSystemChat ||
!!report.isPinned ||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
isTrackOnboardingAdminRoom ||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
requiresAttention ||
(report.isOwnPolicyExpenseChat && !isReportArchived);

Expand Down
4 changes: 4 additions & 0 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ type BuildPolicyDataOptions = {
hasActiveAdminPolicies: boolean | undefined;
betas?: OnyxEntry<Beta[]>;
personalTrackGoal?: string;
shouldShowTrackAdminRoomInLHN?: boolean;
};

// TODO: Remove this type once we complete refactoring the buildPolicyData function to use isSelfTourViewed. Refactor issue: https://github.com/Expensify/App/issues/66424
Expand Down Expand Up @@ -2612,6 +2613,7 @@ function buildPolicyData(options: BuildPolicyDataOptions): OnyxData<BuildPolicyD
isSelfTourViewed,
hasActiveAdminPolicies,
personalTrackGoal,
shouldShowTrackAdminRoomInLHN,
} = options;

const {customUnits, customUnitID, customUnitRateID, outputCurrency} = buildOptimisticDistanceRateCustomUnits(currency);
Expand Down Expand Up @@ -2805,13 +2807,15 @@ function buildPolicyData(options: BuildPolicyDataOptions): OnyxData<BuildPolicyD
addWorkspaceRoom: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
},
...adminsChatData,
...(shouldShowTrackAdminRoomInLHN && {isPinned: false}),
},
},
{
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${adminsChatReportID}`,
value: {
pendingChatMembers,
...(shouldShowTrackAdminRoomInLHN && {isTrackOnboardingAdminRoom: true}),
},
},
{
Expand Down
3 changes: 3 additions & 0 deletions src/types/onyx/ReportMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ type ReportMetadata = {
/** Whether the current report is optimistic */
isOptimisticReport?: boolean;

/** Whether this is the admins room created during Track workspace onboarding and should remain visible in the LHN while active */
isTrackOnboardingAdminRoom?: boolean;

/** Pending members of the report */
pendingChatMembers?: PendingChatMember[];

Expand Down
38 changes: 38 additions & 0 deletions tests/actions/PolicyTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,44 @@ describe('actions/Policy', () => {
mockFetch?.resume?.();
});

it('creates Track onboarding admins rooms unpinned without changing the regular workspace default', async () => {
mockFetch.pause?.();
await Onyx.set(ONYXKEYS.SESSION, {email: ESH_EMAIL, accountID: ESH_ACCOUNT_ID});
await waitForBatchedUpdates();

const createWorkspaceOptions = {
policyOwnerEmail: ESH_EMAIL,
makeMeAdmin: true,
policyName: WORKSPACE_NAME,
engagementChoice: CONST.ONBOARDING_CHOICES.TRACK_WORKSPACE,
introSelected: {choice: CONST.ONBOARDING_CHOICES.TRACK_WORKSPACE},
currentUserAccountIDParam: ESH_ACCOUNT_ID,
currentUserEmailParam: ESH_EMAIL,
currency: CONST.CURRENCY.USD,
isSelfTourViewed: false,
hasActiveAdminPolicies: false,
activePolicy: undefined,
};

const trackWorkspaceParams = Policy.createWorkspace({
...createWorkspaceOptions,
policyID: Policy.generatePolicyID(),
shouldShowTrackAdminRoomInLHN: true,
});
const regularWorkspaceParams = Policy.createWorkspace({
...createWorkspaceOptions,
policyID: Policy.generatePolicyID(),
shouldShowTrackAdminRoomInLHN: false,
});
await waitForBatchedUpdates();

const trackAdminReport = await getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT}${trackWorkspaceParams.adminsChatReportID}`);
const regularAdminReport = await getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT}${regularWorkspaceParams.adminsChatReportID}`);

expect(trackAdminReport?.isPinned).toBe(false);
expect(regularAdminReport?.isPinned).toBe(true);
});

it('creates a new workspace', async () => {
(fetch as MockFetch)?.pause?.();
await Onyx.set(ONYXKEYS.SESSION, {email: ESH_EMAIL, accountID: ESH_ACCOUNT_ID});
Expand Down
46 changes: 46 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6689,6 +6689,52 @@ describe('ReportUtils', () => {
).toBeFalsy();
});

it('should return true for an active empty Track onboarding admins room when empty chats are excluded', async () => {
const report: Report = {
...createAdminRoom(1),
isPinned: false,
};
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`, {isTrackOnboardingAdminRoom: true});
await waitForBatchedUpdates();

expect(
shouldReportBeInOptionList({
report,
chatReport: mockedChatReport,
currentReportId: '',
isInFocusMode: false,
betas: [CONST.BETAS.DEFAULT_ROOMS],
doesReportHaveViolations: false,
excludeEmptyChats: true,
draftComment: '',
isReportArchived: false,
}),
).toBeTruthy();
});

it('should retain archived Track onboarding admins rooms in report option lists used by search', async () => {
const report: Report = {
...createAdminRoom(1),
isPinned: false,
};
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`, {isTrackOnboardingAdminRoom: true});
await waitForBatchedUpdates();

expect(
reasonForReportToBeInOptionList({
report,
chatReport: mockedChatReport,
currentReportId: '',
isInFocusMode: false,
betas: [CONST.BETAS.DEFAULT_ROOMS],
doesReportHaveViolations: false,
excludeEmptyChats: false,
draftComment: '',
isReportArchived: true,
}),
).toBe(CONST.REPORT_IN_LHN_REASONS.IS_ARCHIVED);
});

it('should return DEFAULT for an empty concierge chat when excludeEmptyChats is true', async () => {
const conciergeReportID = 'concierge-report-123';
const report: Report = {
Expand Down
63 changes: 62 additions & 1 deletion tests/unit/SidebarUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {actionR14932 as mockIOUAction} from '../../__mocks__/reportData/actions'
import {chatReportR14932, iouReportR14932} from '../../__mocks__/reportData/reports';
import createRandomPolicy from '../utils/collections/policies';
import createRandomReportAction from '../utils/collections/reportActions';
import {createRandomReport} from '../utils/collections/reports';
import {createAdminRoom, createRandomReport} from '../utils/collections/reports';
import {createSidebarReportsCollection, createSidebarTestData} from '../utils/collections/sidebarReports';
import createRandomTransaction from '../utils/collections/transaction';
import * as LHNTestUtils from '../utils/LHNTestUtils';
Expand Down Expand Up @@ -836,6 +836,67 @@ describe('SidebarUtils', () => {
});

describe('shouldDisplayReportInLHN', () => {
const getAdminRoomDisplayResult = async (reportOverrides: Partial<Report>, isReportArchived = false, currentReportId?: string, isTrackOnboardingAdminRoom = false) => {
const report: Report = {
...createAdminRoom(92431),
participants: {
[CURRENT_USER_ACCOUNT_ID]: {
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
},
},
isPinned: false,
lastMessageText: '',
...reportOverrides,
};
await act(async () => {
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`, {isTrackOnboardingAdminRoom});
});

return SidebarUtils.shouldDisplayReportInLHN({
report,
reports: {[`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report},
currentReportId,
isInFocusMode: false,
betas: [],
transactionViolations: {},
draftComment: undefined,
transactions: {},
isOffline: false,
isReportArchived,
currentUserLogin: CURRENT_USER_LOGIN,
currentUserAccountID: CURRENT_USER_ACCOUNT_ID,
});
};

it('shows an active hidden and empty Track onboarding admins room without pinning it', async () => {
const result = await getAdminRoomDisplayResult({}, false, undefined, true);

expect(result).toStrictEqual({shouldDisplay: true});
});

it.each([
['unpinned and empty', {isPinned: false}],
['pinned', {isPinned: true}],
['non-empty', {lastMessageText: 'Message'}],
])('hides an archived Track onboarding admins room when it is %s', async (_description, reportOverrides) => {
const result = await getAdminRoomDisplayResult(reportOverrides, true, undefined, true);

expect(result).toStrictEqual({shouldDisplay: false});
});

it('hides an archived Track onboarding admins room even when it is focused', async () => {
const report = createAdminRoom(92431);
const result = await getAdminRoomDisplayResult({reportID: report.reportID}, true, report.reportID, true);

expect(result).toStrictEqual({shouldDisplay: false});
});

it('does not change visibility for an unmarked hidden and empty admins room', async () => {
const result = await getAdminRoomDisplayResult({});

expect(result).toStrictEqual({shouldDisplay: false});
});

it('returns shouldDisplay as true if a one transaction thread expense report has receipt upload error', async () => {
const MOCK_REPORT: Report = {
reportID: '1',
Expand Down
Loading