Skip to content

Conversation

Bonymol-aot
Copy link
Contributor

@Bonymol-aot Bonymol-aot commented Jun 20, 2025

User description

Issue Tracking

JIRA: https://aottech.atlassian.net/browse/FWF-4820
Issue Type: BUG/ FEATURE

Changes

  • Modified delete message and button if the selected filter(task & attribute) is private
  • Attribute access issue fixed

PR Type

Bug fix


Description

  • Ensure attributeFilter exists before share logic

  • Show undo warning for private filters deletion

  • Update delete button text per ownership scope

  • Apply same fixes in task filter modal


Changes walkthrough 📝

Relevant files
Bug fix
AttributeFIlterModalBody.tsx
Guard attribute filter share logic                                             

forms-flow-review/src/components/AttributeFilterModal/AttributeFIlterModalBody.tsx

  • Add attributeFilter existence guard in useEffect
  • Prevent share option misassignment when undefined
  • +1/-1     
    AttributeFilterModal.tsx
    Customize attribute filter delete modal text                         

    forms-flow-review/src/components/AttributeFilterModal/AttributeFilterModal.tsx

  • Conditional delete warning message based on
    attributeFilterToEdit.users
  • Adjust secondaryBtnText to reflect filter scope
  • +3/-2     
    TaskFilterModal.tsx
    Customize task filter delete modal text                                   

    forms-flow-review/src/components/TaskFilterModal/TaskFilterModal.tsx

  • Conditional delete warning message based on filterToEdit.users
  • Adjust secondaryBtnText to reflect filter scope
  • +3/-2     

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • @Bonymol-aot Bonymol-aot requested review from a team as code owners June 20, 2025 06:20
    Copy link

    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Reversed Conditional

    The condition for determining private vs. shared filters is inverted, causing the wrong delete message and button text to display.

        content={(attributeFilterToEdit.users.length>0) ? t("This action cannot be undone."): 
          t(
          "This filter is shared with others. Deleting this filter will delete it for everybody and might affect their workflow."
        )}
        dataTestId="attribute-filter-delete-note"
      />
    }
    primaryBtnAction={toggleDeleteModal}
    onClose={toggleDeleteModal}
    primaryBtnText={t("No, Keep This Filter")}
    secondaryBtnText={(attributeFilterToEdit.users.length>0) ? t("Yes, Delete This Filter"): t("Yes, Delete This Filter For Everybody")  }
    Reversed Conditional

    The users length check is reversed, leading to incorrect delete confirmation labels for shared and private filters.

        content={(filterToEdit.users.length>0) ? t("This action cannot be undone."): 
          t(
          "This filter is shared with others. Deleting this filter will delete it for everybody and might affect their workflow."
        )}
        dataTestId="task-filter-delete-note"
      />
    }
    primaryBtnAction={toggleDeleteModal}
    onClose={toggleDeleteModal}
    primaryBtnText={t("No, Keep This Filter")}
    secondaryBtnText={(filterToEdit.users.length>0) ? t("Yes, Delete This Filter"): t("Yes, Delete This Filter For Everybody")  }
    Loose Equality

    Loose equality operator (==) is used instead of strict (===) when comparing array lengths; consider using === for consistency and type safety.

    if(attributeFilter &&(selectedAttributeFilter?.roles.length > 0 || (selectedAttributeFilter?.users.length == 0 && selectedAttributeFilter.roles.length == 0))){ 
      setShareAttrFilter(FILTER_SHARE_OPTIONS.SAME_AS_TASKS);

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Use correct variable with safe checks

    Protect against undefined nested arrays and unintended variable references by using
    the correct variable and optional chaining, and switch to strict equality checks.
    This prevents runtime errors if the filter or its properties are missing.

    forms-flow-review/src/components/AttributeFilterModal/AttributeFIlterModalBody.tsx [174]

    -if(attributeFilter &&(selectedAttributeFilter?.roles.length > 0 || (selectedAttributeFilter?.users.length == 0 && selectedAttributeFilter.roles.length == 0))){
    +if (
    +  selectedAttributeFilter?.roles?.length > 0 ||
    +  (selectedAttributeFilter?.users?.length === 0 && selectedAttributeFilter?.roles?.length === 0)
    +) {
    Suggestion importance[1-10]: 4

    __

    Why: The suggestion adds optional chaining and strict equality to avoid undefined errors, but it drops the original attributeFilter guard and may alter the intended logic, so it’s only moderately impactful.

    Low
    Guard user list access

    Add optional chaining when accessing users to avoid errors if attributeFilterToEdit
    or its users array is undefined.

    forms-flow-review/src/components/AttributeFilterModal/AttributeFilterModal.tsx [138]

    -content={(attributeFilterToEdit.users.length>0) ? t("This action cannot be undone.") : t("This filter is shared with others. Deleting this filter will delete it for everybody and might affect their workflow.")}
    +content={(
    +  attributeFilterToEdit?.users?.length > 0
    +)
    +  ? t("This action cannot be undone.")
    +  : t("This filter is shared with others. Deleting this filter will delete it for everybody and might affect their workflow.")
    +}
    Suggestion importance[1-10]: 3

    __

    Why: Adding optional chaining for attributeFilterToEdit?.users?.length prevents potential runtime errors, but it’s a minor safety improvement with limited impact.

    Low
    Safely access users length

    Use optional chaining on filterToEdit.users to prevent null or undefined errors when
    computing the button text.

    forms-flow-review/src/components/TaskFilterModal/TaskFilterModal.tsx [165]

    -secondaryBtnText={(filterToEdit.users.length>0) ? t("Yes, Delete This Filter") : t("Yes, Delete This Filter For Everybody")}
    +secondaryBtnText={(
    +  filterToEdit?.users?.length > 0
    +)
    +  ? t("Yes, Delete This Filter")
    +  : t("Yes, Delete This Filter For Everybody")
    +}
    Suggestion importance[1-10]: 3

    __

    Why: Introducing optional chaining on filterToEdit?.users?.length guards against undefined values, though it’s a small defensive change and doesn’t affect core functionality.

    Low

    className="note"
    heading="Note"
    content={t(
    content={(attributeFilterToEdit.users.length>0) ? t("This action cannot be undone."):
    Copy link
    Contributor

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    does attributeFilterToEdit.users.length>0 means it is private ? @Bonymol-aot

    @arun-s-aot arun-s-aot merged commit 840acdd into AOT-Technologies:develop Jun 20, 2025
    4 checks passed
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    2 participants