Skip to content

fix: avoid duplicated /SearchForReport calls #60810

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

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a9ab1fe
fix: avoid duplicated /SearchForReport calls
martasudol Apr 24, 2025
0b5ea99
Merge branch 'main' into avoid-duplicated-search-for-reports-calls
martasudol Apr 24, 2025
d1f5510
fix: avoid duplicated /SearchForReport calls
martasudol Apr 24, 2025
52b835f
fix: avoid duplicated /SearchForReport calls
martasudol Apr 24, 2025
2e9d962
fix: avoid duplicated /SearchForReport calls
martasudol Apr 24, 2025
712ca22
fix: avoid duplicated /SearchForReport calls
martasudol Apr 24, 2025
fdf27e4
fix: avoid duplicated /SearchForReport calls
martasudol Apr 24, 2025
214c235
fix: avoid duplicated /SearchForReport calls
martasudol Apr 24, 2025
c2849bb
fix: avoid duplicated /SearchForReport calls
martasudol Apr 25, 2025
6d7b55e
Fix bug with /SearchForReports calls on input focus
martasudol Apr 28, 2025
a0c27f6
Moved Search feature documentation to contributingGuides
martasudol Apr 28, 2025
69fe490
Revert docs/_data_.routes.yml to match main
martasudol Apr 28, 2025
fda4689
Fix prettier issues
martasudol Apr 28, 2025
b4a006c
Fix tests
martasudol Apr 28, 2025
65a1c8d
Fix prettier
martasudol Apr 28, 2025
26ad8a4
Fix prettier
martasudol Apr 28, 2025
3c97469
Use getQueryWithoutFilters to rely on query comparison to handle sear…
martasudol Apr 29, 2025
cc05bde
prettier & eslint fixes
martasudol Apr 29, 2025
a75af9c
prettier & eslint fixes
martasudol Apr 29, 2025
2d89229
prettier & eslint fixes
martasudol Apr 29, 2025
9420b43
Refactoring
martasudol Apr 30, 2025
43c5bb1
Prettier
martasudol Apr 30, 2025
641f18c
Merge branch 'main' into avoid-duplicated-search-for-reports-calls
martasudol May 12, 2025
6f94129
build search query optimization
martasudol May 12, 2025
5997f36
PR comments addressed
martasudol May 13, 2025
aa28dc9
prettier fixes
martasudol May 13, 2025
68cd35b
Merge branch 'main' into avoid-duplicated-search-for-reports-calls
martasudol May 14, 2025
83d600e
fix: `/SearchForReports` call on autocomplete result item click
martasudol May 14, 2025
2f7f97f
fix: `/SearchForReports` call missing for narrow resolutions
martasudol May 14, 2025
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
Copy link
Contributor

Choose a reason for hiding this comment

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

Overall I am not sure if this will be that useful as search changes often ad we will be updating the help site with similar data and surely we will forget to keep this up to date

File renamed without changes.
24 changes: 10 additions & 14 deletions docs/_data/_routes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ platforms:
url: www.expensify.com
description: "Your account settings look like this:"
image: /assets/images/settings-old-dot.svg

# Hubs are comprised of subcategories and articles. Subcategories contain multiple related articles, but there can be standalone articles as well
hubs:
- href: getting-started
Expand All @@ -38,7 +38,7 @@ platforms:
title: Domains
icon: /assets/images/domains.svg
description: Claim and verify your company’s domain to access additional management and security features.

- href: bank-accounts-and-payments
title: Bank Accounts & Payments
icon: /assets/images/send-money.svg
Expand Down Expand Up @@ -88,16 +88,16 @@ platforms:
title: Travel
icon: /assets/images/plane.svg
description: Manage all your corporate travel needs with Expensify Travel.


- href: new-expensify
title: New Expensify
hub-title: New Expensify - Help & Resources
hub-description: Questions? Find the answers by clicking a Category or using the search bar.
url: new.expensify.com
description: "Your account settings look like this:"
image: /assets/images/settings-new-dot.svg

hubs:
- href: getting-started
title: Getting Started
Expand All @@ -113,7 +113,7 @@ platforms:
title: Workspaces
icon: /assets/images/shield.svg
description: Configure rules, settings, and limits for your company’s spending.

- href: reports-and-expenses
title: Reports & Expenses
icon: /assets/images/envelope-receipt.svg
Expand All @@ -128,12 +128,12 @@ platforms:
title: Connect Credit Cards
icon: /assets/images/bank-card.svg
description: Track credit card transactions and reconcile company cards.

- href: expensify-card
title: Expensify Card
icon: /assets/images/hand-card.svg
description: Explore the perks and benefits of the Expensify Card.

- href: travel
title: Travel
icon: /assets/images/plane.svg
Expand All @@ -148,13 +148,9 @@ platforms:
title: Settings
icon: /assets/images/gears.svg
description: Manage profile settings and notifications.

- href: billing-and-subscriptions
title: Expensify Billing & Subscriptions
icon: /assets/images/subscription-annual.svg
description: Review Expensify's subscription options, plan types, and payment methods.

- href: search-overview
title: Search Functionality in New Expensify
icon: /assets/images/magnifying-glass.svg
description: Search feature overview.

24 changes: 19 additions & 5 deletions src/components/Search/SearchAutocompleteList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Str} from 'expensify-common';
import React, {forwardRef, useCallback, useEffect, useMemo, useState} from 'react';
import React, {forwardRef, useCallback, useEffect, useMemo, useRef, useState} from 'react';
import type {ForwardedRef} from 'react';
import {useOnyx} from 'react-native-onyx';
import * as Expensicons from '@components/Icon/Expensicons';
Expand Down Expand Up @@ -503,14 +503,28 @@ function SearchAutocompleteList(
return reportOptions.slice(0, 20);
}, [autocompleteQueryValue, filterOptions, searchOptions]);

// Store the initial query value
const initialRenderRef = useRef(true);
const prevQueryRef = useRef(autocompleteQueryValue);

useEffect(() => {
if (!handleSearch) {
return;
}
handleSearch(autocompleteQueryValue);
// eslint-disable-next-line react-compiler/react-compiler
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [autocompleteQueryValue]);

// If this is the first render, just store the query but don't call the API
if (initialRenderRef.current) {
initialRenderRef.current = false;
prevQueryRef.current = autocompleteQueryValue;
return;
}

// Only call the API if the query has changed from the previous value
if (prevQueryRef.current !== autocompleteQueryValue) {
prevQueryRef.current = autocompleteQueryValue;
handleSearch(autocompleteQueryValue);
}
}, [autocompleteQueryValue, handleSearch]);

/* Sections generation */
const sections: Array<SectionListDataType<OptionData | SearchQueryItem>> = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ function SearchPageHeaderInput({queryJSON, searchRouterListVisible, hideSearchRo

useEffect(() => {
setTextInputValue(isDefaultQuery ? '' : queryText);
setAutocompleteQueryValue(isDefaultQuery ? '' : queryText);
}, [isDefaultQuery, queryText]);

useEffect(() => {
Expand Down
6 changes: 1 addition & 5 deletions src/components/Search/SearchRouter/SearchRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,6 @@ function SearchRouter({onRouterClose, shouldHideInputCaret, isSearchRouterDispla
[setSelection, setTextInputValue],
);

const handleSearchAction = (value: string) => {
searchInServer(value);
};

const onListItemPress = useCallback(
(item: OptionData | SearchQueryItem) => {
if (isSearchQueryItem(item)) {
Expand Down Expand Up @@ -351,7 +347,7 @@ function SearchRouter({onRouterClose, shouldHideInputCaret, isSearchRouterDispla
/>
<SearchAutocompleteList
autocompleteQueryValue={autocompleteQueryValue || textInputValue}
handleSearch={handleSearchAction}
handleSearch={searchInServer}
searchQueryItem={searchQueryItem}
getAdditionalSections={getAdditionalSections}
onListItemPress={onListItemPress}
Expand Down
Loading