Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ function BaseSelectionListWithSections<TItem extends ListItem>({
includeSafeAreaPaddingBottom = true,
shouldTextInputInterceptSwipe = false,
listHeaderContent,
showSectionTitleWithListHeaderContent = false,
onEndReached,
onEndReachedThreshold,
windowSize = 5,
Expand Down Expand Up @@ -593,7 +594,7 @@ function BaseSelectionListWithSections<TItem extends ListItem>({
return <section.CustomSectionHeader section={section} />;
}

if (!section.title || isEmptyObject(section.data) || listHeaderContent) {
if (!section.title || isEmptyObject(section.data) || (!showSectionTitleWithListHeaderContent && listHeaderContent)) {
return null;
}

Expand Down
3 changes: 3 additions & 0 deletions src/components/SelectionListWithSections/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,9 @@ type SelectionListProps<TItem extends ListItem> = Partial<ChildrenProps> & {
/** Custom content to display in the header of list component. */
listHeaderContent?: React.JSX.Element | null;

/** By default, when `listHeaderContent` is passed, the section title will not be rendered. This flag allows the section title to still be rendered in certain cases. */
showSectionTitleWithListHeaderContent?: boolean;

Comment thread
dmkt9 marked this conversation as resolved.
Resolved
/** Custom content to display in the footer */
footerContent?: ReactNode;

Expand Down
2 changes: 1 addition & 1 deletion src/libs/OptionsListUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,7 @@ function optionsOrderBy<T = SearchOptionData>(options: T[], comparator: (option:
if (!peekedValue) {
throw new Error('Heap is empty, cannot peek value');
}
if (comparator(option) > comparator(peekedValue)) {
if (reversed ? comparator(option) < comparator(peekedValue) : comparator(option) > comparator(peekedValue)) {
heap.pop();
heap.push(option);
}
Expand Down
8 changes: 4 additions & 4 deletions src/pages/iou/request/MoneyRequestParticipantsSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ function MoneyRequestParticipantsSelector({
[isIOUSplit, addParticipantToSelection, addSingleParticipant],
);

const footerContentAbovePaginationComponent = useMemo(() => {
const importContactsButtonComponent = useMemo(() => {
const shouldShowImportContactsButton = contactState?.showImportUI ?? showImportContacts;
if (!shouldShowImportContactsButton) {
return null;
Expand All @@ -515,10 +515,9 @@ function MoneyRequestParticipantsSelector({
icon={icons.UserPlus}
onPress={goToSettings}
shouldShowRightIcon
style={styles.mb3}
/>
);
}, [icons.UserPlus, contactState?.showImportUI, showImportContacts, styles.mb3, translate]);
}, [icons.UserPlus, contactState?.showImportUI, showImportContacts, translate]);

const ClickableImportContactTextComponent = useMemo(() => {
if (searchTerm.length || isSearchingForReports) {
Expand Down Expand Up @@ -580,7 +579,8 @@ function MoneyRequestParticipantsSelector({
}
footerContent={footerContent}
listEmptyContent={EmptySelectionListContentWithPermission}
footerContentAbovePagination={footerContentAbovePaginationComponent}
listHeaderContent={importContactsButtonComponent}
showSectionTitleWithListHeaderContent
headerMessage={header}
showLoadingPlaceholder={showLoadingPlaceholder}
canSelectMultiple={isIOUSplit && isAllowedToSplit}
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/OptionsListUtilsTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2493,6 +2493,23 @@ describe('OptionsListUtils', () => {
const result = optionsOrderBy(options, comparator, 0);
expect(result).toEqual([]);
});

it('returns the older options up to the specified limit', () => {
const options: OptionData[] = [
{reportID: '1', lastVisibleActionCreated: '2022-01-01T10:00:00Z'} as OptionData,
{reportID: '2', lastVisibleActionCreated: '2022-01-01T12:00:00Z'} as OptionData,
{reportID: '3', lastVisibleActionCreated: '2022-01-01T09:00:00Z'} as OptionData,
{reportID: '4', lastVisibleActionCreated: '2022-01-01T13:00:00Z'} as OptionData,
];
const comparator = (option: OptionData) => option.lastVisibleActionCreated ?? '';
// We will pass reversed === true to sort the list in ascending order
const result = optionsOrderBy(options, comparator, 2, undefined, true);
expect(result.length).toBe(2);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
expect(result.at(0)!.reportID).toBe('3');
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
expect(result.at(1)!.reportID).toBe('1');
});
});

describe('sortAlphabetically', () => {
Expand Down