Skip to content

[PAID] Implement and use ReportUtils.transactionThreadHasViolations(report) #31095

Closed

Description

@cead22
  • Design Doc
  • Implementation should look like code snippet below
    • Which probably means we should connect ReportUtils to the BETAS onyx collection
    • Let's also connect it to the TRANSACTION_VIOLATIONS and REPORT_ACTIONS Onyx collections as shown below
    • And let's also add as shown below ReportUtils.reportHasViolations
  • Then let's use ReportUtils.transactionThreadHasViolations
    • In SidebarUtils.ts Let's update this
      • From: result.brickRoadIndicator = Object.keys(result.allReportErrors ?? {}).length !== 0 ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : '';
      • To: result.brickRoadIndicator = Object.keys(result.allReportErrors ?? {}).length !== 0 || ReportUtils.transactionThreadHasViolations(report) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : '';
      • That way src/components/LHNOptionsList/OptionRowLHN.js should show the RBR
    • In ReportUtils.shouldReportBeInOptionList above if (isInGSDMode) { we’ll add the if in the snippet below to surface the iou reports with violations on the LHN
  • And let's use ReportUtils.reportHasViolations
    • In src/components/ReportActionItem/ReportPreview.js let's update the code so the hasErrors value takes into account the report violations const hasErrors = (hasReceipts && ReportUtils.hasMissingSmartscanFields(props.iouReportID)) || ReportUtils.reportHasViolations(props.iouReportID);
const transactionViolations = {};
Onyx.connect({
    key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
    callback: (violations, key) => {
        if (!key || !violations) {
            return;
        }

        const transactionID = CollectionUtils.extractCollectionItemID(key);
        transactionViolations[transactionID] = violations;
    },
});

const reportActions = {};
Onyx.connect({
    key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
    callback: (actions, key) => {
        if (!key || !actions) {
            return;
        }

        const reportID = CollectionUtils.extractCollectionItemID(key);
        reportActions[reportID] = actions;
    },
});
function transactionThreadHasViolations(report) {
    if (!permissions.canUseViolations()) {
        return false;
    }
    if (!report.parentReportActionID ?? 0) {
        return false;
    }
    const parentReportAction = lodashGet(reportActions, `${report.parentReportID}.${report.parentReportActionID}`);
    if (!parentReportAction) {
        return false;
    }
    const transactionID = parentReportAction['originalMessage']['IOUTransactionID'] ?? 0;
    if (!transactionID) {
        return false;
    }
    const reportID = parentReportAction['originalMessage']['IOUReportID'] ?? 0;
    if (!reportID) {
        return false;
    }
    if (!isCurrentUserSubmitter(reportID)) {
        return false;
    }
    return transactionHasViolation(transactionID);
}
function transactionHasViolation(transactionID) {
    const violations = lodashGet(transactionViolations, transactionID, []);
    return _.some(violations, violation => violation.type === 'violation');
}
function reportHasViolations(reportID) {
    let transactions = TransactionUtils.getAllReportTransactions(reportID);
    return _.some(transactions, (transaction) => transactionHasViolation(transaction.transactionID));
}
// Always show IOU reports with violations
if (isExpenseRequest(report) && transactionThreadHasViolations(report)) {
    return true;
}

Activity

  1. cead22 commented on Nov 9, 2023

    @cead22
    ContributorAuthor

    @lindboe @cdanwards can you please comment here so I can assign you?

  2. cdanwards commented on Nov 10, 2023

    @cdanwards
    Contributor

    Commenting for assignment

  3. melvin-bot commented on Nov 14, 2023

    @melvin-bot

    @cdanwards Whoops! This issue is 2 days overdue. Let's get this updated quick!

  4. cdanwards commented on Nov 15, 2023

    @cdanwards
    Contributor

    Beginning work on this now.

  5. melvin-bot commented on Nov 21, 2023

    @melvin-bot

    @cdanwards Huh... This is 4 days overdue. Who can take care of this?

  6. melvin-bot commented on Nov 23, 2023

    @melvin-bot

    @cdanwards Still overdue 6 days?! Let's take care of this!

  7. melvin-bot commented on Nov 27, 2023

    @melvin-bot

    @cdanwards 10 days overdue. I'm getting more depressed than Marvin.

  8. cdanwards commented on Nov 27, 2023

    @cdanwards
    Contributor

    Still working on this. Getting some clarification after ReportUtils got swapped to TS.

  9. 50 remaining items

  10. reopened this on Feb 23, 2024
  11. melvin-bot commented on Feb 23, 2024

    @melvin-bot
  12. cead22 commented on Feb 23, 2024

    @cead22
    ContributorAuthor

    @strepanier03 can you please handle payment to @situchan for the PR review, and please make it double the standard amount we pay for these. This was was a pretty complex review and this is something I offered @situchan last month to put the review at the top of the priority list. Thanks

  13. strepanier03 commented on Mar 1, 2024

    @strepanier03
    Contributor

    Will do @cead22!

  14. strepanier03 commented on Mar 1, 2024

    @strepanier03
    Contributor

    @situchan - An offer has been sent. I'll check later today to finish paying out and closing up.

  15. strepanier03 commented on Mar 4, 2024

    @strepanier03
    Contributor

    Paid and contract closed. Thanks everyone!

  16. changed the title [-][HOLD for payment 2024-01-28] Implement and use ReportUtils.transactionThreadHasViolations(report)[/-] [+][PAID] Implement and use ReportUtils.transactionThreadHasViolations(report)[/+] on Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionDailyKSv2EngineeringNewFeatureSomething to build that is a new item.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions