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
2 changes: 2 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6295,6 +6295,7 @@ const CONST = {
SORT_BY: 'sortBy',
SORT_ORDER: 'sortOrder',
POLICY_ID: 'policyID',
GROUP_BY: 'groupBy',
},
SYNTAX_FILTER_KEYS: {
DATE: 'date',
Expand Down Expand Up @@ -6331,6 +6332,7 @@ const CONST = {
SORT_BY: 'sort-by',
SORT_ORDER: 'sort-order',
POLICY_ID: 'workspace',
GROUP_BY: 'group-by',
DATE: 'date',
AMOUNT: 'amount',
EXPENSE_TYPE: 'expense-type',
Expand Down
4 changes: 2 additions & 2 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ const ROUTES = {

SEARCH_ROOT: {
route: 'search',
getRoute: ({query, name, groupBy}: {query: SearchQueryString; name?: string; groupBy?: string}) => {
return `search?q=${encodeURIComponent(query)}${groupBy ? `&groupBy=${groupBy}` : ''}${name ? `&name=${name}` : ''}` as const;
getRoute: ({query, name}: {query: SearchQueryString; name?: string}) => {
return `search?q=${encodeURIComponent(query)}${name ? `&name=${name}` : ''}` as const;
},
},
SEARCH_SAVED_SEARCH_RENAME: {
Expand Down
8 changes: 8 additions & 0 deletions src/components/Search/SearchAutocompleteList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ function SearchAutocompleteList(
const [isInitialRender, setIsInitialRender] = useState(true);

const typeAutocompleteList = Object.values(CONST.SEARCH.DATA_TYPES);
const groupByAutocompleteList = Object.values(CONST.SEARCH.GROUP_BY);
const statusAutocompleteList = Object.values({...CONST.SEARCH.STATUS.EXPENSE, ...CONST.SEARCH.STATUS.INVOICE, ...CONST.SEARCH.STATUS.CHAT, ...CONST.SEARCH.STATUS.TRIP});
const expenseTypes = Object.values(CONST.SEARCH.TRANSACTION_TYPE);

Expand Down Expand Up @@ -337,6 +338,12 @@ function SearchAutocompleteList(

return filteredTypes.map((type) => ({filterKey: CONST.SEARCH.SEARCH_USER_FRIENDLY_KEYS.TYPE, text: type}));
}
case CONST.SEARCH.SYNTAX_ROOT_KEYS.GROUP_BY: {
const filteredGroupBy = groupByAutocompleteList.filter(
(groupByValue) => groupByValue.toLowerCase().includes(autocompleteValue.toLowerCase()) && !alreadyAutocompletedKeys.includes(groupByValue.toLowerCase()),
);
return filteredGroupBy.map((groupByValue) => ({filterKey: CONST.SEARCH.SEARCH_USER_FRIENDLY_KEYS.GROUP_BY, text: groupByValue}));
}
case CONST.SEARCH.SYNTAX_ROOT_KEYS.STATUS: {
const filteredStatuses = statusAutocompleteList
.filter((status) => status.includes(autocompleteValue.toLowerCase()) && !alreadyAutocompletedKeys.includes(status))
Expand Down Expand Up @@ -405,6 +412,7 @@ function SearchAutocompleteList(
workspaceCardFeeds,
cardAutocompleteList,
allCards,
groupByAutocompleteList,
]);

const sortedRecentSearches = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ type SearchPageHeaderProps = {
searchRouterListVisible?: boolean;
hideSearchRouterList?: () => void;
onSearchRouterFocus?: () => void;
shouldGroupByReports?: boolean;
};

type SearchHeaderOptionValue = DeepValueOf<typeof CONST.SEARCH.BULK_ACTION_TYPES> | undefined;

function SearchPageHeader({queryJSON, searchName, searchRouterListVisible, hideSearchRouterList, onSearchRouterFocus, shouldGroupByReports}: SearchPageHeaderProps) {
function SearchPageHeader({queryJSON, searchName, searchRouterListVisible, hideSearchRouterList, onSearchRouterFocus}: SearchPageHeaderProps) {
const {translate} = useLocalize();
const theme = useTheme();
const styles = useThemeStyles();
Expand Down Expand Up @@ -432,7 +431,6 @@ function SearchPageHeader({queryJSON, searchName, searchRouterListVisible, hideS
searchName={searchName}
hideSearchRouterList={hideSearchRouterList}
inputRightComponent={InputRightComponent}
shouldGroupByReports={shouldGroupByReports}
/>
<ConfirmModal
isVisible={isDeleteExpensesConfirmModalVisible}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,9 @@ type SearchPageHeaderInputProps = {
onSearchRouterFocus?: () => void;
searchName?: string;
inputRightComponent: React.ReactNode;
shouldGroupByReports?: boolean;
};

function SearchPageHeaderInput({
queryJSON,
searchRouterListVisible,
hideSearchRouterList,
onSearchRouterFocus,
searchName,
inputRightComponent,
shouldGroupByReports,
}: SearchPageHeaderInputProps) {
function SearchPageHeaderInput({queryJSON, searchRouterListVisible, hideSearchRouterList, onSearchRouterFocus, searchName, inputRightComponent}: SearchPageHeaderInputProps) {
const {translate} = useLocalize();
const [showPopupButton, setShowPopupButton] = useState(true);
const styles = useThemeStyles();
Expand Down Expand Up @@ -271,7 +262,6 @@ function SearchPageHeaderInput({
>
<SearchTypeMenuPopover
queryJSON={queryJSON}
shouldGroupByReports={shouldGroupByReports}
searchName={searchName}
/>
</Animated.View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,15 @@ type SavedSearchMenuItem = MenuItemWithLink & {
type SearchTypeMenuNarrowProps = {
queryJSON: SearchQueryJSON;
searchName?: string;
shouldGroupByReports?: boolean;
};

function SearchTypeMenuPopover({queryJSON, searchName, shouldGroupByReports}: SearchTypeMenuNarrowProps) {
function SearchTypeMenuPopover({queryJSON, searchName}: SearchTypeMenuNarrowProps) {
const theme = useTheme();
const styles = useThemeStyles();
const {singleExecution} = useSingleExecution();
const {windowHeight} = useWindowDimensions();
const {translate} = useLocalize();
const {hash, policyID} = queryJSON;
const {hash, policyID, groupBy} = queryJSON;
const {showDeleteModal, DeleteConfirmModal} = useDeleteSavedSearch();
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
const [session] = useOnyx(ONYXKEYS.SESSION);
Expand All @@ -59,6 +58,7 @@ function SearchTypeMenuPopover({queryJSON, searchName, shouldGroupByReports}: Se
const [workspaceCardFeeds] = useOnyx(ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST);
const allCards = useMemo(() => mergeCardListWithWorkspaceFeeds(workspaceCardFeeds ?? CONST.EMPTY_OBJECT, userCardList), [userCardList, workspaceCardFeeds]);
const {unmodifiedPaddings} = useStyledSafeAreaInsets();
const shouldGroupByReports = groupBy === CONST.SEARCH.GROUP_BY.REPORTS;
const cardFeedNamesWithType = useMemo(() => {
return getCardFeedNamesWithType({workspaceCardFeeds, userCardList, translate});
}, [translate, workspaceCardFeeds, userCardList]);
Expand Down
8 changes: 4 additions & 4 deletions src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ type SearchProps = {
contentContainerStyle?: StyleProp<ViewStyle>;
isSearchScreenFocused?: boolean;
onContentSizeChange?: (w: number, h: number) => void;
shouldGroupByReports?: boolean;
};

const transactionItemMobileHeight = 100;
Expand Down Expand Up @@ -126,7 +125,7 @@ function prepareTransactionsList(item: TransactionListItemType, selectedTransact
};
}

function Search({queryJSON, onSearchListScroll, isSearchScreenFocused, contentContainerStyle, onContentSizeChange, shouldGroupByReports}: SearchProps) {
function Search({queryJSON, onSearchListScroll, isSearchScreenFocused, contentContainerStyle, onContentSizeChange}: SearchProps) {
const {isOffline} = useNetwork();
const {shouldUseNarrowLayout} = useResponsiveLayout();
const styles = useThemeStyles();
Expand All @@ -149,13 +148,14 @@ function Search({queryJSON, onSearchListScroll, isSearchScreenFocused, contentCo
const {selectionMode} = useMobileSelectionMode();
const [offset, setOffset] = useState(0);

const {type, status, sortBy, sortOrder, hash} = queryJSON;
const {type, status, sortBy, sortOrder, hash, groupBy} = queryJSON;

const [currentSearchResults] = useOnyx(`${ONYXKEYS.COLLECTION.SNAPSHOT}${hash}`);
const [transactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION);
const previousTransactions = usePrevious(transactions);
const [reportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS);
const previousReportActions = usePrevious(reportActions);
const shouldGroupByReports = groupBy === CONST.SEARCH.GROUP_BY.REPORTS;

useEffect(() => {
if (!currentSearchResults?.search?.type) {
Expand Down Expand Up @@ -266,7 +266,7 @@ function Search({queryJSON, onSearchListScroll, isSearchScreenFocused, contentCo
return [];
}
return getSections(type, status, searchResults.data, searchResults.search, shouldGroupByReports);
}, [searchResults, status, type, shouldGroupByReports]);
}, [searchResults, type, status, shouldGroupByReports]);

useEffect(() => {
/** We only want to display the skeleton for the status filters the first time we load them for a specific data type */
Expand Down
5 changes: 4 additions & 1 deletion src/components/Search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type InvoiceSearchStatus = ValueOf<typeof CONST.SEARCH.STATUS.INVOICE>;
type TripSearchStatus = ValueOf<typeof CONST.SEARCH.STATUS.TRIP>;
type ChatSearchStatus = ValueOf<typeof CONST.SEARCH.STATUS.CHAT>;
type SearchStatus = ExpenseSearchStatus | InvoiceSearchStatus | TripSearchStatus | ChatSearchStatus | Array<ExpenseSearchStatus | InvoiceSearchStatus | TripSearchStatus | ChatSearchStatus>;
type SearchGroupBy = ValueOf<typeof CONST.SEARCH.GROUP_BY>;

type SearchContext = {
currentSearchHash: number;
Expand Down Expand Up @@ -96,7 +97,8 @@ type SearchFilterKey =
| ValueOf<typeof CONST.SEARCH.SYNTAX_FILTER_KEYS>
| typeof CONST.SEARCH.SYNTAX_ROOT_KEYS.TYPE
| typeof CONST.SEARCH.SYNTAX_ROOT_KEYS.STATUS
| typeof CONST.SEARCH.SYNTAX_ROOT_KEYS.POLICY_ID;
| typeof CONST.SEARCH.SYNTAX_ROOT_KEYS.POLICY_ID
| typeof CONST.SEARCH.SYNTAX_ROOT_KEYS.GROUP_BY;

type UserFriendlyKey = ValueOf<typeof CONST.SEARCH.SEARCH_USER_FRIENDLY_KEYS>;

Expand All @@ -112,6 +114,7 @@ type SearchQueryAST = {
status: SearchStatus;
sortBy: SearchColumnType;
sortOrder: SortOrder;
groupBy?: SearchGroupBy;
filters: ASTNode;
policyID?: string;
};
Expand Down
3 changes: 3 additions & 0 deletions src/libs/SearchAutocompleteUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ function filterOutRangesWithCorrectValue(
const typeList = Object.values(CONST.SEARCH.DATA_TYPES) as string[];
const expenseTypeList = Object.values(CONST.SEARCH.TRANSACTION_TYPE) as string[];
const statusList = Object.values({...CONST.SEARCH.STATUS.EXPENSE, ...CONST.SEARCH.STATUS.INVOICE, ...CONST.SEARCH.STATUS.CHAT, ...CONST.SEARCH.STATUS.TRIP}) as string[];
const groupByList = Object.values(CONST.SEARCH.GROUP_BY) as string[];

switch (range.key) {
case CONST.SEARCH.SYNTAX_FILTER_KEYS.IN:
Expand All @@ -172,6 +173,8 @@ function filterOutRangesWithCorrectValue(
return categoryList.get().includes(range.value);
case CONST.SEARCH.SYNTAX_FILTER_KEYS.TAG:
return tagList.get().includes(range.value);
case CONST.SEARCH.SYNTAX_ROOT_KEYS.GROUP_BY:
return groupByList.includes(range.value);

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.

This highlights the group by syntax on a chat type too, which is unsupported: #75411

default:
return false;
}
Expand Down
Loading