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
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ function ReportActionItemEmojiReactions({reportAction, reportID, isEditingInline

const reportActionID = reportAction.reportActionID;
const [emojiReactions = getEmptyObject<ReportActionReactions>()] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${reportActionID}`);
const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`);
Comment thread
cretadn22 marked this conversation as resolved.

// Prime the locale emoji table when this action has reactions.
// Skip the default locale since getLocalizedEmojiName never reads localeEmojis for it.
Expand All @@ -97,7 +98,7 @@ function ReportActionItemEmojiReactions({reportAction, reportID, isEditingInline
});
return;
}
toggleEmojiReaction(reportID, reportAction, emoji, emojiReactions, skinTone, currentUserAccountID, ignoreSkinToneOnCompare);
toggleEmojiReaction(reportID, reportAction, emoji, emojiReactions, skinTone, currentUserAccountID, reportActions, ignoreSkinToneOnCompare);
};

// Each emoji is sorted by the oldest timestamp of user reactions so that they will always appear in the same order for everyone
Expand Down
3 changes: 1 addition & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10677,11 +10677,10 @@ function canUserPerformWriteAction(report: OnyxEntry<Report>, isReportArchived:
/**
* Returns ID of the original report from which the given reportAction is first created.
*/
function getOriginalReportID(reportID: string | undefined, reportAction: OnyxInputOrEntry<ReportAction>, reportActionsParam: OnyxEntry<ReportActions> | undefined): string | undefined {
function getOriginalReportID(reportID: string | undefined, reportAction: OnyxInputOrEntry<ReportAction>, reportActions: OnyxEntry<ReportActions> | undefined): string | undefined {
if (!reportID) {
return undefined;
}
const reportActions = reportActionsParam ?? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`];
const currentReportAction = reportAction?.reportActionID ? reportActions?.[reportAction.reportActionID] : undefined;
const report = deprecatedAllReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
const chatReport = deprecatedAllReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`];
Expand Down
5 changes: 3 additions & 2 deletions src/libs/actions/EmojiReactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {getOriginalReportID} from '@libs/ReportUtils';

import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {ReportAction, ReportActionReactions} from '@src/types/onyx';
import type {ReportAction, ReportActionReactions, ReportActions} from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

import type {OnyxEntry, OnyxUpdate} from 'react-native-onyx';
Expand Down Expand Up @@ -106,9 +106,10 @@ function toggleEmojiReaction(
existingReactions: OnyxEntry<ReportActionReactions>,
paramSkinTone: number,
currentUserAccountID: number,
reportActions: OnyxEntry<ReportActions>,
ignoreSkinToneOnCompare = false,
) {
const originalReportID = getOriginalReportID(reportID, reportAction, undefined);
const originalReportID = getOriginalReportID(reportID, reportAction, reportActions);

if (!originalReportID) {
return;
Expand Down
7 changes: 4 additions & 3 deletions src/libs/actions/Report/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3094,14 +3094,15 @@ function deleteReportComment(
report: OnyxEntry<Report>,
reportAction: ReportAction,
originalReportActions: OnyxEntry<ReportActions>,
reportActions: OnyxEntry<ReportActions>,
ancestors: Ancestor[],
isReportArchived: boolean | undefined,
isOriginalReportArchived: boolean | undefined,
currentEmail: string,
visibleReportActionsDataParam?: VisibleReportActionsDerivedValue,
) {
const reportID = report?.reportID;
const originalReportID = getOriginalReportID(reportID, reportAction, undefined);
const originalReportID = getOriginalReportID(reportID, reportAction, reportActions);
const reportActionID = reportAction.reportActionID;

if (!reportActionID || !originalReportID || !reportID) {
Expand Down Expand Up @@ -3511,12 +3512,12 @@ function clearAllReportActionDrafts() {
}

/** Saves the draft for a comment report action. This will put the comment into "edit mode" */
function saveReportActionDraft(reportID: string | undefined, reportAction: ReportAction | null, draftMessage: string) {
function saveReportActionDraft(reportID: string | undefined, reportAction: ReportAction | null, reportActions: OnyxEntry<ReportActions>, draftMessage: string) {
if (!reportAction) {
return;
}

const originalReportID = getOriginalReportID(reportID, reportAction, undefined);
const originalReportID = getOriginalReportID(reportID, reportAction, reportActions);
if (!originalReportID) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ function BaseReportActionContextMenu({
const payload: ContextMenuActionPayload = {
reportActions,
childReportActions,
originalReportActions,
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
reportAction: (reportAction ?? null) as ReportAction,
reportID,
Expand Down
9 changes: 5 additions & 4 deletions src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ type ShouldShow = (args: {
type ContextMenuActionPayload = {
reportActions: OnyxEntry<ReportActions>;
childReportActions: OnyxEntry<ReportActions>;
originalReportActions: OnyxEntry<ReportActions>;
reportAction: ReportAction;
transaction?: OnyxEntry<Transaction>;
reportID: string | undefined;
Expand Down Expand Up @@ -433,7 +434,7 @@ const ContextMenuActions: ContextMenuAction[] = [
const isDynamicWorkflowRoutedAction = isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.DYNAMIC_EXTERNAL_WORKFLOW_ROUTED);
return type === CONST.CONTEXT_MENU_TYPES.REPORT_ACTION && !!reportAction && 'message' in reportAction && !isMessageDeleted(reportAction) && !isDynamicWorkflowRoutedAction;
},
renderContent: (closePopover, {reportID, reportAction, currentUserAccountID, close: closeManually, openContextMenu, setIsEmojiPickerActive}) => {
renderContent: (closePopover, {reportID, reportActions, reportAction, currentUserAccountID, close: closeManually, openContextMenu, setIsEmojiPickerActive}) => {
const isMini = !closePopover;

const closeContextMenu = (onHideCallback?: () => void) => {
Expand All @@ -448,7 +449,7 @@ const ContextMenuActions: ContextMenuAction[] = [
};

const toggleEmojiAndCloseMenu = (emoji: Emoji, existingReactions: OnyxEntry<ReportActionReactions>, preferredSkinTone: number) => {
toggleEmojiReaction(reportID, reportAction, emoji, existingReactions, preferredSkinTone, currentUserAccountID);
toggleEmojiReaction(reportID, reportAction, emoji, existingReactions, preferredSkinTone, currentUserAccountID, reportActions);
closeContextMenu();
setIsEmojiPickerActive?.(false);
};
Expand Down Expand Up @@ -610,7 +611,7 @@ const ContextMenuActions: ContextMenuAction[] = [
(canEditReportAction(reportAction, iouTransaction) || canEditReportAction(moneyRequestAction, iouTransaction)) &&
!isArchivedRoom &&
!isChronosReport,
onPress: (closePopover, {reportID, originalReportID, reportAction, moneyRequestAction, introSelected, betas, childReportActions}) => {
onPress: (closePopover, {reportID, reportActions, originalReportActions, originalReportID, reportAction, moneyRequestAction, introSelected, betas, childReportActions}) => {
if (isMoneyRequestAction(reportAction) || isMoneyRequestAction(moneyRequestAction)) {
const editExpense = () => {
const childReportID = reportAction?.childReportID;
Expand All @@ -625,7 +626,7 @@ const ContextMenuActions: ContextMenuAction[] = [
return;
}
const editAction = () => {
saveReportActionDraft(originalReportID ?? reportID, reportAction, Parser.htmlToMarkdown(getActionHtml(reportAction)));
saveReportActionDraft(originalReportID ?? reportID, reportAction, originalReportActions ?? reportActions, Parser.htmlToMarkdown(getActionHtml(reportAction)));
};

if (closePopover) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ function PopoverReportActionContextMenu({ref}: PopoverReportActionContextMenuPro
report,
reportAction,
originalReportActions,
reportActions,
ancestorsRef.current,
isReportArchived,
isOriginalReportArchived,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ function ComposerWithSuggestions({

const {editingState, editingReportID, editingReportAction, effectiveDraft, currentEditMessageSelection} = useComposerEditState();
const {setEditingMessage, setCurrentEditMessageSelection} = useReportActionActiveEditActions();
const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`);

const isEditing = editingState !== CONST.REPORT_ACTION_EDIT_MESSAGE_STATE.OFF;
const text = useComposerText();
Expand All @@ -285,14 +286,7 @@ function ComposerWithSuggestions({
});

// Save the draft of the report action. This debounced so that we're not ceaselessly saving your edit.
const {saveDraft: debouncedSaveReportActionDraft, isSavePending: isDraftSavePending} = useDebouncedSaveDraft(
useCallback(
(comment: string) => {
saveReportActionDraft(editingReportID ?? reportID, editingReportAction, comment);
},
[reportID, editingReportID, editingReportAction],
),
);
const {saveDraft: debouncedSaveReportActionDraft, isSavePending: isDraftSavePending} = useDebouncedSaveDraft(saveReportActionDraft);

// Save the draft of the report comment. This debounced so that we're not ceaselessly saving your edit. Saving the draft
// allows one to navigate somewhere else and come back to the comment and still have it in edit mode.
Expand Down Expand Up @@ -559,11 +553,11 @@ function ComposerWithSuggestions({
if (editingState === CONST.REPORT_ACTION_EDIT_MESSAGE_STATE.EDITING && shouldUseNarrowLayout) {
setEditingMessage(newCommentConverted);
if (shouldDebounceSaveComment) {
debouncedSaveReportActionDraft(newCommentConverted);
debouncedSaveReportActionDraft(editingReportID ?? reportID, editingReportAction, reportActions, newCommentConverted);
return;
}

saveReportActionDraft(editingReportID ?? reportID, editingReportAction, newCommentConverted);
saveReportActionDraft(editingReportID ?? reportID, editingReportAction, reportActions, newCommentConverted);
return;
}

Expand Down Expand Up @@ -594,6 +588,7 @@ function ComposerWithSuggestions({
reportID,
editingReportID,
editingReportAction,
reportActions,
debouncedSaveReportActionDraft,
debouncedSaveComment,
currentUserAccountID,
Expand Down Expand Up @@ -635,7 +630,7 @@ function ComposerWithSuggestions({
webEvent.preventDefault();
if (lastReportAction) {
const message = Array.isArray(lastReportAction?.message) ? (lastReportAction?.message?.at(-1) ?? null) : (lastReportAction?.message ?? null);
saveReportActionDraft(reportID, lastReportAction, Parser.htmlToMarkdown(message?.html ?? ''));
saveReportActionDraft(reportID, lastReportAction, reportActions, Parser.htmlToMarkdown(message?.html ?? ''));
}
}
// Flag emojis like "Wales" have several code points. Default backspace key action does not remove such flag emojis completely.
Expand Down Expand Up @@ -684,6 +679,7 @@ function ComposerWithSuggestions({
onEnterKeyPress,
lastReportAction,
reportID,
reportActions,
updateComment,
setCurrentEditMessageSelection,
],
Expand Down
5 changes: 3 additions & 2 deletions src/pages/inbox/report/ReportActionItemMessageEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ function ReportActionItemMessageEdit({action, reportID, originalReportID, policy
const index = useContext(ReportActionIndexContext);
const [preferredSkinTone = CONST.EMOJI_DEFAULT_SKIN_TONE] = useOnyx(ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE);
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(reportID)}`);
const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${getNonEmptyStringOnyxID(reportID)}`);
const isOriginalReportArchived = useReportIsArchived(originalReportID);
const [originalReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(originalReportID)}`);
const blockedFromConcierge = useBlockedFromConcierge();
Expand Down Expand Up @@ -245,9 +246,9 @@ function ReportActionItemMessageEdit({action, reportID, originalReportID, policy
setEditingMessage(newDraft);

// We want to escape the draft message to differentiate the HTML from the report action and the HTML the user drafted.
saveDraft(reportID, action, newDraft);
saveDraft(reportID, action, reportActions, newDraft);
},
[action, preferredLocale, preferredSkinTone, raiseIsScrollLayoutTriggered, reportID, selection.end, setEditingMessage, setSelection, saveDraft],
[action, preferredLocale, preferredSkinTone, raiseIsScrollLayoutTriggered, reportID, reportActions, selection.end, setEditingMessage, setSelection, saveDraft],
);

useEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions tests/actions/AttachmentTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ describe('AttachmentStorage', () => {
}

// Delete attachment
deleteReportComment({reportID}, attachmentAction, undefined, [], false, false, 'test@user.com');
deleteReportComment({reportID}, attachmentAction, undefined, undefined, [], false, false, 'test@user.com');
await waitForBatchedUpdates();

// Then the attachment should be removed
Expand Down Expand Up @@ -332,7 +332,7 @@ describe('AttachmentStorage', () => {
}

// Delete attachment
deleteReportComment({reportID}, attachmentAction, undefined, [], false, false, 'test@user.com');
deleteReportComment({reportID}, attachmentAction, undefined, undefined, [], false, false, 'test@user.com');
await waitForBatchedUpdates();

const removedAttachment = attachments?.[`${ONYXKEYS.COLLECTION.ATTACHMENT}${attachmentID}`];
Expand Down
Loading
Loading