-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #645 from alleslabs/fix/cfe-29-add-search-resource
Fix/cfe 29 add search resource
- Loading branch information
Showing
17 changed files
with
312 additions
and
209 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { Flex } from "@chakra-ui/react"; | ||
|
||
import { CustomIcon } from "lib/components/icon"; | ||
|
||
export const ErrorFetching = () => ( | ||
<> | ||
<Flex> | ||
<CustomIcon name="alert-circle-solid" color="gray.600" boxSize={4} mr={3} /> | ||
<p>Error fetching data. Please try again later.</p> | ||
</> | ||
</Flex> | ||
); |
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
156 changes: 156 additions & 0 deletions
156
src/lib/pages/account-details/components/resources/ResourceLeftPanel.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,156 @@ | ||
import { | ||
Accordion, | ||
AccordionButton, | ||
AccordionIcon, | ||
AccordionItem, | ||
AccordionPanel, | ||
Flex, | ||
Text, | ||
} from "@chakra-ui/react"; | ||
import { useRouter } from "next/router"; | ||
import { useCallback, useMemo, useState } from "react"; | ||
|
||
import { useInternalNavigate } from "lib/app-provider"; | ||
import InputWithIcon from "lib/components/InputWithIcon"; | ||
import { ResourceCard } from "lib/components/resource"; | ||
import type { | ||
HumanAddr, | ||
ResourceGroup, | ||
ResourceGroupByAccount, | ||
} from "lib/types"; | ||
import { getFirstQueryParam, truncate } from "lib/utils"; | ||
|
||
interface ResourceSectionBodyProps { | ||
address: HumanAddr; | ||
resourcesByOwner: ResourceGroupByAccount[]; | ||
} | ||
|
||
export const ResourceLeftPanel = ({ | ||
address, | ||
resourcesByOwner, | ||
}: ResourceSectionBodyProps) => { | ||
const router = useRouter(); | ||
const navigate = useInternalNavigate(); | ||
const [keyword, setKeyword] = useState(""); | ||
|
||
const selectedAccountParam = getFirstQueryParam( | ||
router.query.account, | ||
resourcesByOwner?.[0]?.owner | ||
); | ||
const selectedNameParam = getFirstQueryParam( | ||
router.query.selected, | ||
resourcesByOwner?.[0]?.resources[0]?.group | ||
); | ||
|
||
const handleSelectResource = useCallback( | ||
( | ||
account: ResourceGroupByAccount["owner"], | ||
resource: ResourceGroup["group"] | ||
) => { | ||
if (account === selectedAccountParam && resource === selectedNameParam) | ||
return; | ||
navigate({ | ||
pathname: `/accounts/[accountAddress]/[tab]`, | ||
query: { | ||
accountAddress: address, | ||
tab: "resources", | ||
account, | ||
selected: resource, | ||
}, | ||
replace: true, | ||
options: { | ||
shallow: true, | ||
}, | ||
}); | ||
}, | ||
[selectedNameParam, selectedAccountParam, address, navigate] | ||
); | ||
|
||
const filteredResourcesByOwner = useMemo(() => { | ||
if (!keyword) return resourcesByOwner; | ||
|
||
return resourcesByOwner?.map((each) => ({ | ||
...each, | ||
resources: each.resources.filter((resource) => | ||
resource.group | ||
.toLowerCase() | ||
.includes(keyword.trim().toLocaleLowerCase()) | ||
), | ||
})); | ||
}, [keyword, resourcesByOwner]); | ||
|
||
const selectedIndex = filteredResourcesByOwner.findIndex( | ||
(item) => item.owner === selectedAccountParam | ||
); | ||
const selectedGroup = filteredResourcesByOwner[selectedIndex]; | ||
const selectedResources = selectedGroup?.resources.find( | ||
(item) => item.group === selectedNameParam | ||
); | ||
|
||
return ( | ||
<Flex | ||
minW={{ base: "full", md: 80 }} | ||
direction="column" | ||
pb={{ base: 4, md: 0 }} | ||
mb={{ base: 4, md: 0 }} | ||
borderBottom={{ base: "1px solid", md: "none" }} | ||
borderColor={{ base: "gray.700", md: "transparent" }} | ||
> | ||
<InputWithIcon | ||
placeholder="Search with module name..." | ||
value={keyword} | ||
onChange={(e) => setKeyword(e.target.value)} | ||
action="execute-message-search" | ||
/> | ||
<Accordion | ||
allowMultiple | ||
defaultIndex={[selectedIndex]} | ||
width="full" | ||
mt={4} | ||
> | ||
{filteredResourcesByOwner.map((item) => ( | ||
<AccordionItem mb={4} key={item.owner}> | ||
<AccordionButton> | ||
<Flex p={4} justifyContent="space-between" w="full"> | ||
<Text variant="body1" fontWeight={600}> | ||
{truncate(item.owner)} | ||
</Text> | ||
<AccordionIcon color="gray.600" /> | ||
</Flex> | ||
</AccordionButton> | ||
<AccordionPanel> | ||
{item.resources.length ? ( | ||
<Flex direction="column" gap={3}> | ||
{Object.values(item.resources).map((subitem) => ( | ||
<ResourceCard | ||
key={subitem.displayName} | ||
name={subitem.group} | ||
amount={subitem.items.length} | ||
isSelected={selectedResources?.group === subitem.group} | ||
onClick={() => | ||
handleSelectResource(item.owner, subitem.group) | ||
} | ||
hasBorder | ||
/> | ||
))} | ||
</Flex> | ||
) : ( | ||
<Text | ||
variant="body2" | ||
color="text.dark" | ||
textAlign="center" | ||
p={4} | ||
border="1px solid" | ||
borderRadius="8px" | ||
borderColor="gray.700" | ||
> | ||
No matching resource found | ||
</Text> | ||
)} | ||
</AccordionPanel> | ||
</AccordionItem> | ||
))} | ||
</Accordion> | ||
</Flex> | ||
); | ||
}; |
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
Oops, something went wrong.
d31e867
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
osmosis-celatone-frontend-staging – ./
staging.osmoscan.io
osmosis-celatone-frontend-staging.vercel.app
osmosis-staging.celat.one
osmosis-celatone-frontend-staging-alleslabs.vercel.app
osmosis-celatone-frontend-staging-git-develop-alleslabs.vercel.app
celatone-staging.osmosis.zone
d31e867
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
celatone-frontend-staging – ./
celatone-frontend-staging.vercel.app
celatone-frontend-staging-alleslabs.vercel.app
dev.celat.one
celatone-frontend-staging-git-develop-alleslabs.vercel.app