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

fix(components): module link clickable with cmd/ctrl + add copier for resource #675

Merged
merged 10 commits into from
Dec 21, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Improvements

- [#675](https://github.com/alleslabs/celatone-frontend/pull/675) Make module links clickable with command/ctrl and add copier for struct names
- [#669](https://github.com/alleslabs/celatone-frontend/pull/669) api v1 - contract transaction
- [#672](https://github.com/alleslabs/celatone-frontend/pull/672) refactor balances
- [#662](https://github.com/alleslabs/celatone-frontend/pull/662) Add republish button in module detail
Expand Down
15 changes: 12 additions & 3 deletions src/lib/components/module/ModuleCard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Flex, Grid, Text } from "@chakra-ui/react";

import { AppLink } from "../AppLink";
import { CustomIcon } from "../icon";
import type { IndexedModule } from "lib/services/move/moduleService";
import { useVerifyModule } from "lib/services/move/moduleService";
Expand All @@ -11,7 +12,7 @@ interface ModuleCardProps {
selectedAddress: MoveAccountAddr;
module: IndexedModule;
selectedModule: Option<IndexedModule>;
setSelectedModule: (module: IndexedModule) => void;
setSelectedModule?: (module: IndexedModule) => void;
}

export const ModuleCard = ({
Expand All @@ -25,7 +26,7 @@ export const ModuleCard = ({
moduleName: module.moduleName,
});

return (
const card = (
<Grid
borderRadius={8}
bgColor={
Expand All @@ -36,7 +37,7 @@ export const ModuleCard = ({
p={4}
alignItems="center"
cursor="pointer"
onClick={() => setSelectedModule(module)}
onClick={() => setSelectedModule?.(module)}
gap={1}
templateColumns="20px 1fr auto"
_hover={{
Expand All @@ -63,4 +64,12 @@ export const ModuleCard = ({
</Flex>
</Grid>
);

return setSelectedModule ? (
card
) : (
<AppLink href={`/modules/${module.address}/${module.moduleName}`} passHref>
{card}
</AppLink>
);
};
32 changes: 21 additions & 11 deletions src/lib/components/resource/ResourceDetailCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import {
Text,
} from "@chakra-ui/react";

import { CopyButton } from "../copy";
import { Copier, CopyButton } from "../copy";
import { CustomIcon } from "../icon";
import { useMobile } from "lib/app-provider";
import type { InternalResource } from "lib/types";
import { parseJsonStr } from "lib/utils";

Expand All @@ -20,6 +21,7 @@ export const ResourceDetailCard = ({
resourceData,
}: ResourceDetailCardProps) => {
const parsedMoveResource = parseJsonStr(resourceData.moveResource);
const isMobile = useMobile();

// Handle fallback case where the move resource is invalid
// TODO: revisit later
Expand Down Expand Up @@ -59,17 +61,25 @@ export const ResourceDetailCard = ({
justifyContent="space-between"
w="full"
align="center"
gap={{ base: 4, md: 8 }}
className="copier-wrapper"
>
<Text
variant="body1"
fontWeight={600}
textAlign="left"
wordBreak="break-word"
>
{resourceData.structTag}
</Text>
<Flex alignItems="center" gap={2} minW={{ base: 8, md: 36 }}>
<Flex alignItems="center">
<Text
variant="body1"
fontWeight={600}
textAlign="left"
wordBreak="break-word"
>
{resourceData.structTag}
</Text>
<Copier
type="resource"
display={!isMobile ? "none" : "inline"}
value={resourceData.structTag}
copyLabel="Copied!"
jennieramida marked this conversation as resolved.
Show resolved Hide resolved
/>
</Flex>
<Flex alignItems="center" gap={2}>
<CopyButton
value={resourceData.moveResource}
variant="outline-gray"
Expand Down
25 changes: 16 additions & 9 deletions src/lib/components/table/modules/ModulePathLink.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Flex, Text } from "@chakra-ui/react";

import { useMobile } from "lib/app-provider";
import { AppLink } from "lib/components/AppLink";
import { Copier } from "lib/components/copy";
import type { HexAddr } from "lib/types";
import { truncate } from "lib/utils";
Expand All @@ -23,16 +24,22 @@ export const ModulePathLink = ({
align="center"
h="24px"
>
<Text
variant="body2"
color="secondary.main"
transition="all 0.25s ease-in-out"
_hover={{ color: "secondary.light", textDecoration: "underline" }}
wordBreak={{ base: "break-all", md: "inherit" }}
cursor="pointer"
<AppLink
href={`/modules/${hexAddr}/${moduleName}`}
passHref
onClick={(e) => e.stopPropagation()}
jennieramida marked this conversation as resolved.
Show resolved Hide resolved
>
{`${truncate(hexAddr)} :: ${moduleName}`}
</Text>
<Text
variant="body2"
color="secondary.main"
transition="all 0.25s ease-in-out"
_hover={{ color: "secondary.light", textDecoration: "underline" }}
wordBreak={{ base: "break-all", md: "inherit" }}
cursor="pointer"
>
{`${truncate(hexAddr)} :: ${moduleName}`}
</Text>
jennieramida marked this conversation as resolved.
Show resolved Hide resolved
</AppLink>
<Copier
type="module_path"
value={`${hexAddr}::${moduleName}`}
Expand Down
7 changes: 4 additions & 3 deletions src/lib/components/table/modules/ModulesTableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ export const ModulesTableRow = ({
templateColumns={templateColumns}
_hover={{ background: "gray.900" }}
transition="all 0.25s ease-in-out"
onClick={() =>
onClick={(e) => {
e.stopPropagation();
jennieramida marked this conversation as resolved.
Show resolved Hide resolved
navigate({
pathname: "/modules/[address]/[moduleName]",
query: {
address: hex,
moduleName: moduleInfo.name,
},
})
}
});
}}
>
<TableRow>
<ModulePathLink hexAddr={hex} moduleName={moduleInfo.name} />
Expand Down
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: 16 }}>
<Box mt={{ base: 4, md: 8 }}>
{isMobileOverview ? (
<MobileTitle
title="Modules"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { SimpleGrid } from "@chakra-ui/react";
import { useMemo } from "react";

import { useInternalNavigate } from "lib/app-provider";
import { Loading } from "lib/components/Loading";
import { ModuleCard } from "lib/components/module";
import { ErrorFetching, EmptyState } from "lib/components/state";
Expand All @@ -23,8 +22,6 @@ export const ModuleListsBody = ({
isLoading,
onViewMore,
}: ModuleListsBodyProps) => {
const navigate = useInternalNavigate();

const filteredModules = useMemo(() => {
if (!keyword) return modules;

Expand All @@ -34,25 +31,18 @@ export const ModuleListsBody = ({
);
}, [keyword, modules]);

const handleOnSelect = (module: IndexedModule) => {
navigate({
pathname: `/modules/[address]/[moduleName]`,
query: {
address: selectedAddress,
moduleName: module.moduleName,
},
});
};

if (isLoading) return <Loading />;
if (!modules) return <ErrorFetching dataName="modules" />;
if (!filteredModules?.length)
return (
<EmptyState
imageVariant={!keyword ? "empty" : "not-found"}
message={!keyword ? "No modules found" : "No matched modules found"}
message={
!keyword
? "There are no modules on this account."
: "No matched modules found"
}
withBorder
my={0}
/>
);
return (
Expand All @@ -64,7 +54,6 @@ export const ModuleListsBody = ({
selectedAddress={selectedAddress}
module={item}
selectedModule={undefined}
setSelectedModule={handleOnSelect}
/>
)
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Accordion, Badge, Box, Button, Flex, Heading } from "@chakra-ui/react";
import { useRouter } from "next/router";
import { useEffect, useState } from "react";

import { useMobile } from "lib/app-provider";
import { Copier } from "lib/components/copy";
import { CustomIcon } from "lib/components/icon";
import { Loading } from "lib/components/Loading";
import { ResourceDetailCard } from "lib/components/resource";
Expand All @@ -23,6 +25,8 @@ export const ResourceSectionBody = ({
isLoading,
}: ResourceSectionBodyProps) => {
const router = useRouter();
const isMobile = useMobile();

const [expandedIndexes, setExpandedIndexes] = useState<number[]>([]);

const selectedAccountParam = getFirstQueryParam(
Expand Down Expand Up @@ -59,13 +63,19 @@ export const ResourceSectionBody = ({
pb={6}
gap={12}
>
<Flex alignItems="center">
<Flex alignItems="center" w="full" className="copier-wrapper">
<Heading as="h6" variant="h6" wordBreak="break-word">
{selectedResource.account}::{selectedResource.group}
</Heading>
<Badge variant="primary" ml={2}>
{selectedResource.items.length}
</Badge>
<Copier
display={!isMobile ? "none" : "inline"}
type="resource"
value={`${selectedResource.account}::${selectedResource.group}`}
copyLabel="Copied!"
jennieramida marked this conversation as resolved.
Show resolved Hide resolved
/>
</Flex>
<Button
variant="outline-primary"
Expand Down
Loading