Skip to content
Closed
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
2 changes: 2 additions & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5154,6 +5154,8 @@ const CONST = {
STANDARD_LENGTH_LIMIT: 100,
STANDARD_LIST_ITEM_LIMIT: 12,
SEARCH_BAR_THRESHOLD: 3,
// Minimum number of domain groups required before the search bar is shown on the Domain → Groups table.
DOMAIN_GROUPS_SEARCH_BAR_THRESHOLD: 15,
// Number of approval workflow cards rendered before the "Load more" affordance on Workspace → Workflows.
WORKFLOW_APPROVALS_INITIAL_BATCH: 5,
LOGIN_CHARACTER_LIMIT: 254,
Expand Down
12 changes: 9 additions & 3 deletions src/components/Table/TableFilterBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ import TableSearchBar from './TableSearchBar';
type TableFilterBarProps = PropsWithChildren<{
/** Label and accessibility label for the search input. */
label: string;

/** The minimum number of items (before searching/filtering) required to render the search bar. Defaults to 0 so the search bar always shows. */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

❌ CLEAN-REACT-PATTERNS-1 (docs)

The new minItemsForSearchBar prop is configuration that gates whether an internal UI element renders: its sole effect is the conditional {shouldShowSearchBar && <TableSearchBar label={label} />} block below. Table is already a compound/composition component (Table.FilterBar, Table.Header, Table.Body, Table.NoResultsState), so search-bar presence should be expressed compositionally (the consumer includes or omits the search bar) rather than by threading a numeric threshold prop that branches inside the component. Each new threshold/flag prop enlarges the component's API and couples every consumer to its internals.

Suggested fix: expose the search bar as a composable child (e.g. Table.SearchBar) that the consumer renders or not, and let DomainGroupsTable decide whether to include it based on the item count, instead of adding minItemsForSearchBar to TableFilterBar:

// DomainGroupsTable
<Table.FilterBar label={translate('domain.groups.findGroup')}>
    {groups.length >= CONST.DOMAIN_GROUPS_SEARCH_BAR_THRESHOLD && <Table.SearchBar label={translate('domain.groups.findGroup')} />}
</Table.FilterBar>

Reviewed at: daab196 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

minItemsForSearchBar?: number;
}>;

export default function TableFilterBar({label, children}: TableFilterBarProps) {
export default function TableFilterBar({label, minItemsForSearchBar = 0, children}: TableFilterBarProps) {
const styles = useThemeStyles();
const {filterConfig, tableMethods, activeFilters, originalDataLength, shouldUseNarrowTableLayout} = useTableContext();

const hasFiltersAvailable = Object.keys(filterConfig ?? {}).length > 0;
const actionColumnVisible = hasFiltersAvailable || !!children;
const shouldShowSearchBar = originalDataLength >= minItemsForSearchBar;

const appliedFilters = Object.entries(activeFilters ?? {})
.filter(([, value]) => !!value?.length)
Expand Down Expand Up @@ -57,15 +61,17 @@ export default function TableFilterBar({label, children}: TableFilterBarProps) {
</View>
);

if (!originalDataLength) {
const hasVisibleContent = shouldShowSearchBar || !!appliedFilters.length || actionColumnVisible;

if (!originalDataLength || !hasVisibleContent) {
return null;
}

return (
<View style={[styles.w100, styles.gap3, styles.pb3, styles.ph5]}>
<View style={[styles.flexRow, styles.gap3, styles.justifyContentBetween, shouldUseNarrowTableLayout && styles.alignItemsCenter]}>
<View style={[styles.flex1, styles.flexRow, styles.flexWrap, styles.gap2, styles.alignItemsCenter]}>
<TableSearchBar label={label} />
{shouldShowSearchBar && <TableSearchBar label={label} />}
{!shouldUseNarrowTableLayout && ActiveFilterChipsComponent}
</View>

Expand Down
7 changes: 6 additions & 1 deletion src/components/Tables/DomainGroupsTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import tokenizedSearch from '@libs/tokenizedSearch';

import variables from '@styles/variables';

import CONST from '@src/CONST';

import type {ListRenderItemInfo} from '@shopify/flash-list';

import React, {useRef} from 'react';
Expand Down Expand Up @@ -87,7 +89,10 @@ export default function DomainGroupsTable({domainAccountID, groups}: DomainGroup
title={translate('domain.groups.title')}
keyExtractor={(item) => item.keyForList}
>
<Table.FilterBar label={translate('domain.groups.findGroup')} />
<Table.FilterBar
label={translate('domain.groups.findGroup')}
minItemsForSearchBar={CONST.DOMAIN_GROUPS_SEARCH_BAR_THRESHOLD}
/>
<Table.NoResultsState />
<Table.Header />
<Table.Body />
Expand Down
Loading