Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use error prop for violations for consistent styling #34303

Merged
merged 41 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
a4844ce
feat(Violations): create useMoneyRequestViewErrors and move violation…
trevor-coleman Jan 10, 2024
67b0987
Merge remote-tracking branch 'upstream/main' into 32594-update-style-…
trevor-coleman Jan 10, 2024
6dc9f5c
feat(Violations): move hasViolations into useMoneyRequestViewErrors, …
trevor-coleman Jan 10, 2024
36b7dbf
feat(Violations): add comment
trevor-coleman Jan 10, 2024
02fe40d
feat(Violations): add comment
trevor-coleman Jan 11, 2024
d3fecfc
feat(Violations): move getErrorForField into MoneyRequestView
trevor-coleman Jan 11, 2024
c19d1a8
Merge branch 'cdanwards/violations/transaction-thread-violations' int…
trevor-coleman Jan 15, 2024
e12dc9f
feat(Violations): fix import
trevor-coleman Jan 15, 2024
32efefc
feat(Violations): update translation params to match violation data o…
trevor-coleman Jan 15, 2024
70e45a8
feat(Violations): change param names to match violation data prop
trevor-coleman Jan 15, 2024
df51b44
feat(Violations): change param names to match violation data prop
trevor-coleman Jan 15, 2024
394caca
feat(Violations): fixes
trevor-coleman Jan 15, 2024
b8b7b18
Merge remote-tracking branch 'upstream/main' into 32594-update-style-…
trevor-coleman Jan 18, 2024
2a624f9
feat(Violations): filter violations by type
trevor-coleman Jan 22, 2024
b80bcdd
Merge remote-tracking branch 'upstream/main' into 32594-update-style-…
trevor-coleman Jan 22, 2024
e37a63a
feat(Violations): fix dependency array
trevor-coleman Jan 22, 2024
ef959ef
feat(Violations): handle default case for missing tag
trevor-coleman Jan 22, 2024
cd807d6
Merge remote-tracking branch 'upstream/main' into 32594-update-style-…
trevor-coleman Jan 23, 2024
8be0e64
feat(Violations): simplify
trevor-coleman Jan 24, 2024
0adddd0
feat(Violations): fix fields
trevor-coleman Jan 24, 2024
a336be8
feat(Violations): reword comment
trevor-coleman Jan 24, 2024
01c552c
feat(Violations): remove redundant check
trevor-coleman Jan 24, 2024
498634a
feat(Violations): add space
trevor-coleman Jan 24, 2024
015764e
feat(Violations): change empty string to single quotes
trevor-coleman Jan 24, 2024
b2ba0b6
feat(Violations): make translations consistent
trevor-coleman Jan 24, 2024
3a75337
Merge remote-tracking branch 'upstream/main' into 32594-update-style-…
trevor-coleman Jan 24, 2024
581f8b0
feat(Violations): rename vars
trevor-coleman Jan 24, 2024
c92ee98
feat(Violations): return empty string if variables are missing
trevor-coleman Jan 24, 2024
a556d5f
Merge remote-tracking branch 'upstream/main' into 32594-update-style-…
trevor-coleman Jan 30, 2024
c9e75c4
Merge remote-tracking branch 'upstream/main' into 32594-update-style-…
trevor-coleman Feb 1, 2024
9cdf6ea
Merge remote-tracking branch 'upstream/main' into 32594-update-style-…
trevor-coleman Feb 2, 2024
a828529
Merge remote-tracking branch 'upstream/main' into 32594-update-style-…
trevor-coleman Feb 3, 2024
abf3255
feat(Violations): restore type
trevor-coleman Feb 3, 2024
5498c82
Merge remote-tracking branch 'upstream/main' into 32594-update-style-…
trevor-coleman Feb 5, 2024
e90cf9f
Merge remote-tracking branch 'origin/main' into 32594-update-style-fo…
trevor-coleman Feb 6, 2024
011a08a
feat(Violations): add deps to array
trevor-coleman Feb 6, 2024
519897a
feat(Violations): replace tag field
trevor-coleman Feb 6, 2024
2327c7c
Merge remote-tracking branch 'upstream/main' into 32594-update-style-…
trevor-coleman Feb 6, 2024
df76a09
Merge remote-tracking branch 'upstream/main' into 32594-update-style-…
trevor-coleman Feb 9, 2024
7eb9560
Merge remote-tracking branch 'upstream/main' into 32594-update-style-…
trevor-coleman Feb 12, 2024
766ccf3
Merge remote-tracking branch 'upstream/main' into 32594-update-style-…
trevor-coleman Feb 12, 2024
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
Prev Previous commit
Next Next commit
feat(Violations): rename vars
  • Loading branch information
trevor-coleman committed Jan 24, 2024
commit 581f8b078c5158301599bc2bde3ce429c037ac80
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/MoneyRequestView.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ function MoneyRequestView({report, parentReport, parentReportActions, policyCate
return translate(translationPath);
}

// Show violations if there are any
// Return violations if there are any
if (canUseViolations && hasViolations(field)) {
const violations = getViolationsForField(field);
return ViolationsUtils.getViolationTranslation(violations[0], translate);
Expand Down
14 changes: 7 additions & 7 deletions src/hooks/useViolations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import type {TransactionViolation, ViolationName} from '@src/types/onyx';
/**
* Names of Fields where violations can occur.
*/
type MoneyRequestField = 'amount' | 'billable' | 'category' | 'comment' | 'date' | 'merchant' | 'receipt' | 'tag' | 'tax';
type ViolationField = 'amount' | 'billable' | 'category' | 'comment' | 'date' | 'merchant' | 'receipt' | 'tag' | 'tax';

/**
* Map from Violation Names to the field where that violation can occur.
*/
const violationFields: Record<ViolationName, MoneyRequestField> = {
const violationFields: Record<ViolationName, ViolationField> = {
allTagLevelsRequired: 'tag',
autoReportedRejectedExpense: 'merchant',
billableExpense: 'billable',
Expand Down Expand Up @@ -45,12 +45,12 @@ const violationFields: Record<ViolationName, MoneyRequestField> = {
taxRequired: 'tax',
};

type ViolationsMap = Map<MoneyRequestField, TransactionViolation[]>;
type ViolationsMap = Map<ViolationField, TransactionViolation[]>;

function useViolations(violations: TransactionViolation[]) {
const violationsByField = useMemo((): ViolationsMap => {
const filteredViolations = violations.filter((v) => v.type === 'violation');
const violationGroups = new Map<MoneyRequestField, TransactionViolation[]>();
const filteredViolations = violations.filter((violation) => violation.type === 'violation');
const violationGroups = new Map<ViolationField, TransactionViolation[]>();
for (const violation of filteredViolations) {
const field = violationFields[violation.name];
const existingViolations = violationGroups.get(field) ?? [];
Expand All @@ -59,12 +59,12 @@ function useViolations(violations: TransactionViolation[]) {
return violationGroups ?? new Map();
}, [violations]);

const getViolationsForField = useCallback((field: MoneyRequestField) => violationsByField.get(field) ?? [], [violationsByField]);
const getViolationsForField = useCallback((field: ViolationField) => violationsByField.get(field) ?? [], [violationsByField]);

return {
getViolationsForField,
};
}

export default useViolations;
export type {MoneyRequestField};
export type {ViolationField};
Loading