Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
9c2f4c93
Unverified
Commit
9c2f4c93
authored
Jul 03, 2023
by
tom goriunov
Committed by
GitHub
Jul 03, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #973 from blockscout/tom2drum/issue-963
search: bug fixes
parents
8fa0f622
b5c9adad
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
70 additions
and
19 deletions
+70
-19
SearchResults.tsx
ui/pages/SearchResults.tsx
+11
-2
SearchBar.pw.tsx
ui/snippets/searchBar/SearchBar.pw.tsx
+14
-10
SearchBarInput.pw.tsx
ui/snippets/searchBar/SearchBarInput.pw.tsx
+38
-0
SearchBarInput.tsx
ui/snippets/searchBar/SearchBarInput.tsx
+1
-1
SearchBarSuggest.tsx
ui/snippets/searchBar/SearchBarSuggest.tsx
+4
-4
SearchBarInput.pw.tsx_dark-color-mode_input-on-home-page-mobile-dark-mode-1.png
...dark-color-mode_input-on-home-page-mobile-dark-mode-1.png
+0
-0
SearchBarInput.pw.tsx_dark-color-mode_input-on-regular-page-mobile-dark-mode-1.png
...k-color-mode_input-on-regular-page-mobile-dark-mode-1.png
+0
-0
SearchBarInput.pw.tsx_default_input-on-home-page-mobile-dark-mode-1.png
....pw.tsx_default_input-on-home-page-mobile-dark-mode-1.png
+0
-0
SearchBarInput.pw.tsx_default_input-on-regular-page-mobile-dark-mode-1.png
....tsx_default_input-on-regular-page-mobile-dark-mode-1.png
+0
-0
SearchBarInput.pw.tsx_mobile_input-on-home-page-mobile-dark-mode-1.png
...t.pw.tsx_mobile_input-on-home-page-mobile-dark-mode-1.png
+0
-0
SearchBarInput.pw.tsx_mobile_input-on-regular-page-mobile-dark-mode-1.png
...w.tsx_mobile_input-on-regular-page-mobile-dark-mode-1.png
+0
-0
useSearchQuery.tsx
ui/snippets/searchBar/useSearchQuery.tsx
+2
-2
No files found.
ui/pages/SearchResults.tsx
View file @
9c2f4c93
...
...
@@ -23,6 +23,15 @@ const SearchResultsPageContent = () => {
const
[
showContent
,
setShowContent
]
=
React
.
useState
(
false
);
React
.
useEffect
(()
=>
{
if
(
showContent
)
{
return
;
}
if
(
!
debouncedSearchTerm
)
{
setShowContent
(
true
);
return
;
}
if
(
redirectCheckQuery
.
data
?.
redirect
&&
redirectCheckQuery
.
data
.
parameter
)
{
switch
(
redirectCheckQuery
.
data
.
type
)
{
case
'
block
'
:
{
...
...
@@ -41,7 +50,7 @@ const SearchResultsPageContent = () => {
}
!
redirectCheckQuery
.
isLoading
&&
setShowContent
(
true
);
},
[
redirectCheckQuery
,
router
]);
},
[
redirectCheckQuery
,
router
,
debouncedSearchTerm
,
showContent
]);
const
handleSubmit
=
React
.
useCallback
((
event
:
FormEvent
<
HTMLFormElement
>
)
=>
{
event
.
preventDefault
();
...
...
@@ -157,4 +166,4 @@ const SearchResultsPageContent = () => {
);
};
export
default
SearchResultsPageContent
;
export
default
React
.
memo
(
SearchResultsPageContent
)
;
ui/snippets/searchBar/SearchBar.pw.tsx
View file @
9c2f4c93
...
...
@@ -162,23 +162,23 @@ test('search by tx hash +@mobile', async({ mount, page }) => {
});
test
(
'
search with simple match
'
,
async
({
mount
,
page
})
=>
{
const
API_URL
=
buildApiUrl
(
'
search
'
)
+
`?q=
${
searchMock
.
t
x1
.
tx_hash
}
`
;
const
API_CHECK_REDIRECT_URL
=
buildApiUrl
(
'
search_check_redirect
'
)
+
`?q=
${
searchMock
.
t
x1
.
tx_hash
}
`
;
const
API_URL
=
buildApiUrl
(
'
search
'
)
+
`?q=
${
searchMock
.
t
oken2
.
name
}
`
;
const
API_CHECK_REDIRECT_URL
=
buildApiUrl
(
'
search_check_redirect
'
)
+
`?q=
${
searchMock
.
t
oken2
.
name
}
`
;
await
page
.
route
(
API_URL
,
(
route
)
=>
route
.
fulfill
({
status
:
200
,
body
:
JSON
.
stringify
({
items
:
[
searchMock
.
t
x1
,
searchMock
.
t
oken2
,
],
}),
}));
await
page
.
route
(
API_CHECK_REDIRECT_URL
,
(
route
)
=>
route
.
fulfill
({
status
:
200
,
body
:
JSON
.
stringify
({
parameter
:
searchMock
.
t
x1
.
tx_hash
,
parameter
:
searchMock
.
t
oken2
.
address
,
redirect
:
true
,
type
:
'
transaction
'
,
type
:
'
address
'
,
}),
}));
...
...
@@ -187,14 +187,18 @@ test('search with simple match', async({ mount, page }) => {
<
SearchBar
/>
</
TestApp
>,
);
await
page
.
getByPlaceholder
(
/search/i
).
type
(
searchMock
.
t
x1
.
tx_hash
);
await
page
.
getByPlaceholder
(
/search/i
).
type
(
searchMock
.
t
oken2
.
name
);
await
page
.
waitForResponse
(
API_URL
);
await
page
.
waitForResponse
(
API_CHECK_REDIRECT_URL
);
const
resultText
=
page
.
getByText
(
'
Found 2 matching result
'
);
await
expect
(
resultText
).
toBeVisible
();
const
resultText
=
page
.
getByText
(
'
Found 1 matching result
'
);
expect
(
resultText
).
toBeTruthy
(
);
const
linkToToken
=
page
.
getByText
(
searchMock
.
token2
.
name
);
await
expect
(
linkToToken
).
toHaveCount
(
1
);
const
link
s
=
page
.
getByText
(
searchMock
.
tx1
.
tx_hash
);
await
expect
(
link
s
).
toHaveCount
(
1
);
const
link
ToAddress
=
page
.
getByText
(
searchMock
.
token2
.
address
);
await
expect
(
link
ToAddress
).
toHaveCount
(
2
);
});
test
(
'
recent keywords suggest +@mobile
'
,
async
({
mount
,
page
})
=>
{
...
...
ui/snippets/searchBar/SearchBarInput.pw.tsx
0 → 100644
View file @
9c2f4c93
import
{
LightMode
}
from
'
@chakra-ui/react
'
;
import
{
test
,
expect
}
from
'
@playwright/experimental-ct-react
'
;
import
React
from
'
react
'
;
import
TestApp
from
'
playwright/TestApp
'
;
import
SearchBarInput
from
'
./SearchBarInput
'
;
const
props
=
{
onChange
:
()
=>
{},
onSubmit
:
()
=>
{},
onClear
:
()
=>
{},
value
:
'
duck duck
'
,
};
test
(
'
input on regular page +@mobile +@dark-mode
'
,
async
({
mount
,
page
})
=>
{
await
mount
(
<
TestApp
>
<
SearchBarInput
{
...
props
}
/>
</
TestApp
>,
);
const
input
=
page
.
getByPlaceholder
(
/search by/i
);
await
expect
(
input
).
toHaveScreenshot
();
});
test
(
'
input on home page +@mobile +@dark-mode
'
,
async
({
mount
,
page
})
=>
{
await
mount
(
<
TestApp
>
<
LightMode
>
<
SearchBarInput
{
...
props
}
isHomepage
/>
</
LightMode
>
</
TestApp
>,
);
const
input
=
page
.
getByPlaceholder
(
/search by/i
);
await
expect
(
input
).
toHaveScreenshot
();
});
ui/snippets/searchBar/SearchBarInput.tsx
View file @
9c2f4c93
...
...
@@ -107,7 +107,7 @@ const SearchBarInput = ({ onChange, onSubmit, isHomepage, onFocus, onBlur, onHid
value=
{
value
}
/>
{
value
&&
(
<
InputRightElement
top=
{
{
base
:
2
,
lg
:
'
18px
'
}
}
right=
{
2
}
>
<
InputRightElement
top=
{
{
base
:
isHomepage
?
'
18px
'
:
2
,
lg
:
'
18px
'
}
}
right=
{
2
}
>
<
ClearButton
onClick=
{
onClear
}
/>
</
InputRightElement
>
)
}
...
...
ui/snippets/searchBar/SearchBarSuggest.tsx
View file @
9c2f4c93
...
...
@@ -16,16 +16,16 @@ const getUniqueIdentifier = (item: SearchResultItem) => {
switch
(
item
.
type
)
{
case
'
contract
'
:
case
'
address
'
:
{
return
item
.
address
;
return
item
.
type
+
item
.
address
;
}
case
'
transaction
'
:
{
return
item
.
tx_hash
;
return
item
.
t
ype
+
item
.
t
x_hash
;
}
case
'
block
'
:
{
return
item
.
block_hash
||
item
.
block_number
;
return
item
.
type
+
(
item
.
block_hash
||
item
.
block_number
)
;
}
case
'
token
'
:
{
return
item
.
address
;
return
item
.
type
+
item
.
address
;
}
}
};
...
...
ui/snippets/searchBar/__screenshots__/SearchBarInput.pw.tsx_dark-color-mode_input-on-home-page-mobile-dark-mode-1.png
0 → 100644
View file @
9c2f4c93
2.71 KB
ui/snippets/searchBar/__screenshots__/SearchBarInput.pw.tsx_dark-color-mode_input-on-regular-page-mobile-dark-mode-1.png
0 → 100644
View file @
9c2f4c93
2.89 KB
ui/snippets/searchBar/__screenshots__/SearchBarInput.pw.tsx_default_input-on-home-page-mobile-dark-mode-1.png
0 → 100644
View file @
9c2f4c93
2.38 KB
ui/snippets/searchBar/__screenshots__/SearchBarInput.pw.tsx_default_input-on-regular-page-mobile-dark-mode-1.png
0 → 100644
View file @
9c2f4c93
2.75 KB
ui/snippets/searchBar/__screenshots__/SearchBarInput.pw.tsx_mobile_input-on-home-page-mobile-dark-mode-1.png
0 → 100644
View file @
9c2f4c93
1.93 KB
ui/snippets/searchBar/__screenshots__/SearchBarInput.pw.tsx_mobile_input-on-regular-page-mobile-dark-mode-1.png
0 → 100644
View file @
9c2f4c93
1.98 KB
ui/snippets/searchBar/useSearchQuery.tsx
View file @
9c2f4c93
...
...
@@ -44,12 +44,12 @@ export default function useSearchQuery(isSearchPage = false) {
}
},
debouncedSearchTerm
);
return
{
return
React
.
useMemo
(()
=>
(
{
searchTerm
,
debouncedSearchTerm
,
handleSearchTermChange
:
setSearchTerm
,
query
,
redirectCheckQuery
,
pathname
,
};
}
),
[
debouncedSearchTerm
,
pathname
,
query
,
redirectCheckQuery
,
searchTerm
])
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment