Skip to content

Commit 4fb68c4

Browse files
committed
feat: update label in filter result recap
1 parent 83a779a commit 4fb68c4

5 files changed

Lines changed: 70 additions & 73 deletions

File tree

client/src/features/searchV2/components/SearchFilters.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ function SearchFilterContent({
412412
visualization={visualization}
413413
type={filter.allowSelectMany ? "checkbox" : "radio"}
414414
>
415+
{element.icon}
415416
{element.label}
416417
{element.quantity !== undefined ? (
417418
<Badge className="ms-1">{element.quantity}</Badge>

client/src/features/searchV2/components/SearchResultRecap.tsx

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import cx from "classnames";
2020
import { ReactNode, useMemo } from "react";
2121

22+
import { getFilterValueLabel } from "~/features/searchV2/contextSearch.utils";
2223
import useAppSelector from "../../../utils/customHooks/useAppSelector.hook";
2324
import { useGetSearchQueryQuery } from "../api/searchV2Api.api";
2425
import {
@@ -33,51 +34,64 @@ import { selectSearchApiQuery } from "../searchV2.slice";
3334

3435
export default function SearchResultRecap() {
3536
const state = useAppSelector(({ searchV2 }) => searchV2);
37+
const {
38+
contentType,
39+
created,
40+
directMember,
41+
keywords,
42+
query,
43+
role,
44+
visibility,
45+
} = state;
3646
const apiQuery = useAppSelector(selectSearchApiQuery);
3747
const { data, isFetching } = useGetSearchQueryQuery({ params: apiQuery });
3848
const total = data?.pagingInfo.totalResult;
3949

4050
const filters = useMemo(() => {
4151
const parts: ReactNode[] = [];
42-
if (state.contentType) {
52+
if (contentType) {
4353
parts.push(
4454
<span key="type">
45-
{FILTER_CONTENT.label}: {state.contentType}
55+
{FILTER_CONTENT.label}:{" "}
56+
{getFilterValueLabel([contentType], FILTER_CONTENT.allowedValues)}
4657
</span>,
4758
);
4859
}
49-
if (state.visibility) {
60+
if (visibility) {
5061
parts.push(
5162
<span key="visibility">
52-
{FILTER_VISIBILITY.label}: {state.visibility}
63+
{FILTER_VISIBILITY.label}:{" "}
64+
{getFilterValueLabel([visibility], FILTER_VISIBILITY.allowedValues)}
5365
</span>,
5466
);
5567
}
56-
if (state.role) {
68+
if (role) {
5769
parts.push(
5870
<span key="role">
59-
{FILTER_MY_ROLE.label}: {state.role}
71+
{FILTER_MY_ROLE.label}:{" "}
72+
{getFilterValueLabel(role.split(","), FILTER_MY_ROLE.allowedValues)}
6073
</span>,
6174
);
6275
}
63-
if (state.keywords) {
76+
if (keywords) {
6477
parts.push(
6578
<span key="keywords">
66-
{FILTER_KEYWORD.label}: {state.keywords}
79+
{FILTER_KEYWORD.label}: {keywords}
6780
</span>,
6881
);
6982
}
70-
if (state.directMember) {
83+
if (directMember) {
7184
parts.push(
7285
<span key="member">
73-
{FILTER_MEMBER.label}: {state.directMember}
86+
{FILTER_MEMBER.label}: {directMember}
7487
</span>,
7588
);
7689
}
77-
if (state.created) {
90+
if (created) {
7891
parts.push(
7992
<span key="created">
80-
{FILTER_DATE.label}: {state.created}
93+
{FILTER_DATE.label}:{" "}
94+
{getFilterValueLabel([created], FILTER_DATE.allowedValues)}
8195
</span>,
8296
);
8397
}
@@ -91,7 +105,7 @@ export default function SearchResultRecap() {
91105
))}
92106
</>
93107
) : null;
94-
}, [state]);
108+
}, [contentType, created, directMember, keywords, role, visibility]);
95109

96110
return (
97111
<p className="mb-0">
@@ -102,10 +116,10 @@ export default function SearchResultRecap() {
102116
{total ? total : "No"} {total && total > 1 ? "results" : "result"}
103117
</span>
104118
)}
105-
{state.query && (
119+
{query && (
106120
<>
107121
{" "}
108-
for <span className="fw-semibold">{`"${state.query}"`}</span>
122+
for <span className="fw-semibold">{`"${query}"`}</span>
109123
</>
110124
)}
111125
{filters && (

client/src/features/searchV2/contextSearch.constants.tsx

Lines changed: 24 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -51,39 +51,23 @@ export const FILTER_CONTENT: EnumFilter = {
5151
allowedValues: [
5252
{
5353
value: "Project",
54-
label: (
55-
<>
56-
<Folder className={cx("bi", "me-1")} />
57-
Project
58-
</>
59-
),
54+
label: "Project",
55+
icon: <Folder className={cx("bi", "me-1")} />,
6056
},
6157
{
6258
value: "DataConnector",
63-
label: (
64-
<>
65-
<Database className={cx("bi", "me-1")} />
66-
Data
67-
</>
68-
),
59+
label: "Data",
60+
icon: <Database className={cx("bi", "me-1")} />,
6961
},
7062
{
7163
value: "User",
72-
label: (
73-
<>
74-
<Person className={cx("bi", "me-1")} />
75-
User
76-
</>
77-
),
64+
label: "User",
65+
icon: <Person className={cx("bi", "me-1")} />,
7866
},
7967
{
8068
value: "Group",
81-
label: (
82-
<>
83-
<People className={cx("bi", "me-1")} />
84-
Group
85-
</>
86-
),
69+
label: "Group",
70+
icon: <People className={cx("bi", "me-1")} />,
8771
},
8872
],
8973
allowSelectMany: false,
@@ -102,21 +86,13 @@ export const FILTER_CONTENT_NAMESPACE: EnumFilter = {
10286
allowedValues: [
10387
{
10488
value: "Project",
105-
label: (
106-
<>
107-
<Folder className={cx("bi", "me-1")} />
108-
Project
109-
</>
110-
),
89+
icon: <Folder className={cx("bi", "me-1")} />,
90+
label: "Project",
11191
},
11292
{
11393
value: "DataConnector",
114-
label: (
115-
<>
116-
<Database className={cx("bi", "me-1")} />
117-
Data
118-
</>
119-
),
94+
icon: <Database className={cx("bi", "me-1")} />,
95+
label: "Data",
12096
},
12197
],
12298
allowSelectMany: false,
@@ -167,21 +143,13 @@ export const FILTER_VISIBILITY: EnumFilter = {
167143
{ value: "", label: "Any visibility" },
168144
{
169145
value: "public",
170-
label: (
171-
<>
172-
<Globe className={cx("bi", "me-1")} />
173-
Public
174-
</>
175-
),
146+
icon: <Globe className={cx("bi", "me-1")} />,
147+
label: "Public",
176148
},
177149
{
178150
value: "private",
179-
label: (
180-
<>
181-
<Lock className={cx("bi", "me-1")} />
182-
Private
183-
</>
184-
),
151+
icon: <Lock className={cx("bi", "me-1")} />,
152+
label: "Private",
185153
},
186154
],
187155
allowSelectMany: false,
@@ -201,15 +169,15 @@ export const FILTER_MY_ROLE: EnumFilter = {
201169
allowedValues: [
202170
{
203171
value: "owner",
204-
label: <>Owner</>,
172+
label: "Owner",
205173
},
206174
{
207175
value: "editor",
208-
label: <>Editor</>,
176+
label: "Editor",
209177
},
210178
{
211179
value: "viewer",
212-
label: <>Viewer</>,
180+
label: "Viewer",
213181
},
214182
],
215183
allowSelectMany: true,
@@ -236,27 +204,27 @@ export const FILTER_DATE: EnumFilter = {
236204
allowedValues: [
237205
{
238206
value: "",
239-
label: <>All</>,
207+
label: "All",
240208
id: "any",
241209
},
242210
{
243211
value: ">today-7d",
244-
label: <>Last week</>,
212+
label: "Last week",
245213
id: "last-week",
246214
},
247215
{
248216
value: ">today-31d",
249-
label: <>Last month</>,
217+
label: "Last month",
250218
id: "last-month",
251219
},
252220
{
253221
value: ">today-90d",
254-
label: <>Last 90 days</>,
222+
label: "Last 90 days",
255223
id: "last-90-days",
256224
},
257225
{
258226
value: "<today-90d",
259-
label: <>Older than 90 days</>,
227+
label: "Older than 90 days",
260228
id: "older-than-90-days",
261229
},
262230
],

client/src/features/searchV2/contextSearch.types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ export type GroupSearchEntity = Exclude<
2525
{ type: "Group" | "User" }
2626
>;
2727

28-
interface FilterValue {
29-
label: ReactNode;
28+
export interface FilterValue {
29+
label: string | ReactNode;
30+
icon?: ReactNode;
3031
quantity?: number;
3132
value: string;
3233
id?: string;

client/src/features/searchV2/contextSearch.utils.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* limitations under the License.
1717
*/
1818

19+
import { FilterValue } from "~/features/searchV2/contextSearch.types";
1920
import { DATE_FILTER_CUSTOM_SEPARATOR } from "./contextSearch.constants";
2021

2122
export function parseCustomDateFilter(value: string): {
@@ -41,3 +42,15 @@ export function buildCustomDateFilterValue(
4142
if (beforeDate) parts.push(`<${beforeDate}`);
4243
return parts.join(DATE_FILTER_CUSTOM_SEPARATOR);
4344
}
45+
46+
export function getFilterValueLabel(
47+
values: string[],
48+
allowedValues: FilterValue[],
49+
): string {
50+
const validLabels = values
51+
.map((value) => allowedValues.find((v) => v.value === value)?.label)
52+
.filter((label): label is string => typeof label === "string");
53+
if (validLabels.length === 0) return values.join(" ");
54+
55+
return validLabels.join(", ");
56+
}

0 commit comments

Comments
 (0)