Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
36de179
[Insights polish] Replace the Top violations donut with a table
mhawryluk Nov 13, 2026
67748a8
Merge branch 'main' into insights/top-violations-table
mhawryluk Nov 16, 2026
987a22c
Refactor
mhawryluk Nov 16, 2026
0a193dd
Modify the skeleton to more closely match the table
mhawryluk Nov 16, 2026
8062bdd
Use svg for the average line instead of CSS
mhawryluk Nov 16, 2026
a5e1092
Use existing variables for column widths
mhawryluk Nov 16, 2026
affd8ce
Style fix + rename
mhawryluk Nov 16, 2026
f8a35e3
Add translations
mhawryluk Nov 16, 2026
aff9842
Don't show "new" when previous period wasn't tracked
mhawryluk Nov 16, 2026
7fc3478
Small refactor
mhawryluk Nov 16, 2026
6696b0a
Move New badge into InsightsChangeBadge
mhawryluk Nov 16, 2026
7a9f225
Rescept full width chart's position in the spec when rendering it
mhawryluk Nov 16, 2026
9e81b8d
Update tests
mhawryluk Nov 16, 2026
0abd2c2
Add RANKING_TABLE_COLUMN object to remove magic numbers
mhawryluk Nov 16, 2026
4aeddb2
Render the average line above the whole table and match its parameters
mhawryluk Nov 16, 2026
e3a5f72
Bring back the previous average line style on mobile
mhawryluk Nov 16, 2026
d94260e
Merge branch 'main' into insights/top-violations-table
mhawryluk Nov 17, 2026
f1d0d66
Replace "New" badge with a dash for violations not appearing in previous
mhawryluk Nov 17, 2026
6c027c5
Move the sole narrow chart in supporting grid to the bottom of the page
mhawryluk Nov 17, 2026
e02214b
Revert GitHub Actions files rewritten by the pre-commit hook
mhawryluk Nov 17, 2026
732554e
Revert unrelated changes
mhawryluk Nov 17, 2026
22d776c
Fix formatting
mhawryluk Nov 17, 2026
ffb1cfb
Add violation filter to the Top violation's drill-in query
mhawryluk Nov 17, 2026
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
1 change: 1 addition & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10636,6 +10636,7 @@ const CONST = {
EFFICIENCY: 'insightsEfficiency',
COMPLIANCE: 'insightsCompliance',
},
NO_CHANGE_PLACEHOLDER: '—',
GRAPH: {
SPEND_OVER_TIME: 'spendOverTime',
VIOLATIONS_OVER_TIME: 'violationsOverTime',
Expand Down
8 changes: 7 additions & 1 deletion src/components/Charts/utils/formatChartCount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ const COUNT_TRANSLATION_KEYS = {
[CONST.SEARCH.CHART_COUNT_DIMENSION.REPORT]: 'iou.reportCount',
} as const satisfies Record<SearchChartCountDimension, string>;

/** Header of a column listing counts, e.g. "Expenses" */
const COUNT_COLUMN_TITLE_KEYS = {
[CONST.SEARCH.CHART_COUNT_DIMENSION.EXPENSE]: 'common.expenses',
[CONST.SEARCH.CHART_COUNT_DIMENSION.REPORT]: 'common.reports',
} as const satisfies Record<SearchChartCountDimension, string>;

/**
* Names a count of expenses or reports in the viewer's locale, e.g. "1,234.5 expenses".
* The number is formatted here and passed to the translation rather than left to it, because locales whose `one` plural category also covers 0 and fractions
Expand All @@ -22,4 +28,4 @@ function formatChartCount(count: number, countDimension: SearchChartCountDimensi
}

export default formatChartCount;
export {MAX_COUNT_FRACTION_DIGITS};
export {COUNT_COLUMN_TITLE_KEYS, MAX_COUNT_FRACTION_DIGITS};
3 changes: 2 additions & 1 deletion src/components/Charts/utils/formatTooltipComparison.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import VictoryTheme from '@components/Charts/VictoryTheme';

import {formatPercentOfTotal} from '@libs/PercentageUtils';

import CONST from '@src/CONST';
import type Locale from '@src/types/onyx/Locale';

import type {NonEmptyTuple} from 'type-fest';
Expand Down Expand Up @@ -44,7 +45,7 @@ type TooltipComparison = {
/** Formats how much the primary value rose or fell relative to the compared one, as a percentage */
function formatChangePercentage(primaryValue: number, comparedValue: number, locale: Locale | undefined): string {
if (comparedValue === 0) {
return '—';
return CONST.INSIGHTS.NO_CHANGE_PLACEHOLDER;
}

const difference = primaryValue - comparedValue;
Expand Down
10 changes: 8 additions & 2 deletions src/components/Search/buildChartSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,14 @@ const AVERAGE_LABEL_KEYS: Partial<Record<SearchGroupBy, TranslationPaths>> = {
[CONST.SEARCH.GROUP_BY.FROM]: 'insightsPage.compare.allSpenderAverage',
[CONST.SEARCH.GROUP_BY.MERCHANT]: 'insightsPage.compare.allMerchantAverage',
[CONST.SEARCH.GROUP_BY.CATEGORY]: 'insightsPage.compare.allCategoryAverage',
[CONST.SEARCH.GROUP_BY.VIOLATION]: 'insightsPage.compare.allViolationAverage',
};

/** Returns the label naming the average a chart grouped by `groupBy` is compared against */
function getAverageLabelKey(groupBy: SearchGroupBy): TranslationPaths {
return AVERAGE_LABEL_KEYS[groupBy] ?? 'insightsPage.compare.average';
}

type BuildChartSeriesParams = {
/** Grouped search results, in the order the search returned them */
data: GroupedItem[];
Expand Down Expand Up @@ -321,7 +327,7 @@ function buildChartSeries({
const primarySeries: ChartSeries = {key: CHART_SERIES_KEY.PRIMARY, label: periods && formatDates(periods.primary, dateFnsLocale)};
const comparisonSeries: ChartSeries | undefined =
averageValue !== undefined
? {key: CHART_SERIES_KEY.COMPARISON, label: translate(AVERAGE_LABEL_KEYS[groupBy] ?? 'insightsPage.compare.average'), isAverage: true}
? {key: CHART_SERIES_KEY.COMPARISON, label: translate(getAverageLabelKey(groupBy)), isAverage: true}
: comparedRows && {key: CHART_SERIES_KEY.COMPARISON, color: comparedRows.color, label: periods && formatDates(periods.comparison, dateFnsLocale)};

return {
Expand All @@ -344,5 +350,5 @@ function buildChartSeries({
};
}

export {buildChartSeries, getSliceColorsByDataIndex, isChartAverage, CHART_SERIES_KEY};
export {buildChartSeries, getAverageLabelKey, getSliceColorsByDataIndex, isChartAverage, CHART_SERIES_KEY};
export type {ChartAverage, ChartComparison, SearchChartModel};
3 changes: 1 addition & 2 deletions src/components/Search/chartGroupByConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ const CHART_GROUP_BY_CONFIG: Record<SearchGroupBy, ChartGroupByConfig> = {
[CONST.SEARCH.GROUP_BY.VIOLATION]: {
titleIconName: 'Exclamation',
getLabel: (item: GroupedItem) => (item.groupedBy === CONST.SEARCH.GROUP_BY.VIOLATION ? item.formattedViolation : ''),
// Search has no violation type filter, so a clicked violation opens the chart's whole query
getFilterQuery: () => '',
getFilterQuery: (item: GroupedItem) => (item.groupedBy === CONST.SEARCH.GROUP_BY.VIOLATION ? `${CONST.SEARCH.SYNTAX_FILTER_KEYS.VIOLATION}:${item.violation}` : ''),
},
[CONST.SEARCH.GROUP_BY.PAID_BY]: {
titleIconName: 'Users',
Expand Down
4 changes: 4 additions & 0 deletions src/languages/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,9 @@ const translations: TranslationDeepObject<typeof en> = {
allMerchantAverage: 'Durchschnitt über alle Händler',
allCategoryAverage: 'Durchschnitt aller Kategorien',
averageValue: (amount: string) => `${amount} durchschnittl.`,
allViolationAverage: 'Durchschnitt aller Verstöße',
noChange: 'Keine Änderung',
percentChange: '% Änderung',
},
compliance: 'Compliance',
runningTotal: 'Laufende Summe',
Expand All @@ -1272,6 +1275,7 @@ const translations: TranslationDeepObject<typeof en> = {
longestToSubmit: 'Am längsten bis zur Einreichung',
slowestToApprove: 'Am langsamsten bei der Genehmigung',
mostTimeToPay: 'Längste Zahlungsfrist',
share: 'Anteil',
averageDays: 'Durchschnittliche Tage',
},
allSettingsScreen: {
Expand Down
4 changes: 4 additions & 0 deletions src/languages/el.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,9 @@ const translations: TranslationDeepObject<typeof en> = {
allMerchantAverage: 'Μέσος όρος όλων των εμπόρων',
allCategoryAverage: 'Μέσος όρος όλων των κατηγοριών',
averageValue: (amount: string) => `${amount} κατά μέσο όρο`,
allViolationAverage: 'Μέσος όρος όλων των παραβάσεων',
noChange: 'Χωρίς αλλαγή',
percentChange: '% μεταβολή',
},
compliance: 'Συμμόρφωση',
runningTotal: 'Τρέχον σύνολο',
Expand All @@ -1318,6 +1321,7 @@ const translations: TranslationDeepObject<typeof en> = {
longestToSubmit: 'Περισσότερος χρόνος για υποβολή',
slowestToApprove: 'Πιο αργοί στην έγκριση',
mostTimeToPay: 'Περισσότερος χρόνος για πληρωμή',
share: 'Μερίδιο',
averageDays: 'Μέσος όρος ημερών',
},
allSettingsScreen: {
Expand Down
5 changes: 5 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,8 @@ const translations = {
topViolations: 'Top violations',
violationsBySubmitter: 'Violations by submitter',
violationsByApprover: 'Violations by approver',
// @context Column header for each group's portion of the total, as a percentage. A noun, not the verb "to share".
share: 'Share',
efficiency: 'Efficiency',
workflowEfficiency: 'Workflow efficiency',
averageProcessingTime: 'Average processing time',
Expand All @@ -1400,12 +1402,15 @@ const translations = {
allSpenderAverage: 'All-spender average',
allMerchantAverage: 'All-merchant average',
allCategoryAverage: 'All-category average',
allViolationAverage: 'All-violation average',
averageValue: (amount: string) => `${amount} avg`,
dayLabel: (day?: number) => (day === undefined ? 'Day' : `Day ${day}`),
weekLabel: (week?: number) => (week === undefined ? 'Week' : `Week ${week}`),
monthLabel: (month?: number) => (month === undefined ? 'Month' : `Month ${month}`),
quarterLabel: (quarter?: number) => (quarter === undefined ? 'Quarter' : `Quarter ${quarter}`),
yearLabel: (year?: number) => (year === undefined ? 'Year' : `Year ${year}`),
noChange: 'No change',
percentChange: '% change',
increase: (percentage: string) => `Up ${percentage}`,
decrease: (percentage: string) => `Down ${percentage}`,
},
Expand Down
4 changes: 4 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,9 @@ const translations: TranslationDeepObject<typeof en> = {
allMerchantAverage: 'Promedio de todos los comercios',
allCategoryAverage: 'Promedio de todas las categorías',
averageValue: (amount: string) => `${amount} prom de media`,
allViolationAverage: 'Media de todas las infracciones',
noChange: 'Sin cambios',
percentChange: '% de cambio',
},
compliance: 'Cumplimiento',
runningTotal: 'Total acumulado',
Expand All @@ -1266,6 +1269,7 @@ const translations: TranslationDeepObject<typeof en> = {
longestToSubmit: 'Más lento en enviar',
slowestToApprove: 'Más lento en aprobar',
mostTimeToPay: 'Más tiempo para pagar',
share: 'Porcentaje de participación',
averageDays: 'Días promedio',
},
allSettingsScreen: {
Expand Down
4 changes: 4 additions & 0 deletions src/languages/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,9 @@ const translations: TranslationDeepObject<typeof en> = {
allMerchantAverage: 'Moyenne tous marchands',
allCategoryAverage: 'Moyenne toutes catégories',
averageValue: (amount: string) => `${amount} en moyenne`,
allViolationAverage: 'Moyenne de toutes les infractions',
noChange: 'Aucun changement',
percentChange: '% de changement',
},
compliance: 'Conformité',
runningTotal: 'Total cumulé',
Expand All @@ -1279,6 +1282,7 @@ const translations: TranslationDeepObject<typeof en> = {
longestToSubmit: 'Le plus long à soumettre',
slowestToApprove: 'Plus lent à approuver',
mostTimeToPay: 'Délai de paiement le plus long',
share: 'Part de la part totale (%)',
averageDays: 'Jours en moyenne',
},
allSettingsScreen: {
Expand Down
4 changes: 4 additions & 0 deletions src/languages/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,9 @@ const translations: TranslationDeepObject<typeof en> = {
allMerchantAverage: 'Media tutti gli esercenti',
allCategoryAverage: 'Media di tutte le categorie',
averageValue: (amount: string) => `${amount} in media`,
allViolationAverage: 'Media di tutte le violazioni',
noChange: 'Nessuna modifica',
percentChange: '% variazione',
},
compliance: 'Conformità',
runningTotal: 'Totale progressivo',
Expand All @@ -1275,6 +1278,7 @@ const translations: TranslationDeepObject<typeof en> = {
longestToSubmit: 'Più lungo per l’invio',
slowestToApprove: 'I più lenti ad approvare',
mostTimeToPay: 'Tempo massimo per pagare',
share: 'Quota%',
averageDays: 'Giorni medi',
},
allSettingsScreen: {
Expand Down
4 changes: 4 additions & 0 deletions src/languages/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,9 @@ const translations: TranslationDeepObject<typeof en> = {
allMerchantAverage: '全加盟店の平均',
allCategoryAverage: '全カテゴリ平均',
averageValue: (amount: string) => `平均 ${amount}`,
allViolationAverage: 'すべての違反の平均',
noChange: '変更なし',
percentChange: '% 変化',
},
compliance: 'コンプライアンス',
runningTotal: '累計合計',
Expand All @@ -1260,6 +1263,7 @@ const translations: TranslationDeepObject<typeof en> = {
longestToSubmit: '提出まで最も長い順',
slowestToApprove: '承認が最も遅い',
mostTimeToPay: '支払いまで最も時間がかかる',
share: 'シェア割合',
averageDays: '平均日数',
},
allSettingsScreen: {
Expand Down
4 changes: 4 additions & 0 deletions src/languages/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,9 @@ const translations: TranslationDeepObject<typeof en> = {
allMerchantAverage: 'Gemiddelde voor alle handelaren',
allCategoryAverage: 'Gemiddelde voor alle categorieën',
averageValue: (amount: string) => `${amount} gem.`,
allViolationAverage: 'Gemiddelde over alle overtredingen',
noChange: 'Geen wijziging',
percentChange: '% wijziging',
},
compliance: 'Naleving',
runningTotal: 'Doorlopend totaal',
Expand All @@ -1271,6 +1274,7 @@ const translations: TranslationDeepObject<typeof en> = {
longestToSubmit: 'Langste om in te dienen',
slowestToApprove: 'Traagst om goed te keuren',
mostTimeToPay: 'Meeste tijd om te betalen',
share: 'Aandeel',
averageDays: 'Gemiddeld aantal dagen',
},
allSettingsScreen: {
Expand Down
4 changes: 4 additions & 0 deletions src/languages/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,9 @@ const translations: TranslationDeepObject<typeof en> = {
allMerchantAverage: 'Średnia dla wszystkich sprzedawców',
allCategoryAverage: 'Średnia dla wszystkich kategorii',
averageValue: (amount: string) => `średnio ${amount}`,
allViolationAverage: 'Średnia wszystkich naruszeń',
noChange: 'Bez zmian',
percentChange: '% zmiana',
},
compliance: 'Zgodność',
runningTotal: 'Suma narastająco',
Expand All @@ -1298,6 +1301,7 @@ const translations: TranslationDeepObject<typeof en> = {
longestToSubmit: 'Najdłużej oczekujące na wysłanie',
slowestToApprove: 'Najwolniejszy w zatwierdzaniu',
mostTimeToPay: 'Najdłuższy czas na zapłatę',
share: 'Udział',
averageDays: 'Średnia liczba dni',
},
allSettingsScreen: {
Expand Down
4 changes: 4 additions & 0 deletions src/languages/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,9 @@ const translations: TranslationDeepObject<typeof en> = {
allMerchantAverage: 'Média de todos os estabelecimentos',
allCategoryAverage: 'Média de todas as categorias',
averageValue: (amount: string) => `${amount} média`,
allViolationAverage: 'Média de todas as violações',
noChange: 'Sem alteração',
percentChange: '% de mudança',
},
compliance: 'Conformidade',
runningTotal: 'Total acumulado',
Expand All @@ -1274,6 +1277,7 @@ const translations: TranslationDeepObject<typeof en> = {
longestToSubmit: 'Mais demorados para enviar',
slowestToApprove: 'Mais lento para aprovar',
mostTimeToPay: 'Maior prazo para pagar',
share: 'Participação',
averageDays: 'Média de dias',
},
allSettingsScreen: {
Expand Down
4 changes: 4 additions & 0 deletions src/languages/zh-hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,9 @@ const translations: TranslationDeepObject<typeof en> = {
allMerchantAverage: '所有商户平均值',
allCategoryAverage: '所有类别平均值',
averageValue: (amount: string) => `${amount} 平均`,
allViolationAverage: '所有违规平均值',
noChange: '无更改',
percentChange: '百分比变动',
},
compliance: '合规',
runningTotal: '累计总额',
Expand All @@ -1221,6 +1224,7 @@ const translations: TranslationDeepObject<typeof en> = {
longestToSubmit: '提交所用时间最长',
slowestToApprove: '审批最慢',
mostTimeToPay: '最长付款时间',
share: '占比',
averageDays: '平均天数',
},
allSettingsScreen: {
Expand Down
43 changes: 43 additions & 0 deletions src/pages/Insights/InsightsChangeBadge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import Badge from '@components/Badge';

import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';

import type {StyleProp, ViewStyle} from 'react-native';

import React from 'react';
import {View} from 'react-native';

type InsightsChangeBadgeProps = {
text: string;

isIncrease: boolean;

style?: StyleProp<ViewStyle>;
};

/** Badge showing how a value changed, with an arrow when it went up or down */
function InsightsChangeBadge({text, isIncrease, style}: InsightsChangeBadgeProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const icons = useMemoizedLazyExpensifyIcons(['ArrowUpLong', 'ArrowDownLong']);

return (
<View
style={style}
accessible
accessibilityLabel={translate(isIncrease ? 'insightsPage.compare.increase' : 'insightsPage.compare.decrease', text)}
>
<Badge
text={text}
icon={isIncrease ? icons.ArrowUpLong : icons.ArrowDownLong}
error={isIncrease}
success={!isIncrease}
badgeStyles={styles.ml0}
/>
</View>
);
}

export default InsightsChangeBadge;
Loading
Loading