Skip to content

Commit 3596d7d

Browse files
ibolton336rszwajko
andauthored
🌱 MTA-2560: Use multi select filter for application names (#1771) (#1828)
Resolves: #1754 Resolves: https://issues.redhat.com/browse/MTA-2560 Signed-off-by: Radoslaw Szwajkowski <[email protected]> Co-authored-by: Radoslaw Szwajkowski <[email protected]>
1 parent c7776c5 commit 3596d7d

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

client/src/app/pages/issues/helpers.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import { useFetchBusinessServices } from "@app/queries/businessservices";
2222
import { useFetchTagsWithTagItems } from "@app/queries/tags";
2323
import { useTranslation } from "react-i18next";
2424
import { useFetchArchetypes } from "@app/queries/archetypes";
25+
import { useFetchApplications } from "@app/queries/applications";
26+
import { localeNumericCompare } from "@app/utils/utils";
27+
import i18n from "@app/i18n";
2528

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

4549
return [
4650
{
4751
key: "application.name",
4852
title: t("terms.applicationName"),
4953
filterGroup: IssueFilterGroups.ApplicationInventory,
50-
type: FilterType.search,
54+
type: FilterType.multiselect,
5155
placeholderText:
5256
t("actions.filterBy", {
5357
what: t("terms.applicationName").toLowerCase(),
5458
}) + "...",
55-
getServerFilterValue: (value) => (value ? [`*${value[0]}*`] : []),
59+
selectOptions: applications
60+
.map(({ name }) => name)
61+
.sort((a, b) => localeNumericCompare(a, b, i18n.language))
62+
.map((name) => ({
63+
key: name,
64+
value: name,
65+
})),
66+
getServerFilterValue: (selectedOptions) =>
67+
selectedOptions?.filter(Boolean) ?? [],
5668
},
5769
{
5870
key: "application.id",

client/src/app/utils/utils.ts

+11
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,14 @@ export const collapseSpacesAndCompare = (
192192

193193
export const capitalizeFirstLetter = (str: string) =>
194194
str.charAt(0).toUpperCase() + str.slice(1);
195+
196+
/**
197+
* Uses native string localCompare method with numeric option enabled.
198+
*
199+
* @param locale to be used by string compareFn
200+
*/
201+
export const localeNumericCompare = (
202+
a: string,
203+
b: string,
204+
locale: string
205+
): number => a.localeCompare(b, locale, { numeric: true });

0 commit comments

Comments
 (0)