Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Use multi select filter for application names #1771

Merged
merged 2 commits into from
Mar 14, 2024
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
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 });
Loading