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
15 changes: 11 additions & 4 deletions src/libs/SearchQueryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,17 @@ function isSearchDatePreset(date: string | undefined): date is SearchDatePreset
* Returns whether a given search filter is supported in a given search data type
*/
function isFilterSupported(filter: SearchAdvancedFiltersKey, type: SearchDataTypes) {
return ALLOWED_TYPE_FILTERS[type].some((supportedFilter) => {
const isReportFieldSupported = supportedFilter === CONST.SEARCH.SYNTAX_FILTER_KEYS.REPORT_FIELD && filter.startsWith(CONST.SEARCH.REPORT_FIELD.GLOBAL_PREFIX);
return supportedFilter === filter || isReportFieldSupported;
});
const supportedTypeFilters = ALLOWED_TYPE_FILTERS[type];
if (!supportedTypeFilters) {
return false;
}
if (supportedTypeFilters.has(filter)) {
return true;
}
if (filter.startsWith(CONST.SEARCH.REPORT_FIELD.GLOBAL_PREFIX)) {
return supportedTypeFilters.has(CONST.SEARCH.SYNTAX_FILTER_KEYS.REPORT_FIELD);
}
return false;
}

/**
Expand Down
26 changes: 13 additions & 13 deletions src/types/form/SearchAdvancedFiltersForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ const FILTER_KEYS = {
LIMIT: 'limit',
} as const;

const ALLOWED_TYPE_FILTERS = {
[CONST.SEARCH.DATA_TYPES.EXPENSE]: [
const ALLOWED_TYPE_FILTERS: Record<string, Set<string>> = {
[CONST.SEARCH.DATA_TYPES.EXPENSE]: new Set([
FILTER_KEYS.TYPE,
FILTER_KEYS.STATUS,
FILTER_KEYS.FROM,
Expand Down Expand Up @@ -270,8 +270,8 @@ const ALLOWED_TYPE_FILTERS = {
FILTER_KEYS.ATTENDEE_NOT,
FILTER_KEYS.COLUMNS,
FILTER_KEYS.LIMIT,
],
[CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT]: [
]),
[CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT]: new Set([
FILTER_KEYS.TYPE,
FILTER_KEYS.STATUS,
FILTER_KEYS.FROM,
Expand Down Expand Up @@ -326,8 +326,8 @@ const ALLOWED_TYPE_FILTERS = {
FILTER_KEYS.TITLE_NOT,
FILTER_KEYS.REPORT_FIELD,
FILTER_KEYS.COLUMNS,
],
[CONST.SEARCH.DATA_TYPES.INVOICE]: [
]),
[CONST.SEARCH.DATA_TYPES.INVOICE]: new Set([
FILTER_KEYS.TYPE,
FILTER_KEYS.STATUS,
FILTER_KEYS.FROM,
Expand Down Expand Up @@ -410,9 +410,9 @@ const ALLOWED_TYPE_FILTERS = {
FILTER_KEYS.REPORT_FIELD,
FILTER_KEYS.TITLE_NOT,
FILTER_KEYS.COLUMNS,
],
]),

[CONST.SEARCH.DATA_TYPES.TRIP]: [
[CONST.SEARCH.DATA_TYPES.TRIP]: new Set([
FILTER_KEYS.TYPE,
FILTER_KEYS.STATUS,
FILTER_KEYS.FROM,
Expand Down Expand Up @@ -488,9 +488,9 @@ const ALLOWED_TYPE_FILTERS = {
FILTER_KEYS.TITLE_NOT,
FILTER_KEYS.REPORT_FIELD,
FILTER_KEYS.COLUMNS,
],
]),

[CONST.SEARCH.DATA_TYPES.CHAT]: [
[CONST.SEARCH.DATA_TYPES.CHAT]: new Set([
FILTER_KEYS.TYPE,
FILTER_KEYS.FROM,
FILTER_KEYS.FROM_NOT,
Expand All @@ -508,9 +508,9 @@ const ALLOWED_TYPE_FILTERS = {
FILTER_KEYS.IS_NOT,
FILTER_KEYS.HAS,
FILTER_KEYS.HAS_NOT,
],
]),

[CONST.SEARCH.DATA_TYPES.TASK]: [
[CONST.SEARCH.DATA_TYPES.TASK]: new Set([
FILTER_KEYS.TYPE,
FILTER_KEYS.STATUS,
FILTER_KEYS.TITLE,
Expand All @@ -527,7 +527,7 @@ const ALLOWED_TYPE_FILTERS = {
FILTER_KEYS.DATE_NOT,
FILTER_KEYS.DATE_AFTER,
FILTER_KEYS.DATE_BEFORE,
],
]),
};

type SearchAdvancedFiltersKey = ValueOf<typeof FILTER_KEYS> | ReportFieldKey;
Expand Down
Loading