Skip to content

Commit

Permalink
🌱 MTA-2560: Use multi select filter for application names (#1771) (#1828
Browse files Browse the repository at this point in the history
)

Resolves: #1754
Resolves: https://issues.redhat.com/browse/MTA-2560

Signed-off-by: Radoslaw Szwajkowski <[email protected]>
Co-authored-by: Radoslaw Szwajkowski <[email protected]>
  • Loading branch information
ibolton336 and rszwajko authored Apr 8, 2024
1 parent c7776c5 commit 3596d7d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
16 changes: 14 additions & 2 deletions client/src/app/pages/issues/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import { useFetchBusinessServices } from "@app/queries/businessservices";
import { useFetchTagsWithTagItems } from "@app/queries/tags";
import { useTranslation } from "react-i18next";
import { useFetchArchetypes } from "@app/queries/archetypes";
import { useFetchApplications } from "@app/queries/applications";
import { localeNumericCompare } from "@app/utils/utils";
import i18n from "@app/i18n";

// Certain filters are shared between the Issues page and the Affected Applications Page.
// We carry these filter values between the two pages when determining the URLs to navigate between them.
Expand All @@ -41,18 +44,27 @@ export const useSharedAffectedApplicationFilterCategories = <
const { businessServices } = useFetchBusinessServices();
const { tagCategories, tags, tagItems } = useFetchTagsWithTagItems();
const { archetypes } = useFetchArchetypes();
const { data: applications } = useFetchApplications();

return [
{
key: "application.name",
title: t("terms.applicationName"),
filterGroup: IssueFilterGroups.ApplicationInventory,
type: FilterType.search,
type: FilterType.multiselect,
placeholderText:
t("actions.filterBy", {
what: t("terms.applicationName").toLowerCase(),
}) + "...",
getServerFilterValue: (value) => (value ? [`*${value[0]}*`] : []),
selectOptions: applications
.map(({ name }) => name)
.sort((a, b) => localeNumericCompare(a, b, i18n.language))
.map((name) => ({
key: name,
value: name,
})),
getServerFilterValue: (selectedOptions) =>
selectedOptions?.filter(Boolean) ?? [],
},
{
key: "application.id",
Expand Down
11 changes: 11 additions & 0 deletions client/src/app/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,14 @@ export const collapseSpacesAndCompare = (

export const capitalizeFirstLetter = (str: string) =>
str.charAt(0).toUpperCase() + str.slice(1);

/**
* Uses native string localCompare method with numeric option enabled.
*
* @param locale to be used by string compareFn
*/
export const localeNumericCompare = (
a: string,
b: string,
locale: string
): number => a.localeCompare(b, locale, { numeric: true });

0 comments on commit 3596d7d

Please sign in to comment.