Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter data feed table #1403

Merged
merged 24 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
28b23ca
filter data-feed by category
simkasss Jul 12, 2023
5c8f081
pagination wip
simkasss Jul 14, 2023
723e2ab
filter eth mainnet table
simkasss Jul 21, 2023
0fc7324
Merge branch 'main' into filter-data-feed-table
simkasss Jul 21, 2023
03fd38b
add search input
simkasss Jul 24, 2023
8194918
url sync with search
simkasss Jul 24, 2023
4c94bd0
update placeholder
simkasss Jul 24, 2023
4d4001c
Merge branch 'main' into filter-data-feed-table
dwightjl Jul 24, 2023
38887aa
Token terminology update (#1414)
dwightjl Jul 24, 2023
ff4eb0e
Vrf v2 cost calculator (#1353)
yacine-benichou Jul 25, 2023
3769067
Fix issue where supported network link did not work for certain netwo…
yacine-benichou Jul 25, 2023
9eaae20
fix tsconfig.json errors in vscode (#1416)
aelmanaa Jul 26, 2023
8e2837d
Vrf v2 cost calculator (#1418)
yacine-benichou Jul 26, 2023
f0acf70
add query parameters
simkasss Aug 3, 2023
7d278e6
close dropdown on click outside
simkasss Aug 3, 2023
0e577b4
Merge branch 'main' into filter-data-feed-table
simkasss Aug 3, 2023
7e54c92
Merge branch 'main' into filter-data-feed-table
dwightjl Aug 3, 2023
baf1079
flexible search box
simkasss Aug 15, 2023
545902f
merge main
simkasss Aug 15, 2023
1d2d44a
reset search and categories on network select
simkasss Aug 15, 2023
ce8426a
typecheck
simkasss Aug 15, 2023
6149824
Merge branch 'main' into filter-data-feed-table
dwightjl Aug 22, 2023
61b3b48
Merge branch 'main' into filter-data-feed-table
dwightjl Sep 6, 2023
16f82a5
fix queryString usage
simkasss Sep 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/features/data/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface Docs {
feedType?: string
hidden?: boolean
porAuditor?: string
porSource?: string
porType?: string
productSubType?: string
productType?: string
Expand Down
103 changes: 103 additions & 0 deletions src/features/feeds/components/FeedList.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,106 @@ div.shutDate > hr {
height: 32px;
transition: all 0.15s;
}

.filterDropdown_details {
position: relative;
cursor: pointer;
display: block;
margin: var(--space-0x) var(--space-2x) var(--space-2x) var(--space-6x);
margin-left: 0px;
width: 200px;
display: inline-block;
line-height: 0;
}

.filterDropdown_search {
display: inline-block;
padding: var(--space-2x) var(--space-4x) var(--space-2x) var(--space-2x);
position: relative;
}
.filterDropdown_searchInput {
height: 42px;
width: 200px;
border: var(--border-width-primary) solid var(--color-border-primary);
background-image: url(https://smartcontract.imgix.net/icons/searchIcon_blue_noborder.svg?auto=compress%2Cformat);
background-repeat: no-repeat;
background-position: left var(--space-2x) top 50%;
padding-left: var(--space-8x);
background-size: 16px;
}
.detailsLabel {
display: inline;
}

@media screen and (max-width: 450px) {
.filterDropdown_details,
.filterDropdown_search {
padding-left: 0px;
padding-top: 1px;
}
}

@media screen and (max-width: 450px) {
.detailsLabel {
display: block;
padding: 1px;
}
}

.filterDropdown_details summary {
color: var(--gray-900);
width: 100%;
padding: var(--space-3x) var(--space-3x) var(--space-3x) var(--space-4x);
border: var(--border-width-primary) solid var(--color-border-primary);
border-radius: var(--border-radius-primary);
background-image: url(https://smartcontract.imgix.net/icons/Caret.svg?auto=compress%2Cformat);
background-repeat: no-repeat;
background-position: right var(--space-2x) top 50%;
list-style: none;
}

.filterDropdown_details nav {
position: absolute;
border-radius: var(--border-radius-primary);
background: var(--white);
z-index: 1;
margin-top: var(--space-2x);
min-width: 165px;
width: 100%;
box-shadow: var(--shadow-mid-secondary);
border: var(--border-width-primary) solid var(--color-border-primary);
}
.filterDropdown_details ul {
list-style: none;
max-height: 280px;
overflow-y: scroll;
padding: 0 var(--space-2x);
}
.filterDropdown_details li button {
display: flex;
align-items: center;
justify-content: flex-start;
color: var(--color-text-primary);
-webkit-font-feature-settings: "liga" off;
font-feature-settings: "liga" off;
text-align: left;
text-decoration: none;
cursor: pointer;
white-space: nowrap;
padding: var(--space-4x) var(--space-2x);
margin: 0;
width: 100%;
}
.filterDropdown_details li button input {
width: auto;
margin-right: var(--space-2x);
}
.filterDropdown_details li button:hover {
color: var(--color-text-link-hover);
fill: var(--color-text-link-hover);
background-color: var(--blue-100);
font-weight: 500;
}
.filterDropdown_filter {
padding: var(--space-3x) var(--space-4x) var(--space-5x) var(--space-4x);
}
111 changes: 107 additions & 4 deletions src/features/feeds/components/FeedList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @jsxImportSource preact */
import { useEffect, useState } from "preact/hooks"
import { useEffect, useState, useRef } from "preact/hooks"
import { MainnetTable, TestnetTable } from "./Tables"
import feedList from "./FeedList.module.css"
import { clsx } from "~/lib"
Expand All @@ -8,6 +8,7 @@ import { Chain, CHAINS, ALL_CHAINS } from "~/features/data/chains"
import { useGetChainMetadata } from "./useGetChainMetadata"
import { ChainMetadata } from "../../data/api"
import useQueryString from "~/hooks/useQueryString"
import { RefObject } from "preact"

export type DataFeedType = "default" | "por" | "nftFloor" | "rates"
export const FeedList = ({
Expand All @@ -23,18 +24,68 @@ export const FeedList = ({
const chains = ecosystem === "deprecating" ? ALL_CHAINS : CHAINS

const [selectedChain, setSelectedChain] = useQueryString("network", chains[0].page)
const [searchValue, setSearchValue] = useQueryString("search", "")
const [selectedFeedCategories, setSelectedFeedCategories] = useQueryString("categories", [])
const [showCategoriesDropdown, setShowCategoriesDropdown] = useState<boolean>(false)
const [showExtraDetails, setShowExtraDetails] = useState(false)

const [currentPage, setCurrentPage] = useQueryString("page", "1")
const paginate = (pageNumber) => setCurrentPage(String(pageNumber))
const addrPerPage = 8
const lastAddr = Number(currentPage) * addrPerPage
const firstAddr = lastAddr - addrPerPage
const dataFeedCategory = ["verified", "monitored", "provisional", "custom", "specialized", "deprecating"]
const chainMetadata = useGetChainMetadata(chains.filter((chain) => chain.page === selectedChain)[0], { initialCache })
const wrapperRef = useRef(null)

function handleNetworkSelect(chain: Chain) {
setSelectedChain(chain.page)
setSearchValue("")
setSelectedFeedCategories([])
setCurrentPage("1")
}

const handleCategorySelection = (category) => {
paginate(1)
if (typeof selectedFeedCategories === "string" && selectedFeedCategories !== category) {
setSelectedFeedCategories([selectedFeedCategories, category])
} else if (typeof selectedFeedCategories === "string" && selectedFeedCategories === category) {
setSelectedFeedCategories([])
}
if (Array.isArray(selectedFeedCategories) && selectedFeedCategories.includes(category)) {
setSelectedFeedCategories(selectedFeedCategories.filter((item) => item !== category))
} else if (Array.isArray(selectedFeedCategories)) {
setSelectedFeedCategories([...selectedFeedCategories, category])
}
}

useEffect(() => {
updateTableOfContents()
}, [chainMetadata.processedData])
if (searchValue === "") {
const searchParams = new URLSearchParams(window.location.search)
searchParams.delete("search")
const newUrl = window.location.pathname + "?" + searchParams.toString()
window.history.replaceState({ path: newUrl }, "", newUrl)
const inputElement = document.getElementById("search") as HTMLInputElement
if (inputElement) {
inputElement.placeholder = "Search price feeds"
}
}
}, [chainMetadata.processedData, searchValue])

const useOutsideAlerter = (ref: RefObject<HTMLDivElement>) => {
useEffect(() => {
function handleClickOutside(event: MouseEvent) {
if (ref.current && event.target instanceof Node && !ref.current.contains(event.target)) {
setShowCategoriesDropdown(false)
}
}
document.addEventListener("mousedown", handleClickOutside)
return () => {
document.removeEventListener("mousedown", handleClickOutside)
}
}, [ref])
}
useOutsideAlerter(wrapperRef)
const isPor = dataFeedType === "por"
const isNftFloor = dataFeedType === "nftFloor"
const isRates = dataFeedType === "rates"
Expand Down Expand Up @@ -128,7 +179,46 @@ export const FeedList = ({
<a href="/docs/data-feeds/l2-sequencer-feeds/">L2 Sequencer Uptime Feeds</a> page for examples.
</p>
)}
<label>

<details class={feedList.filterDropdown_details}>
<summary
class={feedList.filterDropdown_details}
className="text-200"
onClick={() => setShowCategoriesDropdown((prev) => !prev)}
>
Data Feed Categories
</summary>
<nav ref={wrapperRef} style={!showCategoriesDropdown ? { display: "none" } : {}}>
<ul>
{dataFeedCategory.map((category) => (
<li>
<button onClick={() => handleCategorySelection(category)}>
<input
type="checkbox"
checked={selectedFeedCategories?.includes(category)}
readonly
style="cursor:pointer;"
/>
<span> {category}</span>
</button>
</li>
))}
</ul>
</nav>
</details>

<div class={feedList.filterDropdown_search}>
<input
id="search"
class={feedList.filterDropdown_searchInput}
placeholder="Search price feeds"
onInput={(event) => {
setSearchValue((event.target as HTMLInputElement).value)
setCurrentPage("1")
}}
/>
</div>
<label class={feedList.detailsLabel}>
<input
type="checkbox"
style="width:15px;height:15px;display:inline;"
Expand All @@ -138,10 +228,23 @@ export const FeedList = ({
Show more details
</label>
<MainnetTable
selectedFeedCategories={
Array.isArray(selectedFeedCategories)
? selectedFeedCategories
: selectedFeedCategories
? [selectedFeedCategories]
: []
}
network={network}
showExtraDetails={showExtraDetails}
dataFeedType={dataFeedType}
ecosystem={ecosystem}
lastAddr={lastAddr}
firstAddr={firstAddr}
addrPerPage={addrPerPage}
currentPage={Number(currentPage)}
paginate={paginate}
searchValue={typeof searchValue === "string" ? searchValue : ""}
/>
</div>
) : (
Expand Down
55 changes: 54 additions & 1 deletion src/features/feeds/components/Tables.module.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
.table th[aria-hidden="true"],
.table td[aria-hidden="true"] {
.table td[aria-hidden="true"],
.mainnetTable th[aria-hidden="true"],
.mainnetTable td[aria-hidden="true"] {
display: none;
}

.mainnetTable {
table-layout: auto;
width: 100%;
overflowx: auto;
}

.mainnetTable th:nth-child(1),
.mainnetTable td:nth-child(1) {
width: 150px;
}

.mainnetTable th:nth-child(2),
.mainnetTable td:nth-child(2) {
width: 80px;
}
.mainnetTable th:nth-child(3),
.mainnetTable td:nth-child(3) {
width: 80px;
}
.mainnetTable th:nth-child(4),
.mainnetTable td:nth-child(4) {
width: 50px;
}

.heading {
font-family: var(--font-family-text);
line-height: 1.3;
Expand Down Expand Up @@ -48,3 +74,30 @@
align-items: center;
gap: var(--space-1x);
}

.pagination {
display: flex;
margin: 8px 0px 0px;
flex-wrap: wrap;
justify-content: space-between;
padding: 4px;
}

@media screen and (max-width: 500px) {
.pagination {
margin-top: 10px;
margin-bottom: 10px;
}
}

.pagination p {
text-align: center;
margin: 8px 0px 0px;
}

@media screen and (max-width: 500px) {
.pagination p {
order: 1;
width: 100%;
}
}
Loading