Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions src/components/MoneyRequestConfirmationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import {validateAmount} from '@libs/MoneyRequestUtils';
import Navigation from '@libs/Navigation/Navigation';
import {getIOUConfirmationOptionsFromPayeePersonalDetail, hasEnabledOptions} from '@libs/OptionsListUtils';
import {getTagLists, isTaxTrackingEnabled} from '@libs/PolicyUtils';
import {getTagLists, isAttendeeTrackingEnabled, isTaxTrackingEnabled} from '@libs/PolicyUtils';
import {isSelectedManagerMcTest} from '@libs/ReportUtils';
import type {OptionData} from '@libs/ReportUtils';
import {hasEnabledTags, hasMatchingTag} from '@libs/TagsOptionsListUtils';
Expand Down Expand Up @@ -490,7 +490,7 @@
policyTaxRates: policy?.taxRates?.taxes,
iouAttendees,
currentUserPersonalDetails,
isAttendeeTrackingEnabled: policy?.isAttendeeTrackingEnabled,
isAttendeeTrackingEnabled: isAttendeeTrackingEnabled(policy),
isControlPolicy: policy?.type === CONST.POLICY.TYPE.CORPORATE,
});

Expand Down Expand Up @@ -1074,7 +1074,7 @@
iouCategory,
iouAttendees,
currentUserPersonalDetails,
policy?.isAttendeeTrackingEnabled,
isAttendeeTrackingEnabled(policy),
policy?.type === CONST.POLICY.TYPE.CORPORATE,
);
if (isMissingAttendeesViolation) {
Expand Down Expand Up @@ -1148,7 +1148,7 @@
onSendMoney?.(paymentMethod);
}
},
[

Check warning on line 1151 in src/components/MoneyRequestConfirmationList.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

React Hook useCallback has a missing dependency: 'isNewManualExpenseFlowEnabled'. Either include it or remove the dependency array

Check warning on line 1151 in src/components/MoneyRequestConfirmationList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useCallback has a missing dependency: 'isNewManualExpenseFlowEnabled'. Either include it or remove the dependency array
routeError,
transactionID,
iouType,
Expand Down
3 changes: 2 additions & 1 deletion src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
getPolicyByCustomUnitID,
getTagLists,
hasDependentTags as hasDependentTagsPolicyUtils,
isAttendeeTrackingEnabled,
isPolicyAccessible,
isTaxTrackingEnabled,
} from '@libs/PolicyUtils';
Expand Down Expand Up @@ -558,7 +559,7 @@ function MoneyRequestView({
updatedTransaction?.category ?? categoryForDisplay,
actualAttendees,
currentUserPersonalDetails,
policy?.isAttendeeTrackingEnabled,
isAttendeeTrackingEnabled(policy),
policy?.type === CONST.POLICY.TYPE.CORPORATE,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
import {handleActionButtonPress} from '@libs/actions/Search';
import {syncMissingAttendeesViolation} from '@libs/AttendeeUtils';
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import {isAttendeeTrackingEnabled} from '@libs/PolicyUtils';
import {isInvoiceReport, isOpenExpenseReport, isProcessingReport, isReportPendingDelete} from '@libs/ReportUtils';
import {isViolationDismissed, shouldShowViolation} from '@libs/TransactionUtils';
import variables from '@styles/variables';
Expand Down Expand Up @@ -96,7 +97,7 @@ function ExpenseReportListItem<TItem extends ListItem>({
// Sync missingAttendees violation at render time for each transaction in the report
// This ensures violations show immediately when category settings change, without needing to click the row
const hasSyncedMissingAttendeesViolation = useMemo(() => {
if (!policyForViolations?.isAttendeeTrackingEnabled || policyForViolations?.type !== CONST.POLICY.TYPE.CORPORATE) {
if (!isAttendeeTrackingEnabled(policyForViolations)) {
return false;
}

Expand All @@ -114,7 +115,7 @@ function ExpenseReportListItem<TItem extends ListItem>({
transaction.category ?? '',
transaction.attendees,
currentUserDetails,
policyForViolations.isAttendeeTrackingEnabled ?? false,
isAttendeeTrackingEnabled(policyForViolations),
policyForViolations.type === CONST.POLICY.TYPE.CORPORATE,
isInvoice,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import type {TransactionPreviewData} from '@libs/actions/Search';
import {handleActionButtonPress as handleActionButtonPressUtil} from '@libs/actions/Search';
import {syncMissingAttendeesViolation} from '@libs/AttendeeUtils';
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import {isAttendeeTrackingEnabled} from '@libs/PolicyUtils';
import {isInvoiceReport} from '@libs/ReportUtils';
import {isViolationDismissed, mergeProhibitedViolations, shouldShowViolation} from '@libs/TransactionUtils';
import variables from '@styles/variables';
Expand Down Expand Up @@ -145,7 +146,7 @@ function TransactionListItem<TItem extends ListItem>({
transaction?.category ?? transactionItem.category ?? '',
transaction?.comment?.attendees ?? transactionItem.attendees,
currentUserDetails,
policyForViolations?.isAttendeeTrackingEnabled ?? false,
isAttendeeTrackingEnabled(policyForViolations),
policyForViolations?.type === CONST.POLICY.TYPE.CORPORATE,
isInvoice,
);
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useAdvancedSearchFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ function useAdvancedSearchFilters() {
if (key === CONST.SEARCH.SYNTAX_ROOT_KEYS.VIEW && !shouldDisplayViewFilter) {
return;
}
if (key === CONST.SEARCH.SYNTAX_FILTER_KEYS.ATTENDEE && !(policyDerived?.isAttendeeTrackingEnabled ?? false)) {
if (key === CONST.SEARCH.SYNTAX_FILTER_KEYS.ATTENDEE && !(policyDerived?.isAttendeeTrackingEnabled ?? true)) {

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 Default attendee filter to hidden when policy data is absent

Changing this fallback to ?? true causes the ATTENDEE filter to be shown whenever policyDerived is temporarily undefined (e.g., initial Onyx load), unlike other feature-gated filters that default to hidden. That can surface an attendee filter in contexts where policy capabilities are not yet known and produce incorrect/flickering filter UI; the Classic compatibility behavior is already handled by isPolicyFeatureEnabled() once policy data is available.

Useful? React with 👍 / 👎.

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.

Hm maybe. You could also argue the opposite that we're not showing the attendee selector when we should. Not going to block on this.

return;
}
if (key === CONST.SEARCH.SYNTAX_FILTER_KEYS.REPORT_FIELD && !(policyDerived?.hasReportFields ?? false)) {
Expand Down
12 changes: 12 additions & 0 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@

let allPolicies: OnyxCollection<Policy>;

Onyx.connect({

Check warning on line 76 in src/libs/PolicyUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => (allPolicies = value),
Expand Down Expand Up @@ -813,6 +813,14 @@
return policy?.type === CONST.POLICY.TYPE.CORPORATE;
}

/**
* For backwards compatibility with Expensify Classic, attendee tracking defaults to enabled
* on Control policies when the property is undefined.
*/
function isAttendeeTrackingEnabled(policy: OnyxEntry<Policy>): boolean {
return (isControlPolicy(policy) && policy?.isAttendeeTrackingEnabled) ?? true;

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 Align rollback state with new attendee default

This change makes Classic control policies resolve isAttendeeTrackingEnabled to true when the field is missing, but the toggle action still snapshots the original value with !!policy?.isAttendeeTrackingEnabled in setPolicyAttendeeTrackingEnabled(). For a legacy policy (undefined flag), toggling OFF and then hitting an API failure will roll back to false instead of the effective default true, leaving the setting incorrectly disabled until a full refetch. Please ensure rollback uses the same resolver (or preserves undefined) as this new defaulting logic.

Useful? React with 👍 / 👎.

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.

}

/**
* Whether the policy can access a feature based on plan level.
* Corporate-only features are restricted to control (Corporate) policies.
Expand Down Expand Up @@ -1014,6 +1022,9 @@
if (featureName === CONST.POLICY.MORE_FEATURES.IS_TIME_TRACKING_ENABLED) {
return isTimeTrackingEnabled(policy);
}
if (featureName === CONST.POLICY.MORE_FEATURES.IS_ATTENDEE_TRACKING_ENABLED) {
return isAttendeeTrackingEnabled(policy);
}

return !!policy?.[featureName];
}
Expand Down Expand Up @@ -2161,6 +2172,7 @@
getApprovalWorkflow,
getReimburserAccountID,
isControlPolicy,
isAttendeeTrackingEnabled,
isCollectPolicy,
isNetSuiteCustomSegmentRecord,
getNameFromNetSuiteCustomField,
Expand Down
9 changes: 3 additions & 6 deletions src/libs/TransactionUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
getDistanceRateCustomUnit,
getDistanceRateCustomUnitRate,
getTaxByID,
isAttendeeTrackingEnabled as isAttendeeTrackingEnabledForPolicy,
isInstantSubmitEnabled,
isMultiLevelTags as isMultiLevelTagsPolicyUtils,
isPolicyAdmin,
Expand Down Expand Up @@ -597,9 +598,7 @@ function shouldShowAttendees(iouType: IOUType, policy: OnyxEntry<Policy>): boole
return false;
}

// For backwards compatibility with Expensify Classic, we assume that Attendee Tracking is enabled by default on
// Control policies if the policy does not contain the attribute
return policy?.isAttendeeTrackingEnabled ?? true;
return isAttendeeTrackingEnabledForPolicy(policy);
}

/**
Expand Down Expand Up @@ -1687,8 +1686,6 @@ function shouldShowViolation(
const isSubmitter = isCurrentUserSubmitter(iouReport);
const isPolicyMember = isPolicyMemberPolicyUtils(policy, currentUserEmail);
const isReportOpen = isOpenExpenseReport(iouReport);
const isAttendeeTrackingEnabled = policy?.isAttendeeTrackingEnabled ?? false;

if (violationName === CONST.VIOLATIONS.AUTO_REPORTED_REJECTED_EXPENSE) {
return isSubmitter || isPolicyAdmin(policy);
}
Expand All @@ -1706,7 +1703,7 @@ function shouldShowViolation(
}

if (violationName === CONST.VIOLATIONS.MISSING_ATTENDEES) {
return isAttendeeTrackingEnabled;
return isAttendeeTrackingEnabledForPolicy(policy);
}

if (violationName === CONST.VIOLATIONS.MISSING_CATEGORY && isCategoryBeingAnalyzed(transaction)) {
Expand Down
11 changes: 9 additions & 2 deletions src/libs/Violations/ViolationsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ import DistanceRequestUtils from '@libs/DistanceRequestUtils';
import {isReceiptError} from '@libs/ErrorUtils';
import {getCurrentUserEmail} from '@libs/Network/NetworkStore';
import Parser from '@libs/Parser';
import {getDistanceRateCustomUnitRate, getPerDiemRateCustomUnitRate, getSortedTagKeys, isDefaultTagName, isTaxTrackingEnabled} from '@libs/PolicyUtils';
import {
getDistanceRateCustomUnitRate,
getPerDiemRateCustomUnitRate,
getSortedTagKeys,
isAttendeeTrackingEnabled as isAttendeeTrackingEnabledForPolicy,
isDefaultTagName,
isTaxTrackingEnabled,
} from '@libs/PolicyUtils';
import {isCurrentUserSubmitter} from '@libs/ReportUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
import {hasValidModifiedAmount, isViolationDismissed, shouldShowViolation} from '@libs/TransactionUtils';
Expand Down Expand Up @@ -498,7 +505,7 @@ const ViolationsUtils = {
!isInvoiceTransaction && policyCategories?.[categoryName ?? '']?.areCommentsRequired && !updatedTransaction.comment?.comment && isControlPolicy && policy?.areRulesEnabled;
const rawAttendees = updatedTransaction.modifiedAttendees ?? updatedTransaction.comment?.attendees;
const attendees = Array.isArray(rawAttendees) ? rawAttendees : [];
const isAttendeeTrackingEnabled = policy.isAttendeeTrackingEnabled ?? false;
const isAttendeeTrackingEnabled = isAttendeeTrackingEnabledForPolicy(policy);
// Filter out the owner/creator when checking attendance count - expense is valid if at least one non-owner attendee is present
const ownerAccountID = iouReport?.ownerAccountID;
// Calculate attendees minus owner. When ownerAccountID is known, filter by accountID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
import {getDecodedCategoryName} from '@libs/CategoryUtils';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import {isAttendeeTrackingEnabled} from '@libs/PolicyUtils';
import type {SettingsNavigatorParamList} from '@navigation/types';
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
import {setPolicyCategoryAttendeesRequired, setPolicyCategoryDescriptionRequired} from '@userActions/Policy/Category';
Expand All @@ -37,8 +38,6 @@ function CategoryRequiredFieldsPage({
const policyCategory = policyCategories?.[categoryName];
const areCommentsRequired = policyCategory?.areCommentsRequired ?? false;
const areAttendeesRequired = policyCategory?.areAttendeesRequired ?? false;
const isAttendeeTrackingEnabled = policy?.isAttendeeTrackingEnabled ?? false;

return (
<AccessOrNotFoundWrapper
accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN, CONST.POLICY.ACCESS_VARIANTS.CONTROL]}
Expand Down Expand Up @@ -82,7 +81,7 @@ function CategoryRequiredFieldsPage({
</View>
</View>
</OfflineWithFeedback>
{isAttendeeTrackingEnabled && (
{isAttendeeTrackingEnabled(policy) && (
<OfflineWithFeedback pendingAction={policyCategory?.pendingFields?.areAttendeesRequired}>
<View style={[styles.mh5]}>
<View style={[styles.flexRow, styles.mv5, styles.mr2, styles.alignItemsCenter, styles.justifyContentBetween]}>
Expand Down
10 changes: 5 additions & 5 deletions src/pages/workspace/categories/CategorySettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import {isDisablingOrDeletingLastEnabledCategory} from '@libs/OptionsListUtils';
import {getPersonalDetailByEmail} from '@libs/PersonalDetailsUtils';
import {getWorkflowApprovalsUnavailable, hasTags, isControlPolicy} from '@libs/PolicyUtils';
import {getWorkflowApprovalsUnavailable, hasTags, isAttendeeTrackingEnabled, isControlPolicy} from '@libs/PolicyUtils';
import type {SettingsNavigatorParamList} from '@navigation/types';
import NotFoundPage from '@pages/ErrorPage/NotFoundPage';
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
Expand Down Expand Up @@ -155,17 +155,17 @@ function CategorySettingsPage({
if (!policyCategory) {
return '';
}
return formatRequiredFieldsTitle(translate, policyCategory, policy?.isAttendeeTrackingEnabled);
}, [policyCategory, translate, policy?.isAttendeeTrackingEnabled]);
return formatRequiredFieldsTitle(translate, policyCategory, isAttendeeTrackingEnabled(policy));
}, [policyCategory, translate, policy]);

const requireFieldsPendingAction = useMemo(() => {
if (policy?.isAttendeeTrackingEnabled) {
if (isAttendeeTrackingEnabled(policy)) {
// Pending fields are objects so we can't use nullish coalescing
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
return policyCategory?.pendingFields?.areAttendeesRequired || policyCategory?.pendingFields?.areCommentsRequired;
}
return policyCategory?.pendingFields?.areCommentsRequired;
}, [policyCategory?.pendingFields, policy?.isAttendeeTrackingEnabled]);
}, [policyCategory?.pendingFields, policy]);

// eslint-disable-next-line rulesdir/no-negated-variables
const showCannotDeleteOrDisableLastCategoryModal = useCallback(() => {
Expand Down
9 changes: 4 additions & 5 deletions src/pages/workspace/rules/IndividualExpenseRulesSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
import {getCashExpenseReimbursableMode, setPolicyAttendeeTrackingEnabled, setPolicyRequireCompanyCardsEnabled, setWorkspaceEReceiptsEnabled} from '@libs/actions/Policy/Policy';
import {convertToDisplayString} from '@libs/CurrencyUtils';
import Navigation from '@libs/Navigation/Navigation';
import {isAttendeeTrackingEnabled} from '@libs/PolicyUtils';
import ToggleSettingOptionRow from '@pages/workspace/workflows/ToggleSettingsOptionRow';
import type {ThemeStyles} from '@styles/index';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -197,9 +198,7 @@ function IndividualExpenseRulesSection({policyID}: IndividualExpenseRulesSection
const requireCompanyCardsEnabled = policy?.requireCompanyCardsEnabled ?? false;
const disableRequireCompanyCardToggle = !policy?.areCompanyCardsEnabled && !policy?.areExpensifyCardsEnabled;

// For backwards compatibility with Expensify Classic, we assume that Attendee Tracking is enabled by default on
// Control policies if the policy does not contain the attribute
const isAttendeeTrackingEnabled = policy?.isAttendeeTrackingEnabled ?? false;
const isAttendeeTrackingEnabledForPolicy = isAttendeeTrackingEnabled(policy);

return (
<Section
Expand Down Expand Up @@ -269,8 +268,8 @@ function IndividualExpenseRulesSection({policyID}: IndividualExpenseRulesSection
shouldPlaceSubtitleBelowSwitch
titleStyle={styles.pv2}
subtitleStyle={styles.pt1}
isActive={isAttendeeTrackingEnabled}
onToggle={() => handleAttendeeTrackingToggle(!isAttendeeTrackingEnabled)}
isActive={isAttendeeTrackingEnabledForPolicy}
onToggle={() => handleAttendeeTrackingToggle(!isAttendeeTrackingEnabledForPolicy)}
pendingAction={policy?.pendingFields?.isAttendeeTrackingEnabled}
/>
</View>
Expand Down
19 changes: 17 additions & 2 deletions tests/unit/hooks/useAdvancedSearchFilters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ describe('useAdvancedSearchFilters', () => {

describe('attendee filter visibility', () => {

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.

@MelvinBot let's add a test to confirm that we show the attendee filter when the isAttendeeTrackingEnabled prop is absent

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.

Added a test that creates a Corporate policy without isAttendeeTrackingEnabled set (property explicitly deleted) and asserts the attendee filter is visible. All 18 tests pass.

it('hides attendee filter when no policies have attendee tracking enabled', async () => {
const policy = buildPolicy(1, {isAttendeeTrackingEnabled: false});
const policy = buildPolicy(1, {type: CONST.POLICY.TYPE.CORPORATE, isAttendeeTrackingEnabled: false});
await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}1`, policy);

const {result} = renderHook(() => useAdvancedSearchFilters(), {wrapper});
Expand All @@ -268,8 +268,22 @@ describe('useAdvancedSearchFilters', () => {
});
});

it('shows attendee filter when isAttendeeTrackingEnabled is absent (Classic backwards compat)', async () => {
const policy = buildPolicy(1, {type: CONST.POLICY.TYPE.CORPORATE});
// Ensure the property is truly absent, not just falsy
delete (policy as Record<string, unknown>).isAttendeeTrackingEnabled;
await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}1`, policy);

const {result} = renderHook(() => useAdvancedSearchFilters(), {wrapper});

await waitFor(() => {
const allKeys = result.current.typeFiltersKeys.flat();
expect(allKeys).toContain(CONST.SEARCH.SYNTAX_FILTER_KEYS.ATTENDEE);
});
});

it('shows attendee filter when attendee tracking is enabled', async () => {
const policy = buildPolicy(1, {isAttendeeTrackingEnabled: true});
const policy = buildPolicy(1, {type: CONST.POLICY.TYPE.CORPORATE, isAttendeeTrackingEnabled: true});
await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}1`, policy);

const {result} = renderHook(() => useAdvancedSearchFilters(), {wrapper});
Expand Down Expand Up @@ -378,6 +392,7 @@ describe('useAdvancedSearchFilters', () => {
describe('cross-feature interaction', () => {
it('shows multiple filters when multiple features are enabled', async () => {
const policy = buildPolicy(1, {
type: CONST.POLICY.TYPE.CORPORATE,
areCategoriesEnabled: true,
areTagsEnabled: true,
isAttendeeTrackingEnabled: true,
Expand Down
Loading