Skip to content

[NoQA] [Insights] Draw previous period as the charts’ second series - #101874

Closed
mhawryluk wants to merge 32 commits into
Expensify:mainfrom
software-mansion-labs:insights/compare-previous-period
Closed

mhawryluk wants to merge 32 commits into
Expensify:mainfrom
software-mansion-labs:insights/compare-previous-period

Conversation

@mhawryluk

@mhawryluk mhawryluk commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

Explanation of Change

Fixed Issues

$ #100664
PROPOSAL: N/A

Tests

Offline tests

QA Steps

No tests.

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
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

@melvin-bot

melvin-bot Bot commented Sep 22, 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 bun ./scripts/generateTranslations.ts --help

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

@truph01

truph01 commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

@mhawryluk Could you merge main since the #101218 has been merged?

mhawryluk and others added 2 commits September 29, 2026 15:28
@mhawryluk
mhawryluk force-pushed the insights/compare-previous-period branch from 0d7b801 to ff14910 Compare September 29, 2026 13:37
@mhawryluk

Copy link
Copy Markdown
Member Author

@MelvinBot review

@MelvinBot

Copy link
Copy Markdown
Contributor

Review

I found 3 bugs and 2 smaller issues. The date-range math, grouped-bar geometry, y-domain, and drill-down ranges look correct.

Bugs

  1. Previous-period buckets without a current-period match are dropped. Rows are built only from primaryRows, and the comparison value is looked up by pairing key. A bucket that exists only in the previous period is never drawn. buildChartSeries.ts:248-262

    • On Oct 3, "This month" grouped by week has one bucket, so the September line shows one point and loses the rest of September.
    • With an empty current period, the widget shows the empty state even when the previous period has data.
    • The "pairs time buckets by their position" test passes in a previous Q2 value that never reaches the output, so the test locks in this behavior.
  2. Line dots are no longer darker than the line. getDarkerShade finds the first color key with a matching hex. green (#03D47C) comes before green400 in colors.ts. It has no number suffix, so the function returns the same color. The Search line chart and the Insights primary line now draw green400 dots on a green400 line, while the comparison line gets darker dots. VictoryTheme.ts:50-56

  3. Concierge HTML bar tooltips show a trailing bullet. The single-row branch always renders `${title} • ${getRowContent(row)}`. Bars with no currency pass an empty amount and no label, so the tooltip reads "Q1 • ". Before this PR, it read "Q1". ChartTooltip.tsx:110

Smaller issues

  • "Prior 1 months". A custom range of one whole month (for example, Mar 1–31) gives monthCount = 1. priorMonths and priorDays need plural forms. insightsCompare.ts:121
  • Horizontal bar thickness can go stale. barThickness now depends on series.length, but it updates only in handleChartBoundsChange. If you turn compare off, the bars redraw thin, but hit-testing and the tooltip still use the thicker paired-bar layout. HorizontalBarChartContent.tsx:197-212
Nits
  • InsightsChartWidget.tsx:69 switches pie to bar based on whether comparison exists, so a compared pie shows a pie skeleton while loading, then flips to bars. Switch based on "is comparing" instead.
  • ChartLegend.tsx:30 uses an inline {backgroundColor} style. Use StyleUtils.getBackgroundColorStyle, as PieChartContent does.
  • ChartTooltip uses key={row.label}, and label is optional. Unlabeled rows would get duplicate keys and render "undefined • $X".
  • The Skia mockAddedRRects mock in tests/unit/components/Charts/utils.test.ts is never asserted on.
  • No tests cover getDarkerShade, multi-row useTooltipData, or a one-month custom range.
  • useInsightsChartComparison.ts and ChartLegend.tsx have no file-header comment.
Open questions (backend)
  • Labels, bucket pairing, and drill-down dates all assume the backend computes the previous period the same way as resolveComparisonWindows. If it computes "Year to date" or custom ranges differently, bars pair with the wrong buckets.
  • If GetInsights applies the chart limit to the previous-period ranking, a current top-10 member who ranked 11th or lower last period shows a previous value of 0.

view run

@mhawryluk

Copy link
Copy Markdown
Member Author

Splitting this into multiple PRs for easier testing and review.

  1. Support multiple series in chart data - just data structure changes, no visual changes, we'll just test if the single-series charts still work fine: [Insights] Support multiple series in chart data #103754
  2. Draw Average mode baseline on Spend over time (not included in this original PR)
  3. Draw Previous period for Spend over time
  4. Draw multi-series bar charts (Previous period and Average)

@mhawryluk mhawryluk closed this Oct 12, 2026
@truph01

truph01 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

@mhawryluk Do we need to create sub-issues in #100664 to track the work implemented in each PR?

@mhawryluk

Copy link
Copy Markdown
Member Author

@mhawryluk Do we need to create sub-issues in #100664 to track the work implemented in each PR?

sure, we can

@MelvinBot create an issue for each of these points as sub-issues of #100664, assign the users from the parent issue to each of them:

  1. Support multiple series in chart data
  2. Draw Average mode baseline on Spend over time
  3. Draw Previous period for Spend over time
  4. Draw multi-series bar charts

@MelvinBot

Copy link
Copy Markdown
Contributor

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.

3 participants