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

Fix - Company card - Missing "No results found" message when there is no card result #56543

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 @@ -813,6 +814,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 @@ -821,11 +830,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 @@ -867,6 +872,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 @@ -465,6 +465,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