Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
corps-directory
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fhurtado14
corps-directory
Commits
5067f92c
Commit
5067f92c
authored
4 months ago
by
sush202020
Browse files
Options
Downloads
Patches
Plain Diff
got rid of extra spaces
parent
dbe23c8f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontend/src/components/SearchBrowse/SearchBrowse.js
+10
-7
10 additions, 7 deletions
frontend/src/components/SearchBrowse/SearchBrowse.js
with
10 additions
and
7 deletions
frontend/src/components/SearchBrowse/SearchBrowse.js
+
10
−
7
View file @
5067f92c
...
@@ -29,22 +29,25 @@ const SearchBrowse = () => {
...
@@ -29,22 +29,25 @@ const SearchBrowse = () => {
const
handleInputChange
=
(
e
)
=>
{
const
handleInputChange
=
(
e
)
=>
{
const
{
name
,
value
}
=
e
.
target
;
const
{
name
,
value
}
=
e
.
target
;
setSearchParams
((
prev
)
=>
({
...
prev
,
[
name
]:
value
}));
setSearchParams
((
prev
)
=>
({
...
prev
,
[
name
]:
value
.
trimStart
()
}));
};
};
const
handleSearch
=
async
()
=>
{
const
handleSearch
=
async
()
=>
{
setLoading
(
true
);
setLoading
(
true
);
setError
(
null
);
setError
(
null
);
// Trim all search parameters before sending them to the server
const
trimmedSearchParams
=
Object
.
fromEntries
(
Object
.
entries
(
searchParams
).
map
(([
key
,
value
])
=>
[
key
,
value
.
trim
()])
);
try
{
try
{
const
response
=
await
axios
.
post
(
const
response
=
await
axios
.
post
(
`
${
process
.
env
.
REACT_APP_API_URL
}
/person/searchByName`
,
`
${
process
.
env
.
REACT_APP_API_URL
}
/person/searchByName`
,
{
trimmedSearchParams
// send trimmed search parameters in the request payload
...
searchParams
,
// send all searchParams in the request payload
}
);
);
const
filteredResults
=
filterAndSortResults
(
response
.
data
.
people
,
s
earchParams
);
const
filteredResults
=
filterAndSortResults
(
response
.
data
.
people
,
trimmedS
earchParams
);
setResults
(
filteredResults
);
setResults
(
filteredResults
);
}
catch
(
err
)
{
}
catch
(
err
)
{
setError
(
setError
(
...
@@ -60,7 +63,7 @@ const SearchBrowse = () => {
...
@@ -60,7 +63,7 @@ const SearchBrowse = () => {
.
filter
((
person
)
=>
{
.
filter
((
person
)
=>
{
// Only keep results that match at least one non-empty field in searchParams
// Only keep results that match at least one non-empty field in searchParams
return
Object
.
keys
(
searchParams
).
every
((
key
)
=>
{
return
Object
.
keys
(
searchParams
).
every
((
key
)
=>
{
return
!
searchParams
[
key
]
||
person
[
key
]
===
searchParams
[
key
];
return
!
searchParams
[
key
]
||
person
[
key
]
?.
trim
()
===
searchParams
[
key
];
});
});
})
})
.
sort
((
a
,
b
)
=>
{
.
sort
((
a
,
b
)
=>
{
...
@@ -74,7 +77,7 @@ const SearchBrowse = () => {
...
@@ -74,7 +77,7 @@ const SearchBrowse = () => {
const
calculateRelevance
=
(
person
,
searchParams
)
=>
{
const
calculateRelevance
=
(
person
,
searchParams
)
=>
{
let
relevance
=
0
;
let
relevance
=
0
;
Object
.
keys
(
searchParams
).
forEach
((
key
)
=>
{
Object
.
keys
(
searchParams
).
forEach
((
key
)
=>
{
if
(
searchParams
[
key
]
&&
person
[
key
]
===
searchParams
[
key
])
{
if
(
searchParams
[
key
]
&&
person
[
key
]
?.
trim
()
===
searchParams
[
key
])
{
relevance
+=
1
;
relevance
+=
1
;
}
}
});
});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment