Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Block Explorer UI
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
Releases
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
hive
Block Explorer UI
Commits
7f83c088
Commit
7f83c088
authored
3 months ago
by
Lukas
Committed by
mcfarhat
3 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Update comment search component
parent
a9932e97
No related branches found
No related tags found
1 merge request
!499
#392_part2_simplify_URL_route_build
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
components/home/searches/CommentsSearch.tsx
+69
-24
69 additions, 24 deletions
components/home/searches/CommentsSearch.tsx
with
69 additions
and
24 deletions
components/home/searches/CommentsSearch.tsx
+
69
−
24
View file @
7f83c088
import
{
use
State
}
from
"
react
"
;
import
{
use
Effect
}
from
"
react
"
;
import
{
Loader2
}
from
"
lucide-react
"
;
import
{
config
}
from
"
@/Config
"
;
import
Explorer
from
"
@/types/Explorer
"
;
import
{
getOperationButtonTitle
}
from
"
@/utils/UI
"
;
import
{
trimAccountName
}
from
"
@/utils/StringUtils
"
;
import
{
convertIdsToBooleanArray
}
from
"
@/lib/utils
"
;
import
{
convertBooleanArrayToIds
,
convertIdsToBooleanArray
,
parseUrlFlagsIntoBooleanArray
,
}
from
"
@/lib/utils
"
;
import
{
Input
}
from
"
@/components/ui/input
"
;
import
OperationTypesDialog
from
"
@/components/OperationTypesDialog
"
;
import
{
Button
}
from
"
@/components/ui/button
"
;
import
AutocompleteInput
from
"
@/components/ui/AutoCompleteInput
"
;
import
{
startCommentSearch
}
from
"
./utils/commentSearchHelpers
"
;
import
{
getCommentPageLink
,
startCommentSearch
,
}
from
"
./utils/commentSearchHelpers
"
;
import
{
useSearchesContext
}
from
"
@/contexts/SearchesContext
"
;
import
useOperationsTypes
from
"
@/hooks/api/common/useOperationsTypes
"
;
import
useCommentSearch
from
"
@/hooks/api/common/useCommentSearch
"
;
import
{
usePathname
}
from
"
next/navigation
"
;
import
{
useRouter
}
from
"
next/router
"
;
const
CommentsSearch
=
()
=>
{
const
{
...
...
@@ -24,23 +32,26 @@ const CommentsSearch = () => {
setPreviousCommentSearchProps
,
setLastSearchKey
,
searchRanges
,
commentsSearchAccountName
,
setCommentsSearchAccountName
,
commentsSearchPermlink
,
setCommentsSearchPermlink
,
selectedCommentSearchOperationTypes
,
setSelectedCommentSearchOperationTypes
,
}
=
useSearchesContext
();
const
pathname
=
usePathname
();
const
router
=
useRouter
();
const
{
commentSearchDataLoading
}
=
useCommentSearch
(
commentSearchProps
);
const
{
operationsTypes
}
=
useOperationsTypes
();
const
[
accountName
,
setAccountName
]
=
useState
<
string
>
(
""
);
const
[
permlink
,
setPermlink
]
=
useState
<
string
>
(
""
);
const
[
selectedCommentSearchOperationTypes
,
setSelectedCommentSearchOperationTypes
,
]
=
useState
<
number
[]
>
([]);
const
{
getRangesValues
}
=
searchRanges
;
const
isCommentsPage
=
pathname
?.
includes
(
"
/comments
"
)
??
false
;
const
onButtonClick
=
async
()
=>
{
if
(
a
ccountName
!==
""
)
{
const
handleStartCommentSearch
=
async
()
=>
{
if
(
commentsSearchA
ccountName
!==
""
)
{
const
{
payloadFromBlock
,
payloadToBlock
,
...
...
@@ -48,9 +59,9 @@ const CommentsSearch = () => {
payloadEndDate
,
}
=
await
getRangesValues
();
const
commentS
earchProps
:
Explorer
.
CommentSearchParams
=
{
accountName
:
trimAccountName
(
accountName
),
permlink
,
const
s
earchProps
:
Explorer
.
CommentSearchParams
=
{
accountName
:
trimAccountName
(
commentsSearchAccountName
as
string
),
permlink
:
commentsSearchPermlink
as
string
,
fromBlock
:
payloadFromBlock
,
toBlock
:
payloadToBlock
,
startDate
:
payloadStartDate
,
...
...
@@ -67,16 +78,50 @@ const CommentsSearch = () => {
rangeSelectKey
:
searchRanges
.
rangeSelectKey
,
timeUnit
:
searchRanges
.
timeUnitSelectKey
,
};
startCommentSearch
(
commentS
earchProps
,
s
earchProps
,
setCommentSearchProps
,
setCommentPaginationPage
,
setPreviousCommentSearchProps
,
(
val
:
"
comment
"
)
=>
setLastSearchKey
(
val
)
);
// change url on comments page when filters are applied
if
(
isCommentsPage
)
{
const
commentPageLink
=
getCommentPageLink
({
...
searchProps
,
...
searchRanges
,
operationTypes
:
searchProps
?.
filters
?.
length
?
convertBooleanArrayToIds
(
searchProps
.
filters
)
:
undefined
,
});
router
.
replace
(
commentPageLink
);
}
}
};
//Set parameters for inputs and selected operation types from url (if there are any) on initial load
useEffect
(()
=>
{
if
(
isCommentsPage
)
{
const
accountNameFromRoute
=
trimAccountName
(
(
router
.
query
.
accountName
?.[
0
]
as
string
)
??
""
);
const
permlinkFromRoute
=
router
.
query
.
permlink
??
""
;
const
filtersFromRoute
=
router
.
query
.
filters
??
""
;
setCommentsSearchAccountName
(
accountNameFromRoute
);
setCommentsSearchPermlink
(
permlinkFromRoute
);
if
(
!!
filtersFromRoute
)
{
const
convertedFilters
=
convertBooleanArrayToIds
(
parseUrlFlagsIntoBooleanArray
(
filtersFromRoute
as
string
)
);
setSelectedCommentSearchOperationTypes
(
convertedFilters
);
}
}
},
[
isCommentsPage
,
router
.
query
]);
return
(
<>
<
p
className
=
"ml-2"
>
...
...
@@ -85,8 +130,8 @@ const CommentsSearch = () => {
</
p
>
<
div
className
=
"flex flex-col"
>
<
AutocompleteInput
value
=
{
accountName
}
onChange
=
{
setAccountName
}
value
=
{
commentsSearchAccountName
as
string
}
onChange
=
{
set
CommentsSearch
AccountName
}
placeholder
=
"Author"
inputType
=
"account_name"
className
=
"w-1/2 bg-theme dark:bg-theme border-0 border-b-2"
...
...
@@ -98,8 +143,8 @@ const CommentsSearch = () => {
data-testid
=
"permlink-input"
className
=
"w-1/2 bg-theme dark:bg-theme border-0 border-b-2"
type
=
"text"
value
=
{
p
ermlink
}
onChange
=
{
(
e
)
=>
setPermlink
(
e
.
target
.
value
)
}
value
=
{
commentsSearchP
ermlink
}
onChange
=
{
(
e
)
=>
set
CommentsSearch
Permlink
(
e
.
target
.
value
)
}
placeholder
=
"Permlink *"
required
/>
...
...
@@ -121,16 +166,16 @@ const CommentsSearch = () => {
<
div
className
=
"flex items-center"
>
<
Button
data-testid
=
"search-button"
onClick
=
{
handleStartCommentSearch
}
className
=
"mr-2 my-2"
onClick
=
{
onButtonClick
}
disabled
=
{
!
accountName
||
!
permlink
}
disabled
=
{
!
commentsSearchAccountName
||
!
commentsSearchPermlink
}
>
Search
{
commentSearchDataLoading
&&
(
<
Loader2
className
=
"ml-2 animate-spin h-4 w-4 ..."
/>
)
}
</
Button
>
{
!
a
ccountName
&&
(
{
!
commentsSearchA
ccountName
&&
(
<
label
className
=
"text-gray-300 dark:text-gray-500 "
>
Set author name and permlink
</
label
>
...
...
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