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

[$250] The focused background isn't updated when the selected option is updated from BE side #54089

Open
1 of 8 tasks
m-natarajan opened this issue Dec 13, 2024 · 11 comments
Open
1 of 8 tasks
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor Help Wanted Apply this label when an issue is open to proposals by contributors

Comments

@m-natarajan
Copy link

m-natarajan commented Dec 13, 2024

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Version Number: 9.0.75-6
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught on HybridApp, is this reproducible on New Expensify Standalone?:
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: @DylanDylann
Slack conversation (hyperlinked to channel name): expensify_bugs

Action Performed:

  1. In the device 1, go to Settings> Preferences > Priority mode
  2. In the device 2, go to Settings> Preferences > Priority mode
  3. In the device 2, click on another option

Expected Result:

The selected option is updated in the device 1 but the focus background isn't updated

Actual Result:

The focused background isn't updated in the device 1

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android: Standalone
  • Android: HybridApp
  • Android: mWeb Chrome
  • iOS: Standalone
  • iOS: HybridApp
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence
Screen.Recording.2024-12-12.at.11.29.54.mov
Recording.844.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021867633562881780913
  • Upwork Job ID: 1867633562881780913
  • Last Price Increase: 2024-12-13
Issue OwnerCurrent Issue Owner: @
Issue OwnerCurrent Issue Owner: @DylanDylann
@m-natarajan m-natarajan added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Dec 13, 2024
Copy link

melvin-bot bot commented Dec 13, 2024

Triggered auto assignment to @michaelkwardrop (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

@nyomanjyotisa
Copy link
Contributor

Proposal

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

The focused background isn't updated when the selected option is updated from BE side

What is the root cause of that problem?

The focus is not updated when the selected priority mode changes, causing the UI to stay focused on the old selection.

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

We should manage the focus using a state variable (focusedKey) that gets updated when the priorityMode changes. This ensures the UI focus stays in sync with the selected priority mode.

    const [focusedKey, setFocusedKey] = useState(priorityMode);

    useEffect(() => {
        setFocusedKey(priorityMode);
    }, [priorityMode]);

And change the SelectionList to this

            <SelectionList
                sections={[{data: priorityModes}]}
                ListItem={RadioListItem}
                onSelectRow={(mode) => {
                    updateMode(mode);
                    setFocusedKey(mode.keyForList);
                }}
                shouldSingleExecuteRowSelect
                initiallyFocusedOptionKey={focusedKey}
                key={focusedKey}
            />

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

What alternative solutions did you explore? (Optional)

POC

New-Expensify.mp4

@linhvovan29546
Copy link

linhvovan29546 commented Dec 13, 2024

Edited by proposal-police: This proposal was edited at 2024-12-13 02:47:13 UTC.

Proposal

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

The focused background isn't updated when the selected option is updated from BE side

What is the root cause of that problem?

In BaseSelectionList, the getItemBackgroundColorStyle function is used to get the background color for an item. This function only applies a background color if isFocused is true. When updates are received from the backend, only the isSelected state of priorityModes is updated, but isFocused is not. As a result, the focused background does not change.

isFocused && StyleUtils.getItemBackgroundColorStyle(!!item.isSelected, !!isFocused, !!item.isDisabled, theme.activeComponentBG, theme.hoverComponentBG),

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

Out dated

In PreferencesPage, we should use a useEffect with priorityModes as a dependency to determine the focusedIndex and then call ref.current.setFocusedIndex(focusedIndex).

useEffect(() => {
        const handleFocus = () => {
            const focusedIndex = priorityModes.findIndex((mode) => mode.isSelected)
            refSelectionList.current?.setFocusedIndex(focusedIndex)
        }
        handleFocus()
    }, [priorityModes])
.....
            <SelectionList
                ref={refSectionList}
                //    other props
             />

We also need to export the setFocusedIndex method from BaseSelectionList using useImperativeHandle to enable this functionality.

useImperativeHandle(ref, () => ({scrollAndHighlightItem, clearInputAfterSelect, updateAndScrollToFocusedIndex, updateExternalTextInputFocus, scrollToIndex}), [
scrollAndHighlightItem,
clearInputAfterSelect,
updateAndScrollToFocusedIndex,
updateExternalTextInputFocus,
scrollToIndex,
]);

New proposal:

In the BaseSelectionList add a new prop shouldAutoUpdateFocusedIndex, with a default value of false. This prop will be set to true only in the specific places where the focused index needs to be updated automatically, in order to avoid regression.
Use useEffect with flattenedSections as a dependency to update focusedIndex

    const isRenderRef = useRef(false)

    useEffect(() => {
        if (!shouldAutoUpdateFocusedIndex) return
        if (!isRenderRef.current) {
            isRenderRef.true
            return
        }
        const handleUpdateFocusedIndex = () => {
            const focusedIndex = flattenedSections.allOptions.findIndex((section) => section.isSelected)
            setFocusedIndex(focusedIndex)
        }
        handleUpdateFocusedIndex()
    }, [shouldAutoUpdateFocusedIndex, flattenedSections.allOptions])

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

Edited at 2024-12-14 04:46:13 UTC.
I don't see any test files for this, so I think we need to implement UI tests for the BaseSelectionList component, including the following actions: render the BaseSelectionList with the correct selected status, handling item press, and rerender the BaseSelectionList with the updated selected status.

N/A

What alternative solutions did you explore? (Optional)

N/A

@daledah
Copy link
Contributor

daledah commented Dec 13, 2024

Proposal

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

The focused background isn't updated in the device 1

What is the root cause of that problem?

In BaseSelectionList, we don't have logics to change focusedIndex when there's update from BE.

This Bug also appears on similar pages: Language and Theme settings.

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

Add an useEffect to change focusedIndex when list data is updated to after here:

    useEffect(() => {
        const selectedItemIndex = flattenedSections.allOptions.findIndex((option) => option.isSelected);
        if (selectedItemIndex === -1 || selectedItemIndex === focusedIndex) {
            return;
        }
        setFocusedIndex(selectedItemIndex);
    }, [flattenedSections]);

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

What alternative solutions did you explore? (Optional)

We can pass key to SelectionList in PriorityModePage to force re-render when priority mode is changed, however this can cause unwanted extra render count and make the UI briefly flashes but still noticeable.

@DylanDylann
Copy link
Contributor

hey contributors, please make sure that your proposal also fix this problem

@DylanDylann
Copy link
Contributor

DylanDylann commented Dec 13, 2024

@linhvovan29546
Copy link

Updated proposal to fix this problem

#54089 (comment)

@mountiny mountiny added the External Added to denote the issue can be worked on by a contributor label Dec 13, 2024
Copy link

melvin-bot bot commented Dec 13, 2024

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

@melvin-bot melvin-bot bot changed the title The focused background isn't updated when the selected option is updated from BE side [$250] The focused background isn't updated when the selected option is updated from BE side Dec 13, 2024
@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Dec 13, 2024
Copy link

melvin-bot bot commented Dec 13, 2024

Current assignee @DylanDylann is eligible for the External assigner, not assigning anyone new.

@mountiny
Copy link
Contributor

What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

Make sure to add tests too

@linhvovan29546
Copy link

Updated proposal to add automated tests

#54089 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor Help Wanted Apply this label when an issue is open to proposals by contributors
Projects
Development

No branches or pull requests

7 participants