Skip to content

Commit

Permalink
Merge pull request #645 from alleslabs/fix/cfe-29-add-search-resource
Browse files Browse the repository at this point in the history
Fix/cfe 29 add search resource
  • Loading branch information
evilpeach authored Dec 8, 2023
2 parents 6e465b6 + 857ff05 commit d31e867
Show file tree
Hide file tree
Showing 17 changed files with 312 additions and 209 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Improvements

- [#645](https://github.com/alleslabs/celatone-frontend/pull/645) Add search for resource in account detail
- [#634](https://github.com/alleslabs/celatone-frontend/pull/634) api v1 - move pool info
- [#657](https://github.com/alleslabs/celatone-frontend/pull/657) api v1 - overview stats
- [#650](https://github.com/alleslabs/celatone-frontend/pull/650) api v1 - account info on account detail page
- [#655](https://github.com/alleslabs/celatone-frontend/pull/655) Change title of publish new module page
Expand Down
1 change: 1 addition & 0 deletions src/lib/app-provider/hooks/useBaseApiRoute.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable complexity */
import { useCelatoneApp } from "../contexts";
import { CELATONE_API_OVERRIDE as api } from "env";

Expand Down
13 changes: 11 additions & 2 deletions src/lib/components/resource/ResourceDetailCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,17 @@ export const ResourceDetailCard = ({
>
<Flex direction="column" gap={3}>
{formattedArray.map((item) => (
<Flex key={item.key} gap={4}>
<Text variant="body2" color="text.dark" minW={40}>
<Flex
key={item.key}
gap={{ base: 1, md: 4 }}
direction={{ base: "column", md: "row" }}
>
<Text
variant="body2"
color="text.dark"
fontWeight="600"
minW={40}
>
{item.key}
</Text>
{typeof item.value === "object" ? (
Expand Down
38 changes: 20 additions & 18 deletions src/lib/components/state/EmptyState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,31 @@ export const EmptyState = ({
textVariant = "body1",
}: EmptyStateProps) => (
<Flex
alignItems="center"
flexDir="column"
gap={4}
width="full"
py={py}
my={my}
direction="column"
borderY={withBorder ? "1px solid" : undefined}
borderColor="gray.700"
>
<Flex alignItems="center" flexDir="column" gap={4} width="full">
{imageVariant && (
<StateImage imageVariant={imageVariant} imageWidth={imageWidth} />
)}
{heading && (
<Heading as="h5" variant="h5">
{heading}
</Heading>
)}
<Text
color="text.dark"
textAlign="center"
whiteSpace="pre-wrap"
variant={textVariant}
>
{message}
</Text>
</Flex>
{imageVariant && (
<StateImage imageVariant={imageVariant} imageWidth={imageWidth} />
)}
{heading && (
<Heading as="h5" variant="h5">
{heading}
</Heading>
)}
<Text
color="text.dark"
textAlign="center"
whiteSpace="pre-wrap"
variant={textVariant}
>
{message}
</Text>
</Flex>
);
10 changes: 8 additions & 2 deletions src/lib/components/table/MobileTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { TableTitle } from "./TableTitle";
interface MobileTitleProps {
title: string;
count: Option<number>;
showCount?: boolean;
onViewMore?: () => void;
}
const cardProps = {
Expand All @@ -17,14 +18,19 @@ const cardProps = {
borderRadius: "8px",
};

export const MobileTitle = ({ onViewMore, title, count }: MobileTitleProps) => (
export const MobileTitle = ({
title,
count,
showCount = true,
onViewMore,
}: MobileTitleProps) => (
<Flex
style={cardProps}
onClick={!count ? undefined : onViewMore}
opacity={!count ? 0.5 : 1}
bg="gray.900"
>
<TableTitle title={title} count={count} mb={0} />
<TableTitle title={title} count={count} showCount={showCount} mb={0} />
<CustomIcon name="chevron-right" color="gray.600" />
</Flex>
);
14 changes: 8 additions & 6 deletions src/lib/components/table/TableTitle.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import type { BoxProps } from "@chakra-ui/react";
import { Badge, Box, Flex, Heading, Text } from "@chakra-ui/react";

import type { Option } from "lib/types";

interface TableTitleProps extends BoxProps {
title: string;
count: Option<number>;
count?: number;
showCount?: boolean;
helperText?: string;
}

export const TableTitle = ({
title,
count,
showCount = true,
helperText,
mb = 6,
...props
Expand All @@ -21,9 +21,11 @@ export const TableTitle = ({
<Heading as="h6" variant="h6">
{title}
</Heading>
<Badge textColor={count ? "text.main" : "text.disabled"}>
{count ?? "N/A"}
</Badge>
{showCount && (
<Badge textColor={count ? "text.main" : "text.disabled"}>
{count ?? "N/A"}
</Badge>
)}
</Flex>
<Text variant="body2" textColor="text.dark" fontWeight={600}>
{helperText}
Expand Down
6 changes: 4 additions & 2 deletions src/lib/pages/account-details/components/ErrorFetching.tsx
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>
);
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const ModuleLists = ({
const isMobile = useMobile();
const isMobileOverview = isMobile && !!onViewMore;
return (
<Box mt={{ base: 4, md: 8 }}>
<Box mt={{ base: 4, md: 16 }}>
{isMobileOverview ? (
<MobileTitle
title="Modules"
Expand Down
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>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const ResourceOverview = ({
<TableTitle
title="Resources"
helperText="Resources stored in this account"
count={totalCount}
showCount={false}
/>
<ResourceOverviewBody
address={address}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,24 @@ import { ResourceSectionBody } from "./ResourceSectionBody";

interface ResourceSectionProps {
address: HumanAddr;
totalCount: Option<number>;
resourcesByOwner: Option<ResourceGroupByAccount[]>;
isLoading: boolean;
}

export const ResourceSection = ({
address,
totalCount,
resourcesByOwner,
isLoading,
}: ResourceSectionProps) => (
<Flex direction="column" mt={8}>
<TableTitle
helperText="Resources stored in this account"
title="Resources"
count={resourcesByOwner?.length}
count={totalCount}
/>
<Flex
gap={6}
flexDirection={{ base: "column", md: "row" }}
position="relative"
>
<Flex gap={6} flexDirection={{ base: "column", md: "row" }}>
<ResourceSectionBody
address={address}
resourcesByOwner={resourcesByOwner}
Expand Down
Loading

2 comments on commit d31e867

@vercel
Copy link

@vercel vercel bot commented on d31e867 Dec 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on d31e867 Dec 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.