Skip to content

[Insights: Violations]: Expanding group & Suggested search - #97067

Open
nkdengineer wants to merge 17 commits into
Expensify:mainfrom
nkdengineer:fix/95859
Open

[Insights: Violations]: Expanding group & Suggested search#97067
nkdengineer wants to merge 17 commits into
Expensify:mainfrom
nkdengineer:fix/95859

Conversation

@nkdengineer

Copy link
Copy Markdown
Contributor

Explanation of Change

feat: Expanding group & Suggested search

Fixed Issues

$ #95859
PROPOSAL:

Tests

  • Suggested search
  1. Create a control workspace
  2. Enable rules
  3. Add a member
  4. Submit some expenses with various violations as the workspace owner and the member, with more expenses coming from the member
  5. Submit some expenses without violations
  6. As the workspace owner, open the Spend page
  7. Verify there is a suggested search under the Insights section called “Violations by submitter”, and it has the icon with a person and an eye
  8. Click on it
  9. Verify you see a table with columns From, Expenses, and Total
  10. Verify there is a down arrow next to Expenses meaning it is sorted by count of expenses descending
  11. Verify the count and total is correct for each user
  12. Verify the filters display “Date: Last month”
  13. Run the same test as an auditor
  • Expanding group
  1. Run the same setup as the manual tests for the section above
  2. Ensure one expense has multiple violations
  3. Click on a row for one user
  4. Verify it expands, shows a brief loader, and then displays a table of expenses for that user
  5. Verify the proper expenses are displayed
  6. Verify there is a Violations column and it contains the proper violation names, separated by commas for multiple violations
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

Same as test

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Screen.Recording.2026-07-27.at.14.32.35.mov
Android: mWeb Chrome
Screen.Recording.2026-07-27.at.14.25.08.mov
iOS: Native
Screen.Recording.2026-07-27.at.14.29.43.mov
iOS: mWeb Safari
Screen.Recording.2026-07-27.at.14.27.52.mov
MacOS: Chrome / Safari
Screen.Recording.2026-07-27.at.14.20.06.mov

@melvin-bot

melvin-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown

Hey, I noticed you changed src/languages/en.ts in a PR from a fork. For security reasons, translations are not generated automatically for PRs from forks.

If you want to automatically generate translations for other locales, an Expensify employee will have to:

  1. Look at the code and make sure there are no malicious changes.
  2. Run the Generate static translations GitHub workflow. If you have write access and the K2 extension, you can simply click: [this button]

Alternatively, if you are an external contributor, you can run the translation script locally with your own OpenAI API key. To learn more, try running:

npx ts-node ./scripts/generateTranslations.ts --help

Typically, you'd want to translate only what you changed by running npx ts-node ./scripts/generateTranslations.ts --compare-ref main

@nkdengineer nkdengineer changed the title feat: Expanding group & Suggested search [[Insights: Violations]: Expanding group & Suggested search Jul 27, 2026
@nkdengineer nkdengineer changed the title [[Insights: Violations]: Expanding group & Suggested search [Insights: Violations]: Expanding group & Suggested search Jul 27, 2026
@nkdengineer

Copy link
Copy Markdown
Contributor Author

@neil-marcellini From the doc, I added a violation column. But I think it's unnecessary as we displayed the violation below each transaction like this. What do you think?

Screenshot 2026-07-27 at 14 34 30

@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/CONST/index.ts 94.81% <ø> (ø)
...archList/ListItem/TransactionGroupListExpanded.tsx 67.69% <100.00%> (ø)
.../TransactionListItem/TransactionListItemNarrow.tsx 0.00% <ø> (ø)
...em/TransactionListItem/TransactionListItemWide.tsx 0.00% <ø> (ø)
src/components/Search/SearchTableHeader.tsx 50.57% <ø> (ø)
...ents/TransactionItemRow/TransactionItemRowWide.tsx 98.38% <100.00%> (+0.02%) ⬆️
src/hooks/useSearchShouldCalculateTotals.ts 100.00% <ø> (ø)
src/hooks/useSearchTypeMenuSections.ts 93.44% <ø> (ø)
src/libs/ReportActionsUtils.ts 78.56% <ø> (ø)
src/libs/Violations/ViolationsUtils.ts 79.74% <100.00%> (+0.07%) ⬆️
... and 3 more
... and 18 files with indirect coverage changes

@nkdengineer
nkdengineer marked this pull request as ready for review July 27, 2026 07:51
@nkdengineer
nkdengineer requested review from a team as code owners July 27, 2026 07:51
@melvin-bot
melvin-bot Bot requested review from cretadn22 and removed request for a team July 27, 2026 07:51
@melvin-bot

melvin-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown

@cretadn22 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot
melvin-bot Bot requested review from heyjennahay and removed request for a team July 27, 2026 07:51

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d43b90fa27

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/libs/SearchUIUtils.ts Outdated
Comment thread src/libs/SearchUIUtils.ts
const isEligibleForTopSpendersSuggestion = isGroupPolicyEligible && (isAdmin || isAuditor || isUserApprover) && memberCount >= 2;
const isEligibleForTopCategoriesSuggestion = isGroupPolicyEligible && policy.areCategoriesEnabled === true;
const isEligibleForTopMerchantsSuggestion = isGroupPolicyEligible;
const isEligibleForViolationsBySubmitterSuggestion = isGroupPolicyEligible && (isAdmin || isAuditor) && arePolicyRulesEnabled(policy) && memberCount >= 2;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Include migrated category rules when checking eligibility

For migrated Control workspaces where areRulesEnabled is undefined but Classic category rules exist, this call always treats rules as disabled because it does not pass policy categories. arePolicyRulesEnabled() explicitly relies on hasAnyCategoryRules(policyCategories) for that migration case, so admins and auditors of these workspaces never see the new suggestion despite having applicable submitted violations.

Useful? React with 👍 / 👎.

Comment thread src/libs/SearchUIUtils.ts Outdated
Comment thread src/libs/SearchUIUtils.ts Outdated
@github-actions

Copy link
Copy Markdown
Contributor

🚧 dubielzyk-expensify has triggered a test Expensify/App build. You can view the workflow run here.

@github-actions

This comment has been minimized.

@dubielzyk-expensify

Copy link
Copy Markdown
Contributor

I'm seeing the LHN but not any data even though there is a violation. Is it because it's myself?

CleanShot.2026-07-27.at.18.28.27.mp4

@nkdengineer

nkdengineer commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

@dubielzyk-expensify You can check the transaction's date. Because the violation suggested search filter is for the date last month, we need to update the date to June

@dubielzyk-expensify

Copy link
Copy Markdown
Contributor

Even when I remove it I don't get any though?

CleanShot 2026-07-27 at 18 38 54@2x

@nkdengineer

Copy link
Copy Markdown
Contributor Author

@dubielzyk-expensify Can you try to submit the expense report above?

@neil-marcellini
neil-marcellini self-requested a review July 27, 2026 15:36
@neil-marcellini

neil-marcellini commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

@dubielzyk-expensify to be clear the violations only display for expenses that have been submitted because that's what the search is looking for.

Also, I'm noticing that we never display the "Violations" column on mobile, or the narrow layout. Currently the narrow layout for a transaction item on the search page has a fixed card that doesn't include all columns.

I think we should update it so the narrow layout on the suggest search shows the same key info as the wide layout.

image image

The group item should display "From, Expenses, Total" and the transaction items should display the "Violations" column, maybe instead of the current violations? We kind of missed designing the UI for the narrow view during the design doc. What do you think. Looping in @trjExpensify as well.

@neil-marcellini neil-marcellini left a comment

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.

Looking pretty good, but a couple of fixes are needed. Please also add unit tests for these functions, as the design doc mentions: buildQueryStringFromFilterFormValues, getSuggestedSearches, getSuggestedSearchesVisibility.

Comment thread src/CONST/index.ts Outdated
Comment thread src/styles/utils/index.ts Outdated
Comment thread src/libs/SearchUIUtils.ts Outdated
@dubielzyk-expensify

Copy link
Copy Markdown
Contributor

Ahh, I see. It worked now that's it submitted.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7f502aaac8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/components/Search/SearchTableHeader.tsx
@trjExpensify

Copy link
Copy Markdown
Contributor

Why "Expense too old" for the name of this one, and not either "Date older than X days" or "Max expense age" which are elsewhere in the product when referring to this violation?

image image

Also, @neil-marcellini it seems like with the date we're filtering this expense out but it was actually submitted this month? 🤔

image image

@neil-marcellini

Copy link
Copy Markdown
Contributor

Both "Itemized receipt required" and "Receipt required" violations are displaying at the same time. We should only show one of them

I'm not sure about this one, I think it's ok to display both since they are different.

@nkdengineer Using a shorter name in the violation column is fine, but the number of violation and violation type should match the red violation text

I don't think this is necessarily a problem. The Violations column is supposed to show every unique violation that was present at submit time, which might not match the current violations on the expense.

@trjExpensify

Copy link
Copy Markdown
Contributor

I'm not sure about this one, I think it's ok to display both since they are different.

It does seem like there's some kind of prioritisation logic @neil-marcellini for either the itemised receipt or receipt required violation depending on the limit amounts set, so it kinda' makes sense to me it reflects which one was flagged and ignored:

image

@neil-marcellini

Copy link
Copy Markdown
Contributor

Why "Expense too old" for the name of this one, and not either "Date older than X days" or "Max expense age" which are elsewhere in the product when referring to this violation?

Yes I agree it should be something like "Date older than max expense age".

Also, @neil-marcellini it seems like with the date we're filtering this expense out but it was actually submitted this month? 🤔

The date filter for the query operates based on the expense itself, not when the report was submitted, so that the date filter behavior matches the behavior when it's used for other expense searches.

@trjExpensify

Copy link
Copy Markdown
Contributor

The date filter for the query operates based on the expense itself, not when the report was submitted, so that the date filter behavior matches the behavior when it's used for other expense searches.

Yeah, I understand why it's happening, but I'm questioning if using expense date is the right call for these canned suggested searches. We have Submitted date at our disposal after all. It's probably pretty easy to change later, it just dawned on me when looking at it.

@neil-marcellini

Copy link
Copy Markdown
Contributor

The date filter for the query operates based on the expense itself, not when the report was submitted, so that the date filter behavior matches the behavior when it's used for other expense searches.

Yeah, I understand why it's happening, but I'm questioning if using expense date is the right call for these canned suggested searches. We have Submitted date at our disposal after all. It's probably pretty easy to change later, it just dawned on me when looking at it.

Yeah it probably does make more sense to use the submitted date, so we should swap it to submitted:last-month instead of the plain date filter. Maybe we should spin up issues to do that before launching release 1?

@trjExpensify

Copy link
Copy Markdown
Contributor

Yeah, though I guess for violations by approver, the approved date is not helpful for the middle approver cases (i.e forwarded). 🤔

@nkdengineer

Copy link
Copy Markdown
Contributor Author

@nkdengineer We introduced a new Violations column, but the data in this column appears empty on the Expense page. The data only appear in "Violations by submitter" table

@neil-marcellini Should Violations column appear on Expense page? Or should it only appear when Has:Submitted Violation

@neil-marcellini

Copy link
Copy Markdown
Contributor

@nkdengineer We introduced a new Violations column, but the data in this column appears empty on the Expense page. The data only appear in "Violations by submitter" table

@neil-marcellini Should Violations column appear on Expense page? Or should it only appear when Has:Submitted Violation

Yes it should only appear when the data is present, such as when that filter is applied.

@nkdengineer

Copy link
Copy Markdown
Contributor Author

@cretadn22 Ready for another review.

@cretadn22

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2f31cf65dc

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/libs/SearchUIUtils.ts
return translate(`violations.shortName.${violationName}`);
}

return violationName;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Add short labels for all known submitted violations

When a submitted snapshot contains current violation names omitted from SUBMITTED_TRANSACTION_VIOLATION_SHORT_NAMES (tagOutOfPolicy, overLimitAttendee, or customRules), this fallback returns the backend enum and TextCell displays it directly. Fresh evidence after the prior translation finding is that these are still valid CONST.VIOLATIONS entries but were not added to the short-name set, so users can still see camelCase identifiers instead of localized labels; please add parameter-free labels or otherwise translate every known violation before falling back only for truly unknown names.

Useful? React with 👍 / 👎.

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.

@neil-marcellini Can you give the sort name for these violations?

@cretadn22

Copy link
Copy Markdown
Contributor

tagOutOfPolicy is not translated

Screenshot 2026-08-02 at 11 43 06

Comment thread src/languages/de.ts
topSpenders: 'Höchste Ausgaben',
topCategories: 'Topkategorien',
topMerchants: 'Top-Händler',
violationsBySubmitter: 'Violations by submitter',

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.

Untranslated copy

Comment thread src/libs/SearchUIUtils.ts
Comment on lines +5064 to +5074
function getSubmittedViolationDisplayName(violationName: string, translate: LocalizedTranslate): string {
if (!isValidViolationName(violationName)) {
return violationName;
}

if (isSubmittedTransactionViolationShortName(violationName)) {
return translate(`violations.shortName.${violationName}`);
}

return violationName;
}

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.

Suggested change
function getSubmittedViolationDisplayName(violationName: string, translate: LocalizedTranslate): string {
if (!isValidViolationName(violationName)) {
return violationName;
}
if (isSubmittedTransactionViolationShortName(violationName)) {
return translate(`violations.shortName.${violationName}`);
}
return violationName;
}
function getSubmittedViolationDisplayName(violationName: string, translate: LocalizedTranslate): string {
return isSubmittedTransactionViolationShortName(violationName) ? translate(`violations.shortName.${violationName}`) : violationName;
}

@cretadn22

cretadn22 commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

@neil-marcellini Should expenses be hidden under "Violations by submitter" if a user retracts the expense or fixes the violation?

@nkdengineer I think the expense should be hidden in the above case, but currently, it is not.

@cretadn22

Copy link
Copy Markdown
Contributor

The expense count is displaying incorrectly. In my test, it shows 16 expenses, but the list only contains 10.

Screen.Recording.2026-08-02.at.11.57.41.mov

@cretadn22

Copy link
Copy Markdown
Contributor

@neil-marcellini In this case, the Violations column displays "Receipt required," which is confusing since the receipt has already been uploaded

Screen.Recording.2026-08-02.at.12.00.12.mov

@nkdengineer

Copy link
Copy Markdown
Contributor Author

@nkdengineer I think the expense should be hidden in the above case, but currently, it is not.

@cretadn22 If it's correct, we need to fix this from the backend site as it's the result from backend.

@trjExpensify

Copy link
Copy Markdown
Contributor

@neil-marcellini In this case, the Violations column displays "Receipt required," which is confusing since the receipt has already been uploaded

Yeah, so violations reporting isn't about "current" violations. It's about highlighting bottlenecks and inefficiencies in the process at the time of submission and at the time of approval - whether or not that is rectified later. For example, if an employee submitted an expense with a missing receipt, that would hold up the process to approve, potentially for weeks. If we didn't include "violations that were later cleared" the company would never identify that employee as being a bottleneck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants