Skip to content

Commit

Permalink
Merge pull request #56543 from FitseTLT/fix-add-no-results-found-on-e…
Browse files Browse the repository at this point in the history
…mpty-company-card-search-list

Fix - Company card - Missing "No results found" message when there is no card result
  • Loading branch information
MarioExpensify authored Feb 12, 2025
2 parents 2fbd77a + bf4cef4 commit 532d95d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ function BaseSelectionList<TItem extends ListItem>(
sectionTitleStyles,
textInputAutoFocus = true,
shouldShowTextInputAfterHeader = false,
shouldShowHeaderMessageAfterHeader = false,
includeSafeAreaPaddingBottom = true,
shouldTextInputInterceptSwipe = false,
listHeaderContent,
Expand Down Expand Up @@ -805,6 +806,14 @@ function BaseSelectionList<TItem extends ListItem>(
},
);

const headerMessageContent = () =>
(!isLoadingNewOptions || headerMessage !== translate('common.noResultsFound') || (flattenedSections.allOptions.length === 0 && !showLoadingPlaceholder)) &&
!!headerMessage && (
<View style={headerMessageStyle ?? [styles.ph5, styles.pb5]}>
<Text style={[styles.textLabel, styles.colorMuted, styles.minHeight5]}>{headerMessage}</Text>
</View>
);

const {safeAreaPaddingBottomStyle} = useStyledSafeAreaInsets();

// TODO: test _every_ component that uses SelectionList
Expand All @@ -813,11 +822,7 @@ function BaseSelectionList<TItem extends ListItem>(
{shouldShowTextInput && !shouldShowTextInputAfterHeader && renderInput()}
{/* If we are loading new options we will avoid showing any header message. This is mostly because one of the header messages says there are no options. */}
{/* This is misleading because we might be in the process of loading fresh options from the server. */}
{(!isLoadingNewOptions || headerMessage !== translate('common.noResultsFound') || (flattenedSections.allOptions.length === 0 && !showLoadingPlaceholder)) && !!headerMessage && (
<View style={headerMessageStyle ?? [styles.ph5, styles.pb5]}>
<Text style={[styles.textLabel, styles.colorMuted, styles.minHeight5]}>{headerMessage}</Text>
</View>
)}
{!shouldShowHeaderMessageAfterHeader && headerMessageContent()}
{!!headerContent && headerContent}
{flattenedSections.allOptions.length === 0 && (showLoadingPlaceholder || shouldShowListEmptyContent) ? (
renderListEmptyContent()
Expand Down Expand Up @@ -859,6 +864,7 @@ function BaseSelectionList<TItem extends ListItem>(
<>
{listHeaderContent}
{renderInput()}
{shouldShowHeaderMessageAfterHeader && headerMessageContent()}
</>
) : (
listHeaderContent
Expand Down
3 changes: 3 additions & 0 deletions src/components/SelectionList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,9 @@ type BaseSelectionListProps<TItem extends ListItem> = Partial<ChildrenProps> & {
/** Whether the text input should be shown after list header */
shouldShowTextInputAfterHeader?: boolean;

/** Whether the header message should be shown after list header */
shouldShowHeaderMessageAfterHeader?: boolean;

/** Whether to include padding bottom */
includeSafeAreaPaddingBottom?: boolean;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ function CardSelectionStep({feed, policyID}: CardSelectionStepProps) {
<>
<SelectionList
sections={[{data: searchedListOptions}]}
headerMessage={searchedListOptions.length ? undefined : translate('common.noResultsFound')}
shouldShowTextInput={cardListOptions.length > CONST.COMPANY_CARDS.CARD_LIST_THRESHOLD}
textInputLabel={translate('common.search')}
textInputValue={searchText}
Expand All @@ -157,6 +158,7 @@ function CardSelectionStep({feed, policyID}: CardSelectionStepProps) {
</View>
}
shouldShowTextInputAfterHeader
shouldShowHeaderMessageAfterHeader
includeSafeAreaPaddingBottom={false}
shouldShowListEmptyContent={false}
shouldUpdateFocusedIndex
Expand Down

0 comments on commit 532d95d

Please sign in to comment.