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] [Search v2.2] - List does not scroll down and "To" field is hidden when "Save search" button appears #49257

Closed
6 tasks done
IuliiaHerets opened this issue Sep 16, 2024 · 21 comments
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 Engineering 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

@IuliiaHerets
Copy link

IuliiaHerets commented Sep 16, 2024

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 9.0.35-4
Reproducible in staging?: Y
Reproducible in production?: N
Email or phone of affected tester (no customers): applausetester+kh010901@applause.expensifail.com
Issue reported by: Applause Internal Team

Action Performed:

  1. Go to staging.new.expensify.com
  2. Go to Search.
  3. Click Filters.
  4. Scroll down to the bottom.
  5. Click "To".
  6. Select any user and save it.

Expected Result:

The list will auto scroll down to show "To" field when "Save search" button appears.

Actual Result:

The list does not auto scroll down and "To" field is hidden when "Save search" button appears.

Workaround:

Unknown

Platforms:

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Bug6605317_1726482606930.20240916_182646.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021835635471984345939
  • Upwork Job ID: 1835635471984345939
  • Last Price Increase: 2024-09-23
Issue OwnerCurrent Issue Owner: @akinwale
@IuliiaHerets IuliiaHerets added DeployBlockerCash This issue or pull request should block deployment Bug Something is broken. Auto assigns a BugZero manager. labels Sep 16, 2024
Copy link

melvin-bot bot commented Sep 16, 2024

Triggered auto assignment to @VictoriaExpensify (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.

Copy link

melvin-bot bot commented Sep 16, 2024

Triggered auto assignment to @Gonals (DeployBlockerCash), see https://stackoverflowteams.com/c/expensify/questions/9980/ for more details.

@melvin-bot melvin-bot bot added the Daily KSv2 label Sep 16, 2024
@IuliiaHerets
Copy link
Author

We think that this bug might be related to #wave-control

@github-actions github-actions bot added Engineering Hourly KSv2 and removed Daily KSv2 labels Sep 16, 2024
Copy link
Contributor

👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:

  1. Identify the pull request that introduced this issue and revert it.
  2. Find someone who can quickly fix the issue.
  3. Fix the issue yourself.

@lakchote
Copy link
Contributor

Not a blocker, it's a minor UI bug. Putting the external label.

@lakchote lakchote added External Added to denote the issue can be worked on by a contributor Daily KSv2 Help Wanted Apply this label when an issue is open to proposals by contributors and removed Hourly KSv2 labels Sep 16, 2024
@melvin-bot melvin-bot bot changed the title Search - List does not scroll down and "To" field is hidden when "Save search" button appears [$250] Search - List does not scroll down and "To" field is hidden when "Save search" button appears Sep 16, 2024
Copy link

melvin-bot bot commented Sep 16, 2024

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

Copy link

melvin-bot bot commented Sep 16, 2024

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

@huult
Copy link
Contributor

huult commented Sep 16, 2024

Edited by proposal-police: This proposal was edited at 2023-10-09T08:43:00Z.

Proposal

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

List does not scroll down and "To" field is hidden when "Save search" button appears

What is the root cause of that problem?

After applying the Save filter, the Save Search button becomes visible

{!SearchUtils.isCannedSearchQuery(queryJSON) && (
<Button
text={translate('search.saveSearch')}
onPress={onSaveSearch}
style={[styles.mh4, styles.mt4]}
large
/>
)}

Screenshot 2024-09-16 at 18 41 02

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

We should calculate the current offset of the scroll and add the height of the Save Search button. Some thing like that:

// .src/pages/Search/AdvancedSearchFilters.tsx#L231
+    const {saveScrollOffset, getScrollOffset} = useContext(ScrollOffsetContext);
+    const route = useRoute();
+    const scrollViewRef = useRef<RNScrollView>(null);
+    const saveSearchRef = useRef<RefObject<View>>(null);

+    const onScroll = useCallback<NonNullable<ScrollViewProps['onScroll']>>((e) => {
+        if (e.nativeEvent.layoutMeasurement.height === 0) {
+            return;
+        }

+        saveScrollOffsetByName(route, e.nativeEvent.contentOffset.y);
+    }, []);

// .src/pages/Search/AdvancedSearchFilters.tsx#L289
+    function isScrollingPossible(scrollOffset: number | null): boolean {
+        return !!scrollOffset && !!scrollViewRef.current && !!saveSearchRef.current;
+    }

+    function measureAndScroll(scrollOffset: number, bufferHeight: number): void {
+        saveSearchRef.current?.measure((_, __, ___, height) => {
+            scrollViewRef.current?.scrollTo({
+                y: scrollOffset + height + bufferHeight,
+                animated: false,
+            });
+        });
+    }

// .src/pages/Search/AdvancedSearchFilters.tsx#L290
            <ScrollView
+                ref={scrollViewRef}
+                onScroll={onScroll}
+                onLayout={() => {
+                    const scrollOffset = getScrollOffsetByName(route);
+                    if (!scrollOffset || !isScrollingPossible(scrollOffset)) {
+                        return;
+                    }

+                    const BUFFER_HEIGHT = 16;
+                    measureAndScroll(scrollOffset, BUFFER_HEIGHT);
+                }}
+                scrollEventThrottle={16}
                 contentContainerStyle={[styles.flexGrow1, styles.justifyContentBetween]}
            >

// .src/pages/Search/AdvancedSearchFilters.tsx#L312
   <Button
                    text={translate('search.saveSearch')}
                    onPress={onSaveSearch}
                    style={[styles.mh4, styles.mt4]}
                    large
+                    ref={saveSearchRef}
                />

.src/components/ScrollOffsetContextProvider.tsx#L87
+ const saveScrollOffsetByName: ScrollOffsetContextValue['saveScrollOffsetByName'] = useCallback((name, scrollOffset) => {
+        scrollOffsetsRef.current[name] = scrollOffset;
+    }, []);

+    const getScrollOffsetByName: ScrollOffsetContextValue['getScrollOffsetByName'] = useCallback((name) => {
+        if (!scrollOffsetsRef.current) {
+            return;
+        }
+        return scrollOffsetsRef.current[name];
+    }, []);

+    const clearScrollOffsetByName: ScrollOffsetContextValue['clearScrollOffsetByName'] = useCallback((name) => {
+        if (!scrollOffsetsRef.current) {
+            return;
+        }
+        delete scrollOffsetsRef.current[name];
+    }, []);


// .src/components/ScrollOffsetContextProvider.tsx#L82
- if (!scrollOffsetkeysOfExistingScreens.includes(key)) {
+ if (
+                    !scrollOffsetkeysOfExistingScreens.includes(key) &&
+                    key !== ADVANCED_SEARCH_FILTER)
+                ) {
                    delete scrollOffsetsRef.current[key];
                }

// .src/components/Search/index.tsx#L132
+    useFocusEffect(
+        useCallback(() => {
+            clearScrollOffsetByName(ADVANCED_SEARCH_FILTER);
+        }, []),
+    );

Here is test branch

POC
Screen.Recording.2024-09-16.at.21.59.31.mov

@ChavdaSachin
Copy link
Contributor

Proposal

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

  • List does not scroll down and "To" field is hidden when "Save search" button appears

What is the root cause of that problem?

  • scrollView offset is retained but after rendering saveButton it hides the last element from scrollView.

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

  • make saveButton always visible but disable the button if all filters are empty.
    <Button
        text={translate('search.saveSearch')}
        onPress={onSaveSearch}
        style={[styles.mh4, styles.mt4]}
        large
        isDisabled={SearchUtils.isCannedSearchQuery(queryJSON)}
    />

{!SearchUtils.isCannedSearchQuery(queryJSON) && (
<Button
text={translate('search.saveSearch')}
onPress={onSaveSearch}
style={[styles.mh4, styles.mt4]}
large
/>
)}

What alternative solutions did you explore? (Optional)

Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

@drminh2807
Copy link

Proposal

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

List does not scroll down and "To" field is hidden when "Save search" button appears

What is the root cause of that problem?

The "Save search" button make scroll view layout change

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

Auto-scroll to last visible position when layout changed

            <ScrollView
                ref={scrollViewRef}
                onLayout={(e) => {
                    const newPosition = positionRef.current - e.nativeEvent.layout.height;
                    if (newPosition < 0) {
                        return;
                    }
                    scrollViewRef.current?.scrollTo({
                        y: newPosition,
                        animated: false,
                    });
                }}
                onScroll={(e) => {
                    positionRef.current = e.nativeEvent.contentOffset.y + e.nativeEvent.layoutMeasurement.height;
                }}
                contentContainerStyle={[styles.flexGrow1, styles.justifyContentBetween]}
            >

What alternative solutions did you explore? (Optional)

N/A

@mountiny mountiny removed the DeployBlockerCash This issue or pull request should block deployment label Sep 16, 2024
@huult
Copy link
Contributor

huult commented Sep 17, 2024

Proposal update

  • Create function get/set/clear offset by name
  • Add test branch

@luacmartins luacmartins changed the title [$250] Search - List does not scroll down and "To" field is hidden when "Save search" button appears [$250] [Search v2.2] - List does not scroll down and "To" field is hidden when "Save search" button appears Sep 19, 2024
@melvin-bot melvin-bot bot added the Overdue label Sep 19, 2024
@VictoriaExpensify
Copy link
Contributor

Hey @akinwale - can you please review these proposals and let us know what you think?

@ChavdaSachin
Copy link
Contributor

Note

Here's the reason why I have recommended to always show the save button over the other approaches.(My Proposal)
I checked out @huult's solution and it again has wrong scrolling behavior for different case.

Check this video

https://github.com/user-attachments/assets/24e76771-4917-4157-a31d-8d58840ecfc2
Notice `Merchant` was scrolled out of view.

And @drminh2807's solution would also behave similar for this case.

So rather, always showing save button is fairly simple and effective solution.

cc. @akinwale

@huult
Copy link
Contributor

huult commented Sep 19, 2024

Thank you for your note, @ChavdaSachin ,
My proposal directly addresses this issue. I will provide an update on your problem after testing during the PR phase. I will update it as follows:

+   const onScroll = useCallback<NonNullable<ScrollViewProps['onScroll']>>((event) => {
+    const { layoutMeasurement, contentOffset, contentSize } = event.nativeEvent;

+    if (layoutMeasurement.height === 0) return;

+    const isAtBottom = layoutMeasurement.height + contentOffset.y >= contentSize.height;

+    if (isAtBottom) {
+        saveScrollOffsetByName(ADVANCED_SEARCH_FILTER, contentOffset.y);
+    } else {
+      getScrollOffsetByName(ADVANCED_SEARCH_FILTER) &&  clearScrollOffsetByName(ADVANCED_SEARCH_FILTER);
+    }
+}, []);
POC
Screen.Recording.2024-09-19.at.13.44.58.mov

cc @akinwale

@ChavdaSachin
Copy link
Contributor

@huult let me help you with the test cases here.

  1. Edit first field and check scroll behavior.
  2. Edit last field and check scroll behavior.
  3. Make sure first field is hidden and then edit second field
  4. Make sure last field is hidden and then edit second last field
  5. Make sure first field is hidden and then edit last visible field
  6. Make sure last field is hidden and then edit first visible field

Note

Perform all of the above test with and without saving.

@akinwale
Copy link
Contributor

@ChavdaSachin Could you post a test video of your proposed solution?

@melvin-bot melvin-bot bot removed the Overdue label Sep 19, 2024
@ChavdaSachin
Copy link
Contributor

Make save button always visible but disable it until all search fields are empty

Screen.Recording.2024-09-19.at.11.04.59.AM.mov

@ChavdaSachin
Copy link
Contributor

@akinwale my solution does not need the steps I mentioned above.

@ChavdaSachin
Copy link
Contributor

@akinwale do you want me to make a video on steps I mentioned above

Copy link

melvin-bot bot commented Sep 23, 2024

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

@melvin-bot melvin-bot bot added the Overdue label Sep 23, 2024
@luacmartins
Copy link
Contributor

This is the expected behavior and not an issue. Closing this issue

@melvin-bot melvin-bot bot removed the Overdue label Sep 23, 2024
@github-project-automation github-project-automation bot moved this from Polish to Done in [#whatsnext] #expense Sep 23, 2024
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 Engineering 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
Archived in project
Development

No branches or pull requests

10 participants