Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/components/ChangeWorkspaceMenuSectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function ChangeWorkspaceMenuSectionList() {
src={section.icon}
additionalStyles={[styles.mr4]}
/>
<View style={[styles.flex1, styles.justifyContentCenter]}>
<View style={[styles.flex1, styles.flexRow, styles.justifyContentCenter, styles.alignItemsCenter, styles.wAuto]}>
<RenderHTML html={`<comment>${convertToLTR(translate(section.titleTranslationKey))}</comment>`} />
</View>
</View>
Expand Down
14 changes: 10 additions & 4 deletions src/hooks/useWorkspaceList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type WorkspaceListItem = {
type UseWorkspaceListParams = {
policies: OnyxCollection<Policy>;
currentUserLogin: string | undefined;
isOffline: boolean;
shouldShowPendingDeletePolicy: boolean;
selectedPolicyID: string | undefined;
searchTerm: string;
additionalFilter?: (policy: OnyxEntry<Policy>) => boolean;
Expand All @@ -41,7 +41,7 @@ function useWorkspaceList({
currentUserLogin,
selectedPolicyID,
searchTerm,
isOffline,
shouldShowPendingDeletePolicy,
isWorkspaceSwitcher = false,
hasUnreadData,
getIndicatorTypeForPolicy,
Expand All @@ -53,7 +53,13 @@ function useWorkspaceList({
}

return Object.values(policies)
.filter((policy) => !!policy && shouldShowPolicy(policy, !!isOffline, currentUserLogin) && !policy?.isJoinRequestPending && (additionalFilter ? additionalFilter(policy) : true))
.filter(
(policy) =>
!!policy &&
shouldShowPolicy(policy, shouldShowPendingDeletePolicy, currentUserLogin) &&
!policy?.isJoinRequestPending &&
(additionalFilter ? additionalFilter(policy) : true),
)
.map((policy) => ({
text: policy?.name ?? '',
policyID: policy?.id,
Expand All @@ -76,7 +82,7 @@ function useWorkspaceList({
brickRoadIndicator: getIndicatorTypeForPolicy(policy?.id),
}),
}));
}, [policies, isOffline, currentUserLogin, additionalFilter, selectedPolicyID, getIndicatorTypeForPolicy, hasUnreadData, isWorkspaceSwitcher]);
}, [policies, shouldShowPendingDeletePolicy, currentUserLogin, additionalFilter, selectedPolicyID, getIndicatorTypeForPolicy, hasUnreadData, isWorkspaceSwitcher]);

const filteredAndSortedUserWorkspaces = useMemo<WorkspaceListItem[]>(
() =>
Expand Down
41 changes: 34 additions & 7 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4942,7 +4942,9 @@ function changeReportPolicy(reportID: string, policyID: string) {

// 2. If the old workspace had a workspace chat, mark the report preview action as deleted
if (reportToMove?.parentReportID && reportToMove?.parentReportActionID) {
const oldReportPreviewAction = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportToMove?.parentReportID}`]?.[reportToMove?.parentReportActionID];
const workspaceChatReportID = reportToMove.parentReportID;
const reportPreviewActionID = reportToMove.parentReportActionID;
const oldReportPreviewAction = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${workspaceChatReportID}`]?.[reportPreviewActionID];

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.

This change + the below failureData addition led to the following issue:

which we addressed in this PR, see proposal for more details on the root cause and solution.

const deletedTime = DateUtils.getDBTime();
const firstMessage = Array.isArray(oldReportPreviewAction?.message) ? oldReportPreviewAction.message.at(0) : null;
const updatedReportPreviewAction = {
Expand All @@ -4968,13 +4970,34 @@ function changeReportPolicy(reportID: string, policyID: string) {

optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportToMove?.parentReportID}`,
value: {[reportToMove?.parentReportActionID]: updatedReportPreviewAction},
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${workspaceChatReportID}`,
value: {[reportPreviewActionID]: updatedReportPreviewAction},
});
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportToMove?.parentReportID}`,
value: {[reportToMove?.parentReportActionID]: oldReportPreviewAction},
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${workspaceChatReportID}`,
value: {[reportPreviewActionID]: oldReportPreviewAction},
});

// Update the workspace chat report
const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${workspaceChatReportID}`];
const lastMessageText = getLastVisibleMessage(workspaceChatReportID, {[reportPreviewActionID]: updatedReportPreviewAction as ReportAction})?.lastMessageText;
const lastVisibleActionCreated = getReportLastMessage(workspaceChatReportID, {[reportPreviewActionID]: updatedReportPreviewAction as ReportAction})?.lastVisibleActionCreated;

optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${workspaceChatReportID}`,
value: {
hasOutstandingChildRequest: false,
iouReportID: null,
lastMessageText,
lastVisibleActionCreated,
},
});
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${workspaceChatReportID}`,
value: chatReport,
});
}

Expand Down Expand Up @@ -5042,15 +5065,19 @@ function changeReportPolicy(reportID: string, policyID: string) {
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportToMove.reportID}`,
value: {
[optimisticMovedReportAction.reportActionID]: {
...optimisticMovedReportAction,
pendingAction: null,
errors: null,
},
},
});
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportToMove.reportID}`,
value: {[optimisticMovedReportAction.reportActionID]: null},
value: {
[optimisticMovedReportAction.reportActionID]: {
errors: getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'),
},
},
});

// Call the ChangeReportPolicy API endpoint
Expand Down
8 changes: 7 additions & 1 deletion src/pages/ReportChangeWorkspacePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {ReportChangeWorkspaceNavigatorParamList} from '@libs/Navigation/types';
import {isWorkspaceEligibleForReportChange} from '@libs/PolicyUtils';
import {isExpenseReport, isMoneyRequestReportPendingDeletion} from '@libs/ReportUtils';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import NotFoundPage from './ErrorPage/NotFoundPage';
import type {WithReportOrNotFoundProps} from './home/report/withReportOrNotFound';
import withReportOrNotFound from './home/report/withReportOrNotFound';

Expand Down Expand Up @@ -51,12 +53,16 @@ function ReportChangeWorkspacePage({report}: ReportChangeWorkspacePageProps) {
const {sections, shouldShowNoResultsFoundMessage, shouldShowSearchInput} = useWorkspaceList({
policies,
currentUserLogin,
isOffline,
shouldShowPendingDeletePolicy: false,
selectedPolicyID: report.policyID,
searchTerm: debouncedSearchTerm,
additionalFilter: (newPolicy) => isWorkspaceEligibleForReportChange(newPolicy, report, oldPolicy, currentUserLogin),
});

if (!isExpenseReport(report) || isMoneyRequestReportPendingDeletion(report) || (!report.total && !report.unheldTotal)) {

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.

The condition (!report.total && !report.unheldTotal) caused issue #61342, and the original issue it aimed to fix was no longer reproducible, so we removed it in PR #62073.

return <NotFoundPage />;
}

return (
<ScreenWrapper
testID={ReportChangeWorkspacePage.displayName}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/WorkspaceSwitcherPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function WorkspaceSwitcherPage() {

const {sections, shouldShowNoResultsFoundMessage, shouldShowSearchInput, shouldShowCreateWorkspace} = useWorkspaceList({
policies,
isOffline,
shouldShowPendingDeletePolicy: !!isOffline,
currentUserLogin,
selectedPolicyID: activeWorkspaceID,
searchTerm: debouncedSearchTerm,
Expand Down