-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): add filter panel with rollup filter in PaginatedTable
- Loading branch information
Showing
7 changed files
with
150 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
apps/web/src/components/PaginatedTable/components/FilterPanel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { useState } from "react"; | ||
import type { FC } from "react"; | ||
|
||
import { Button } from "~/components/Button"; | ||
import type { Rollup } from "~/types"; | ||
import type { Option } from "../../Dropdown/Dropdown"; | ||
import type { PaginatedTableQueryFilters } from "../PaginatedTable"; | ||
import { RollupFilter } from "./RollupFilter"; | ||
|
||
interface FilterPanelState { | ||
rollup: Option | null; | ||
} | ||
|
||
interface FilterPanelProps { | ||
onFilter: (queryFilters: PaginatedTableQueryFilters) => void; | ||
} | ||
|
||
export const FilterPanel: FC<FilterPanelProps> = function ({ onFilter }) { | ||
const [formData, setFormData] = useState<FilterPanelState>({ | ||
rollup: null, | ||
}); | ||
|
||
const allowToFilter = !!formData.rollup; | ||
|
||
const handleSubmit = () => { | ||
!!formData.rollup && onFilter({ rollup: formData.rollup.value as Rollup }); | ||
}; | ||
|
||
const handleRollupFilterChange = (newRollup: Option) => { | ||
setFormData((prevState) => ({ ...prevState, rollup: newRollup })); | ||
}; | ||
|
||
return ( | ||
<form | ||
className="flex justify-between rounded-lg bg-slate-50 p-2" | ||
onSubmit={handleSubmit} | ||
> | ||
<RollupFilter | ||
selected={formData.rollup} | ||
onChange={handleRollupFilterChange} | ||
/> | ||
<Button label="Filter" onClick={handleSubmit} disabled={!allowToFilter} /> | ||
</form> | ||
); | ||
}; |
53 changes: 53 additions & 0 deletions
53
apps/web/src/components/PaginatedTable/components/RollupFilter.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import type { FC } from "react"; | ||
|
||
import { Dropdown } from "~/components/Dropdown/Dropdown"; | ||
import type { DropdownProps } from "~/components/Dropdown/Dropdown"; | ||
import { RollupIcon } from "~/components/RollupIcon"; | ||
import type { Rollup } from "~/types"; | ||
|
||
const rollups: Rollup[] = [ | ||
"base", | ||
"mode", | ||
"scroll", | ||
"arbitrum", | ||
"blast", | ||
"boba", | ||
"camp", | ||
"kroma", | ||
"linea", | ||
"metal", | ||
"optimism", | ||
"optopia", | ||
"paradex", | ||
"pgn", | ||
"starknet", | ||
"taiko", | ||
"zksync", | ||
"zora", | ||
]; | ||
|
||
const ROLLUP_OPTIONS: DropdownProps["options"] = rollups.map((rollup) => { | ||
const icon = <RollupIcon rollup={rollup} />; | ||
return { | ||
value: rollup, | ||
label: rollup.charAt(0).toUpperCase() + rollup.slice(1), | ||
prefix: icon === null ? <div className="h-4 w-4"></div> : icon, | ||
}; | ||
}); | ||
|
||
type RollupFilterProps = Pick<DropdownProps, "onChange" | "selected">; | ||
|
||
export const RollupFilter: FC<RollupFilterProps> = function ({ | ||
onChange, | ||
selected, | ||
}) { | ||
return ( | ||
<Dropdown | ||
selected={selected} | ||
options={ROLLUP_OPTIONS} | ||
onChange={onChange} | ||
placeholder="Rollup" | ||
width="w-40" | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters