App icon indicating copy to clipboard operation
App copied to clipboard

[$175] Categories - Category visibility error shows up when disabling all categories on Collect plan

Open applause-bot[bot] opened this issue 2 weeks ago • 13 comments

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: 9.5.39-2 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://github.com/Expensify/App/pull/105184 Email or phone of affected tester (no customers): [email protected] Issue reported by: Applause Internal Team Bug source: Exploratory - Significant User Experience Deterioration Device used: Mac 26.5 / Chrome App Component: Workspace Settings

Action Performed:

Precondition:

  • Enable categoryVisibility beta.
  • Create a Collect workspace.
  • Enable Rules.
  • Disable Category in Rules > Require fields for all expenses.
  1. Go to staging.new.expensify.com
  2. Go to workspace settings > Categories.
  3. Disable all categories.

Expected Result:

User can disable all categories without category visibility issue when workspace is on Collect plan.

Actual Result:

Category visibility error shows up when disabling all categories on Collect workspace when the feature is exclusive to Control plan.

Workaround:

Unknown

Platforms:

  • [x] Android: App
  • [ ] Android: mWeb Chrome
  • [x] iOS: App
  • [ ] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [x] Windows: Chrome
  • [x] MacOS: Chrome Safari

Screenshots/Videos

https://github.com/user-attachments/assets/24b74f4e-4e25-4d9d-a24c-dbb107d6abc3

View all open jobs on GitHub

Applause Internal Information Exported by: Chandana Kiran Bug ID: 7315905

Upwork Automation - Do Not Edit

applause-bot[bot] avatar Nov 16 '26 20:11 applause-bot[bot]

While Applause doesn't embed attachments for this bug, here are the links for quick view: https://platform.applause.com/services/links/v1/external/9189efa695460bddfa36147c3702e689f2acbd1f6200f30512004df4a0c33e87

applause-bot[bot] avatar Nov 16 '26 20:11 applause-bot[bot]

This looks like a dupe of https://github.com/Expensify/App/issues/107025#top for which its not a blocker and we already merged a fix. closing.

chiragsalian avatar Nov 16 '26 20:11 chiragsalian

Triggered auto assignment to Contributor-plus team member for initial proposal review - @parasharrajat (External)

Job added to Upwork: https://www.upwork.com/jobs/~022122430957717034638

Investigation Progress:

  • [x] Steps 1–4: Extracted symptoms, formed the hypothesis, scanned related issues, and completed two independent code investigations.
  • [x] Step 5: Traced the failure through all three disable entry points.
  • [x] Step 6: Ruled out the existing required-category safeguard as the cause.
  • [x] Step 7: Determined production logs are not needed to establish this client-side path; browser reproduction was not performed.
  • [x] Step 8: Prepared the proposal.

The source evidence supports the missing Control-plan gate. The merge diff also confirms that the referenced category-visibility PR introduced these checks.## Proposal

What is the root cause of that problem?

The category-visibility validation runs on Collect, although the feature is Control-only.

With Category requirement disabled, the existing required-category safeguard correctly permits disabling all categories. However, the separate visibility check then treats every workspace member as losing their last category—even when categories have no visibility restrictions—and blocks the update.

Confidence: Medium: confirmed through source and merge-diff analysis; not independently reproduced in a browser.

Code evidence and regression origin

What changes do you think we should make in order to solve the problem?

Run the category-visibility validation only when isControlPolicy(policy) is true, consistently across all three disable entry points.

For bulk Disable, use an empty affected-members result outside Control so focus-restoration behavior also remains correct. Preserve the existing required-category safeguard and server-error handling.

Add regression coverage for:

  • Collect with Category requirement off: bulk-disable all categories and disable the final category through both toggle locations; assert the update occurs without the visibility modal.
  • Collect with Category requirement on: retain the existing last-category restriction.
  • Control: retain protection when disabling a member’s last visible category.

The current branch no longer has the category-visibility beta; do not reintroduce it.

What alternative solutions did you explore? (Optional)

  • Gate on Category requirement: incorrect; it would weaken independent visibility protection on Control.
  • Skip validation for unrestricted categories: incomplete; it does not enforce plan eligibility when visibility restrictions remain after a downgrade.
Related issue

Category visibility field shows “All categories” when all categories are deleted concerns the same feature and empty-category state, but has a different symptom; it is not a confirmed duplicate.


Next Steps for Contributor+ team:
To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/107039) to create a draft PR.
To refine: @MelvinBot <your feedback>
To reject: Explain why you are rejecting Melvin's proposal.


view run

MelvinBot avatar Nov 16 '26 20:11 MelvinBot

Issue reproducible with Collect WS on latest build v9.5.40-0

https://github.com/user-attachments/assets/6a3ed109-6179-4c0e-8134-7db7e175c808

Chandkia24 avatar Nov 17 '26 01:11 Chandkia24

Proposal

What is the root cause of that problem?

Category Visibility is a feature exclusive to Control workspaces (isControlPolicy(policy)). On Collect workspaces (CONST.POLICY.TYPE.TEAM), category visibility is not supported—the category visibility row is hidden in member details (WorkspaceMemberDetailsPage.tsx), and the member category visibility page is blocked (WorkspaceMemberCategoryVisibilityPage.tsx).

When "Require category" is disabled under Rules (areCategoriesRequiredInRules is false), workspace admins are permitted to disable all categories without violating the last-category requirement in isDisablingOrDeletingLastEnabledCategory.

However, the category visibility validation in:

  1. WorkspaceCategoriesPage.tsx (handleCategoryToggle at line 245)
  2. WorkspaceCategoriesPage.tsx (bulk disable action at lines 491 and 503)
  3. CategorySettingsPage.tsx (updateWorkspaceCategoryEnabled at line 163)

invokes getMembersWithoutVisibleCategories without gating on isControlPolicy(policy).

Inside getMembersWithoutVisibleCategories (CategoryUtils.ts:116–121), categories on Collect plans have no per-member restrictions (!category.visibleTo is true). When disabling all enabled categories, isEveryoneLosingACategory is set to true while membersKeepingACategory is empty. Consequently, getMembersWithoutVisibleCategories returns all workspace member account IDs. This triggers showMembersNeedCategoryModal and blocks disabling categories with a category visibility error on Collect workspaces where the feature does not exist.

What changes do you think we should make in order to solve the problem?

Gate the category visibility validation with isControlPolicy(policy) across all three category disable entry points:

  1. In src/pages/workspace/categories/WorkspaceCategoriesPage.tsx:

    • In handleCategoryToggle: Wrap the visibility validation in if (isControlPolicy(policy) && !enabled).
    • In the bulk disable option: Compute membersWithoutVisibleCategories only when isControlPolicy(policy) is true, defaulting to an empty array otherwise:
      const isControl = isControlPolicy(policy);
      const membersWithoutVisibleCategories = isControl ? getMembersWithoutVisibleCategories(policyCategories, enabledCategories, policyMemberAccountIDs) : [];
      
    • In the bulk disable onSelected callback: Only check if (isControl && membersWithoutVisibleCategories.length > 0). This also ensures shouldSkipFocusRestore is not falsely set on Collect workspaces.
  2. In src/pages/workspace/categories/CategorySettingsPage.tsx:

    • In updateWorkspaceCategoryEnabled: Wrap the visibility validation in if (isControlPolicy(policy) && !value). Note that isControlPolicy is already imported and policy is available from policyData.
  3. Test coverage:

    • Add unit/UI tests asserting that:
      • On a Collect workspace with category requirement disabled in rules, disabling the final category or bulk disabling all categories proceeds without triggering the categoryVisibilityRequiredModal.
      • On a Control workspace, category visibility safeguards continue to block disabling categories that leave restricted members without visible categories.

What alternative solutions did you explore? (Optional)

  • Passing policy into getMembersWithoutVisibleCategories directly: Keeping the isControlPolicy(policy) check at the UI/handler call sites aligns with how WorkspaceMemberDetailsPage and WorkspaceMemberCategoryVisibilityPage gate category visibility, avoiding unnecessary computation for Collect workspaces entirely.
  • Gating on areCategoriesRequiredInRules: Rejected because category requirements and category visibility restrictions are distinct; a Control workspace may not require categories on all expenses but can still have members restricted to specific categories.

Contributor details

  • Email: [email protected]
  • Upwork Profile: https://www.upwork.com/freelancers/~0131dae36abcf59374

kevinjosh10 avatar Nov 17 '26 01:11 kevinjosh10

Proposal

What is the root cause of that problem?

In src/libs/CategoryUtils.ts:103-135, getMembersWithoutVisibleCategories is designed to be plan-agnostic and return [] whenever no member is selectively excluded by visibleTo restrictions (matching CategoryPickerModal in src/components/CategoryPicker/CategoryPickerModal.tsx:78, which filters by visibleTo without checking the workspace plan, and as documented in tests/unit/CategoryUtilsTest.ts under "returns nothing when no category is restricted").

However, getMembersWithoutVisibleCategories only short-circuits for unrestricted categories (!category.visibleTo) when at least one unrestricted enabled category stays enabled (src/libs/CategoryUtils.ts:116-121):

  • When an unrestricted enabled category is not in categoriesToDisable (!isBeingDisabled), line 118 returns [].
  • When all enabled categories in the workspace are being disabled (either via bulk Disable or by toggling off the final enabled category when "Require category" is disabled in Rules so isDisablingOrDeletingLastEnabledCategory returns false), no enabled category has !isBeingDisabled.
  • Every unrestricted enabled category sets isEveryoneLosingACategory = true while membersKeepingACategory stays empty, so lines 131-134 return every workspace member and block the disable with showMembersNeedCategoryModal—even though zero visibleTo restrictions exist and zero enabled categories will remain in the workspace.
  • Because the bug is in getMembersWithoutVisibleCategories itself, this affects both Collect and Control workspaces whenever "Require category" is disabled in Rules and an admin disables all categories: even on Control, no member can be assigned an alternate category via Category visibility when zero enabled categories remain in the workspace.

What changes do you think we should make in order to solve the problem?

  1. Return [] from getMembersWithoutVisibleCategories when no enabled category remains after the disable (src/libs/CategoryUtils.ts:103-135):
    • Track a boolean hasRemainingEnabledCategory inside the enabled-categories loop (set to true whenever !isBeingDisabled), and after the loop return [] if !hasRemainingEnabledCategory.
    • Whether a workspace is allowed to have zero enabled categories is already guarded immediately beforehand by isDisablingOrDeletingLastEnabledCategory (policy?.requiresCategory) across all three disable entry points (WorkspaceCategoriesPage.tsx:239, WorkspaceCategoriesPage.tsx:490, and CategorySettingsPage.tsx:158).
    • When at least one enabled category remains (hasRemainingEnabledCategory is true), getMembersWithoutVisibleCategories continues to return any member left without a visible category among the remaining enabled categories (including when an unrestricted category is disabled while only restricted categories remain enabled).
    • When all enabled categories are being disabled (!hasRemainingEnabledCategory) and policy.requiresCategory is false, getMembersWithoutVisibleCategories returns [], allowing all three entry points (and keeping bulk Disable's shouldSkipFocusRestore at WorkspaceCategoriesPage.tsx:497 false) to complete without showing the category-visibility modal on both Collect and Control plans.
  2. Add unit tests in tests/unit/CategoryUtilsTest.ts:
    • Verify getMembersWithoutVisibleCategories returns [] when all enabled categories are disabled together and when the last remaining enabled category is disabled.
    • Verify partial-disable cases (including disabling an unrestricted category while a restricted category remains enabled) still return the affected member account IDs.

What alternative solutions did you explore? (Optional)

  • Only gating the three UI call sites in WorkspaceCategoriesPage.tsx and CategorySettingsPage.tsx on isControlPolicy(policy): Incomplete because it leaves the exact same false error and deadlock on Control workspaces when "Require category" is turned off in Rules and an admin disables all categories (where every member is already set to "All categories" and zero enabled categories remain to select). It also diverges from CategoryPicker and backend SetWorkspaceCategoriesEnabled validation, which evaluate visibleTo directly rather than gating on workspace plan type.

ocakciomursel-pixel avatar Nov 17 '26 13:11 ocakciomursel-pixel

Proposal

What is the root cause of that problem?

The root cause is a logical flaw in getMembersWithoutVisibleCategories within src/libs/CategoryUtils.ts. When a Control workspace disables all categories and the Require category rule is also disabled, the function fails to correctly evaluate the visibility state for members, incorrectly identifying them as having no visible categories due to an unhandled state in the membership filtering logic. This creates a visibility deadlock that manifests as an error in the UI.

What changes do you think we should make in order to solve the problem?

  1. Modify getMembersWithoutVisibleCategories: Update the logic in src/libs/CategoryUtils.ts to explicitly return an empty list when no enabled categories remain in the workspace, regardless of the workspace type (Collect or Control). This ensures that the system does not incorrectly flag members as lacking access when category enforcement is effectively disabled.
  2. Conditional Gating: Apply conditional gating using isControlPolicy in the relevant UI components (e.g., WorkspaceCategoriesPage.tsx, CategoryFieldDropdown.tsx) to ensure that category-disable checks only trigger in workspaces where category enforcement is actively applicable. This prevents the UI from reacting to disabled category states in non-enforcement contexts.

What alternative solutions did you explore?

  • UI-only gating: I explored gating the error message display purely on isControlPolicy at the component level. This was rejected because it only masks the underlying logical error in the member visibility filtering function, failing to resolve the root cause in the data layer.

ocakciomursel-pixel avatar Nov 18 '26 11:11 ocakciomursel-pixel

Proposal

What is the root cause of that problem?

Category-visibility validation runs on Collect workspaces even though the visibility feature is restricted to Control.

When all enabled categories are disabled, getMembersWithoutVisibleCategories can report every workspace member as losing access to their last category. The category-row toggle, bulk Disable action and category-settings toggle display the visibility error and return before submitting the update.

This is separate from the existing required-category safeguard, which correctly permits disabling the final category when Category requirement is off.

The client-side blocking path is supported by source inspection. I have not independently reproduced the browser flow.

What changes do you think we should make in order to solve the problem?

Run the visibility validation only when isControlPolicy(policy) is true, consistently across all three disable entry points.

Skip only that validation on Collect—not the category update or the existing required-category safeguard. For bulk Disable, ensure the affected-members result is empty outside Control so subsequent focus-restoration behavior remains consistent.

Preserve Control visibility protections, optimistic updates, rollback and server-error handling. Do not reintroduce a category-visibility beta condition.

Add regression coverage for:

  • Collect, Category requirement off: disable all categories through bulk, row and settings controls.
  • Collect, Category requirement on: retain the final-category restriction.
  • Control: retain protection when members would lose their last visible category.
  • Failed updates: preserve existing rollback and error behavior.

These are proposed tests, not tests I have executed.

What alternative solutions did you explore? (Optional)

Hiding the error without correcting eligibility would conceal the problem. Disabling visibility checks whenever categories are optional could weaken independent Control protections. Changing the shared helper to ignore every empty-category result would likewise broaden the behavior unnecessarily.

Vallejo1921 avatar Nov 19 '26 00:11 Vallejo1921

@parasharrajat Whoops! This issue is 2 days overdue. Let's get this updated quick!

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~013b564a690d9bcdab

Proposal

Please re-state the problem that we are trying to solve in this issue.

On a Collect workspace, disabling all categories shows the "Members must have at least one category" visibility error and blocks the update, even though category visibility is a Control-only feature. The repro is: enable the categoryVisibility beta, create a Collect workspace, enable Rules, disable Category in Rules > Require fields for all expenses, then disable all categories in workspace settings > Categories. Expected: the categories disable without any visibility error. Actual: the visibility error modal appears and the update is blocked.

What is the root cause of that problem?

The category-visibility validation runs on Collect, although the feature is Control-only. Two separate defects combine to produce the error:

1. The validation is never gated on plan at any disable entry point. getMembersWithoutVisibleCategories is called without an isControlPolicy(policy) check in all three disable paths:

  • src/pages/workspace/categories/WorkspaceCategoriesPage.tsx:245 (handleCategoryToggle, row toggle)
  • src/pages/workspace/categories/WorkspaceCategoriesPage.tsx:485 (bulk Disable)
  • src/pages/workspace/categories/CategorySettingsPage.tsx:163 (updateWorkspaceCategoryEnabled, settings toggle)

The rest of the feature gates itself correctly: the visibility row is hidden on non-Control workspaces (WorkspaceMemberDetailsPage.tsx, shouldShowCategoryVisibility = isControlPolicy(policy) && ...), and the visibility editor page blocks non-Control workspaces (WorkspaceMemberCategoryVisibilityPage.tsx:152-158). Only the disable-path validation was left ungated.

2. The helper itself miscomputes for unrestricted categories. In src/libs/CategoryUtils.ts:103-134, when an unrestricted category (!category.visibleTo) is being disabled, the helper sets isEveryoneLosingACategory = true. Disabling all unrestricted categories therefore returns every workspace member as "without a visible category", even though no member has any visibility restriction to protect. The existing test "returns nothing when no category is restricted" pins the intended invariant for disabling one unrestricted category; the disable-all case breaks the same invariant. This defect is plan-independent: a Control workspace with no restrictions set hits the same spurious modal when all categories are disabled with the category requirement off.

The required-category safeguard is not the cause and must not change: isDisablingOrDeletingLastEnabledCategory (src/libs/OptionsListUtils/index.ts:875) only blocks when policy.requiresCategory is true, and the repro disables the category requirement in Rules, so it correctly permits disabling all categories. The visibility check then blocks the update on its own.

Not a duplicate of #107025. #107025 is a display-label bug: the member-details summary computes visibleCategoriesCount === getEnabledCategoriesCount(...), which is 0 === 0 after all categories are deleted, and shows "All categories" (WorkspaceMemberDetailsPage.tsx:199-203). #107039 is a validation bug on the disable path. Different symptoms, different files, different fixes, and neither fix has been merged (verified on live main 17/11/2026: both defects are still present). The internal comment claiming a fix was already merged for #107025 is not borne out: on #107025 itself the internal reviewer said the follow-up was still to come.

What changes do you think we should make in order to solve the problem?

Layer 1 - Fix the helper computation (src/libs/CategoryUtils.ts). An unrestricted category being disabled no longer sets isEveryoneLosingACategory; the flag is removed entirely. Only members who lose a restricted category they could use are returned. The early return when an unrestricted category stays enabled is unchanged. This fixes Collect and also Control workspaces with no restrictions set, and makes the helper match its own documented contract and its own existing test.

Layer 2 - Gate the validation on Control at all three call sites. Skip the visibility validation on non-Control plans, matching how the rest of the feature gates itself:

  • WorkspaceCategoriesPage.tsx handleCategoryToggle: run the check only when !enabled && isControlPolicy(policy).
  • WorkspaceCategoriesPage.tsx bulk Disable: compute membersWithoutVisibleCategories only when isControlPolicy(policy) is true, defaulting to [] otherwise, so shouldSkipFocusRestore is not falsely set on Collect workspaces.
  • CategorySettingsPage.tsx updateWorkspaceCategoryEnabled: run the check only when !value && isControlPolicy(policy).

Layer 2 also covers restrictions left over after a Control-to-Collect downgrade, which the helper fix alone would not: on a downgraded workspace the feature does not exist, so no member may be blocked by it. isControlPolicy is already imported and policy is already in scope at all three sites; no new imports are needed. The required-category safeguard and the server-error handling (MembersNeedCategoryError middleware) are untouched.

Verification (implemented and tested on a local branch off e91964cb):

  • New helper tests in tests/unit/CategoryUtilsTest.ts: disabling all unrestricted categories returns [], and disabling all categories where one is restricted returns only the restricted member. Both FAIL on baseline (returning all members) and pass with the fix. Full suite: 82/82 pass.
  • New UI tests in tests/ui/WorkspaceCategoriesTest.tsx: on a Collect workspace with a leftover restriction, bulk disabling all categories shows no visibility modal (fails on baseline, passes with the fix); on a Control workspace with the same data, the visibility modal still appears (protection retained). Full suite: 5/5 pass. Adjacent MembersNeedCategoryErrorTest: 4/4 pass.
  • One staging check remains after merge: confirm the disable succeeds end to end, since the backend can also reject SET_WORKSPACE_CATEGORIES_ENABLED with accountIDs (the middleware path). If the backend mirrors the ungated check, the same gate is needed server-side, which is outside this repo.

What alternative solutions did you explore? (Optional)

  • Gate only at the call sites (the two existing proposals): incomplete. It fixes the Collect repro but leaves the Control-with-no-restrictions case broken, because the helper still flags every member when all unrestricted categories are disabled. The helper fix is needed for the computation to be right on every plan.
  • Fix only the helper, no plan gate: incomplete. It fixes the computation but does not enforce plan eligibility when visibility restrictions remain after a Control-to-Collect downgrade; on a downgraded workspace a restricted member could still be blocked by a feature that no longer exists there.
  • Gate on areCategoriesRequiredInRules: incorrect. Category requirements and category visibility restrictions are independent: a Control workspace may not require categories on all expenses while still restricting members to specific categories, and a Collect workspace with the requirement on must still never see the visibility error.

dankezo avatar Nov 21 '26 15:11 dankezo

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 21 '26 15:11 melvin-bot[bot]