Skip to content

Commit

Permalink
Fix type error and review sugestions
Browse files Browse the repository at this point in the history
  • Loading branch information
289Adam289 committed Jul 31, 2024
1 parent 53c0802 commit ee320a8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions src/libs/SearchUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,11 @@ function buildDateFilterQuery(filterValues: Partial<SearchAdvancedFiltersForm>)
return dateFilter;
}

function sanitizeCategoryName(category: string) {
if (category.includes(' ')) {
return `"${category}"`;
function sanitizeString(str: string) {
if (str.includes(' ')) {
return `"${str}"`;
}
return category;
return str;
}

/**
Expand All @@ -398,8 +398,8 @@ function buildQueryStringFromFilters(filterValues: Partial<SearchAdvancedFilters
}

if (filterKey === INPUT_IDS.CATEGORY && filterValues[filterKey]) {
const categories = filterValues[filterKey];
return `${CONST.SEARCH.SYNTAX_FILTER_KEYS.CATEGORY}:${categories.map((category) => sanitizeCategoryName(category)).join(',')}`;
const categories = filterValues[filterKey] ?? [];
return `${CONST.SEARCH.SYNTAX_FILTER_KEYS.CATEGORY}:${categories.map(sanitizeString).join(',')}`;
}

return undefined;
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Search/AdvancedSearchFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ function getFilterDisplayTitle(filters: Partial<SearchAdvancedFiltersForm>, fiel
}

if (fieldName === CONST.SEARCH.SYNTAX_FILTER_KEYS.CATEGORY && filters[fieldName]) {
const categories = filters[fieldName];
return categories.map((category) => Str.recapitalize(category)).join(', ');
const categories = filters[fieldName] ?? [];
return categories.join(', ');
}

// Todo Once all Advanced filters are implemented this line can be cleaned up. See: https://github.com/Expensify/App/issues/45026
Expand Down
8 changes: 4 additions & 4 deletions src/pages/Search/SearchFiltersCategoryPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ function SearchFiltersCategoryPage() {
const [newCategories, setNewCategories] = useState<string[]>(currentCategories ?? []);
const policyID = searchAdvancedFiltersForm?.policyID ?? '-1';

const [allPolicyIdCategories] = useOnyx(ONYXKEYS.COLLECTION.POLICY_CATEGORIES);
const singlePolicyCategories = allPolicyIdCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`];
const [allPolicyIDCategories] = useOnyx(ONYXKEYS.COLLECTION.POLICY_CATEGORIES);
const singlePolicyCategories = allPolicyIDCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`];

const categoryNames = useMemo(() => {
let categories: string[] = [];
if (!singlePolicyCategories) {
categories = Object.values(allPolicyIdCategories ?? {})
categories = Object.values(allPolicyIDCategories ?? {})
.map((policyCategories) => Object.values(policyCategories ?? {}).map((category) => category.name))
.flat();
} else {
categories = Object.values(singlePolicyCategories ?? {}).map((value) => value.name);
}

return [...new Set(categories)];
}, [allPolicyIdCategories, singlePolicyCategories]);
}, [allPolicyIDCategories, singlePolicyCategories]);

const sections = useMemo(() => {
const newSections: CategorySection[] = [];
Expand Down

0 comments on commit ee320a8

Please sign in to comment.