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): add expand collapse all to proposal message accordion #776

Merged
merged 6 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Improvements

- [#776](https://github.com/alleslabs/celatone-frontend/pull/776) Add expand/collapse all to proposal messages in detail page
- [#771](https://github.com/alleslabs/celatone-frontend/pull/771) Adjust proposal detail
jennieramida marked this conversation as resolved.
Show resolved Hide resolved
- [#772](https://github.com/alleslabs/celatone-frontend/pull/772) Add zod validator to code details page code id params
- [#770](https://github.com/alleslabs/celatone-frontend/pull/770) Add unit test for account store (mobx)
- [#769](https://github.com/alleslabs/celatone-frontend/pull/769) Add unit test for format.test.ts on shortenName function
Expand Down
1 change: 1 addition & 0 deletions src/lib/amplitude/track-event/trackInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const trackUseExpand = ({
| "module_interaction_function_accordion"
| "module_interaction_selected_function_card"
| "pool_tx_msg"
| "proposal_message_card"
| "resources_detail_card"
| "resources_by_account_card";
info?: object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const ResourceSectionBody = ({
const selectedResource = resourcesByOwner
?.find((resource) => resource.owner === selectedAccountParam)
?.resources?.find((resource) => resource.group === selectedNameParam);

useEffect(() => {
setExpandedIndexes(selectedResource?.items.length === 1 ? [0] : []);
}, [resourcesByOwner, selectedResource]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import {
AccordionButton,
AccordionIcon,
AccordionItem,
AccordionPanel,
Flex,
Text,
} from "@chakra-ui/react";

import { trackUseExpand } from "lib/amplitude";
import JsonReadOnly from "lib/components/json/JsonReadOnly";

interface ProposalMessageCardProps {
header: string;
jsonString: string;
}

export const ProposalMessageCard = ({
header,
jsonString,
}: ProposalMessageCardProps) => {
return (
jennieramida marked this conversation as resolved.
Show resolved Hide resolved
<AccordionItem mb={4}>
{({ isExpanded }) => (
<>
<AccordionButton
background="gray.900"
borderRadius={8}
_hover={{ background: "gray.900" }}
onClick={() =>
trackUseExpand({
action: !isExpanded ? "expand" : "collapse",
component: "proposal_message_card",
section: "proposal message",
})
}
>
<Flex
px={4}
justifyContent="space-between"
w="full"
align="center"
className="copier-wrapper"
>
<Flex alignItems="center">
<Text variant="body1" fontWeight={600} wordBreak="break-word">
{header}
</Text>
</Flex>
<Flex alignItems="center" gap={2}>
<AccordionIcon color="gray.600" />
</Flex>
</Flex>
</AccordionButton>
<AccordionPanel p={0} pt={4}>
<div
style={
isExpanded
? { display: "block" }
: { height: 0, display: "none" }
}
>
jennieramida marked this conversation as resolved.
Show resolved Hide resolved
<JsonReadOnly text={jsonString} canCopy isExpandable />
</div>
</AccordionPanel>
</>
)}
</AccordionItem>
);
};
Original file line number Diff line number Diff line change
@@ -1,39 +1,73 @@
import { Flex, Heading, Text } from "@chakra-ui/react";
import { Accordion, Button, Flex, Heading } from "@chakra-ui/react";
import { useEffect, useState } from "react";

import { JsonInfo } from "lib/components/json/JsonInfo";
import { trackUseExpandAll } from "lib/amplitude";
import { CustomIcon } from "lib/components/icon";
import type { ProposalData } from "lib/types";
import { jsonPrettify } from "lib/utils";

import { ProposalMessageCard } from "./ProposalMessageCard";

interface ProposalMessagesProps {
messages: ProposalData["messages"];
}
export const ProposalMessages = ({ messages }: ProposalMessagesProps) => {
const [expandedIndexes, setExpandedIndexes] = useState<number[]>([]);

useEffect(() => {
setExpandedIndexes(messages?.length === 1 ? [0] : []);
}, [messages]);

export const ProposalMessages = ({ messages }: ProposalMessagesProps) => (
<Flex
direction="column"
gap={4}
pt={8}
borderTop="1px solid"
borderColor="gray.700"
>
<Heading as="h6" variant="h6">
Proposal Messages
</Heading>
{messages?.length ? (
<>
{messages.map((item, i) => (
<JsonInfo
return (
<Flex
direction="column"
gap={4}
pt={8}
borderTop="1px solid"
borderColor="gray.700"
>
<Flex w="full" alignItems="center" justifyContent="space-between">
<Heading as="h6" variant="h6">
Proposal Messages
</Heading>
<Button
variant="ghost-primary"
minW={{ base: "auto", md: 32 }}
size="sm"
rightIcon={
<CustomIcon
name={expandedIndexes.length ? "chevron-up" : "chevron-down"}
boxSize={3}
/>
}
onClick={() => {
trackUseExpandAll(
expandedIndexes.length ? "collapse" : "expand",
"account detail resources Tab"
);
jennieramida marked this conversation as resolved.
Show resolved Hide resolved
setExpandedIndexes((prev) =>
!prev.length ? Array.from(Array(messages?.length).keys()) : []
);
}}
>
{expandedIndexes.length ? "Collapse All" : "Expand All"}
</Button>
</Flex>
<Accordion
allowMultiple
width="full"
variant="transparent"
index={expandedIndexes}
onChange={(indexes: number[]) => setExpandedIndexes(indexes)}
>
{messages?.map((item, i) => (
<ProposalMessageCard
key={`msg-${item}`}
header={`[${i}] ${item["@type"]}`}
jennieramida marked this conversation as resolved.
Show resolved Hide resolved
jsonString={jsonPrettify(JSON.stringify(item))}
defaultExpand={messages?.length === 1}
key={`msg-${item}`}
/>
))}
</>
) : (
<Text variant="body1" color="text.dark">
No Messages
</Text>
)}
</Flex>
);
</Accordion>
</Flex>
);
};
1 change: 1 addition & 0 deletions src/lib/styles/theme/components/accordion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const gray900 = definePartsStyle({
borderRadius: "0px 8px 8px 0px",
},
});

const transparent = definePartsStyle({
container: {
bg: "transparent",
Expand Down
Loading