Skip to content

Commit

Permalink
✨ Extend filtering in the Set Target step (#2092)
Browse files Browse the repository at this point in the history
Added filters:
1. by name (freetext search)
2. by custom target (yes/no select)
3. by labels (multiselect)

Resolves: https://issues.redhat.com/browse/MTA-3702

Signed-off-by: Radoslaw Szwajkowski <[email protected]>
  • Loading branch information
rszwajko authored Oct 4, 2024
1 parent c04bb35 commit 9bd0b3b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
54 changes: 52 additions & 2 deletions client/src/app/pages/applications/analysis-wizard/set-targets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import { useLocalTableControls } from "@app/hooks/table-controls";
import { useSetting } from "@app/queries/settings";
import { AppPlaceholder } from "@app/components/AppPlaceholder";
import { StateError } from "@app/components/StateError";
import { universalComparator } from "@app/utils/utils";
import { toLabelValue } from "@app/utils/rules-utils";

interface SetTargetsProps {
applications: Application[];
Expand Down Expand Up @@ -177,9 +179,12 @@ const SetTargetsInternal: React.FC<SetTargetsInternalProps> = ({
tableName: "target-cards",
items: targets,
idProperty: "name",
initialFilterValues: { name: applicationProviders },
initialFilterValues: { provider: applicationProviders },
columnNames: {
name: "name",
provider: "provider",
custom: "custom",
labels: "labels",
},
isFilterEnabled: true,
isPaginationEnabled: false,
Expand All @@ -200,11 +205,56 @@ const SetTargetsInternal: React.FC<SetTargetsInternalProps> = ({
value: language,
})),
placeholderText: "Filter by language...",
categoryKey: "name",
categoryKey: "provider",
title: "Languages",
type: FilterType.multiselect,
matcher: (filter, target) => !!target.provider?.includes(filter),
},
{
placeholderText: "Filter by name...",
categoryKey: "name",
title: "Name",
type: FilterType.search,
matcher: (filter, target) =>
!!target.name?.toLowerCase().includes(filter.toLowerCase()),
},
{
placeholderText: "Filter by custom target...",
categoryKey: "custom",
title: "Custom target",
type: FilterType.select,
selectOptions: [
{ value: "true", label: "Yes" },
{ value: "false", label: "No" },
],
matcher: (filter, target) => String(!!target.custom) === filter,
},
{
selectOptions: unique(
targets
.flatMap(({ labels }) => labels ?? [])
.map(({ name, label }) => ({
name,
label: toLabelValue(label),
})),
({ label }) => label
)
.map(({ label, name }) => ({
value: label,
label: name,
chipLabel: label,
}))
.sort((a, b) => universalComparator(a.label, b.label)),

placeholderText: "Filter by labels...",
categoryKey: "labels",
title: "Labels",
type: FilterType.multiselect,
matcher: (filter, target) =>
(target.labels ?? [])
.map(({ label }) => toLabelValue(label))
.includes(filter),
},
],
});

Expand Down
4 changes: 3 additions & 1 deletion client/src/app/utils/rules-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ interface ParsedLabel {
labelValue: string;
}

export const toLabelValue = (label?: string) => label?.split("=").pop() ?? "";

export const getParsedLabel = (label: string | null): ParsedLabel => {
if (label === null) {
return {
Expand All @@ -116,7 +118,7 @@ export const getParsedLabel = (label: string | null): ParsedLabel => {
const char1 = label.indexOf("/") + 1;
const char2 = label.lastIndexOf("=");
const type = label.substring(char1, char2);
const value = label.split("=").pop();
const value = toLabelValue(label);

return {
labelType: type || "",
Expand Down

0 comments on commit 9bd0b3b

Please sign in to comment.