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

feat: add amplitude to proposal list page and pagination #317

Merged
merged 5 commits into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
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 @@ -39,6 +39,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Features

- [#317](https://github.com/alleslabs/celatone-frontend/pull/317) Add amplitude for proposal list page and pagination

### Improvements

### Bug fixes
Expand Down
5 changes: 5 additions & 0 deletions src/lib/components/InputWithIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@ import type { InputProps } from "@chakra-ui/react";
import { Input, InputGroup, InputRightElement } from "@chakra-ui/react";
import type { ChangeEvent } from "react";

import { AmpTrackUseInput } from "lib/services/amplitude";

import { CustomIcon } from "./icon";

interface InputWithIconProps {
placeholder: string;
value: string;
onChange: (e: ChangeEvent<HTMLInputElement>) => void;
size?: InputProps["size"];
action?: string;
}

const InputWithIcon = ({
placeholder,
value,
size,
action,
onChange,
}: InputWithIconProps) => (
<InputGroup>
Expand All @@ -23,6 +27,7 @@ const InputWithIcon = ({
value={value}
onChange={onChange}
size={size}
onClick={action ? () => AmpTrackUseInput(action) : undefined}
/>
<InputRightElement h="56px" alignItems="center" mr="1">
<CustomIcon name="search" />
Expand Down
9 changes: 5 additions & 4 deletions src/lib/components/button/NewProposalButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { TooltipComponent } from "../TooltipComponent";
import { useCurrentNetwork, useInternalNavigate } from "lib/app-provider";
import { CustomIcon } from "lib/components/icon";
import { AmpEvent, AmpTrack } from "lib/services/amplitude";

const StyledMenuItem = chakra(MenuItem, {
baseStyle: {
Expand All @@ -24,6 +25,7 @@ export const NewProposalButton = () => {
return (
<Menu>
<MenuButton
onClick={() => AmpTrack(AmpEvent.USE_CREATE_NEW_PROPOSAL)}
variant="primary"
color="text.main"
as={Button}
Expand All @@ -32,17 +34,16 @@ export const NewProposalButton = () => {
Create New Proposal
</MenuButton>
<MenuList>
{/* <StyledMenuItem
<StyledMenuItem
icon={<CustomIcon name="code" />}
// TODO - Change navigation path
onClick={() => {
navigate({
pathname: "/proposal-storecode",
pathname: "/proposal/store-code",
});
}}
>
To Store Code
</StyledMenuItem> */}
</StyledMenuItem>
{/* <StyledMenuItem
icon={<CustomIcon name="contract-address" />}
onClick={() => {
Expand Down
3 changes: 3 additions & 0 deletions src/lib/components/pagination/Next.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Button } from "@chakra-ui/react";
import type { FC } from "react";
import { useContext } from "react";

import { AmpTrackPaginationNavigate } from "lib/services/amplitude";

import { PaginatorContext } from "./PaginatorProvider";

export const Next: FC<ButtonProps> = ({ children, ...buttonProps }) => {
Expand All @@ -13,6 +15,7 @@ export const Next: FC<ButtonProps> = ({ children, ...buttonProps }) => {
const isLast = pagesQuantity ? currentPage > pagesQuantity - 1 : true;

const handleNextClick = () => {
AmpTrackPaginationNavigate("next");
if (!isLast) changePage(currentPage + 1);
};

Expand Down
3 changes: 3 additions & 0 deletions src/lib/components/pagination/Previous.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Button } from "@chakra-ui/react";
import type { FC } from "react";
import { useContext } from "react";

import { AmpTrackPaginationNavigate } from "lib/services/amplitude";

import { PaginatorContext } from "./PaginatorProvider";

export const Previous: FC<ButtonProps> = ({ children, ...buttonProps }) => {
Expand All @@ -13,6 +15,7 @@ export const Previous: FC<ButtonProps> = ({ children, ...buttonProps }) => {
const isFirst = currentPage === 1;

const handlePreviousClick = () => {
AmpTrackPaginationNavigate("previous");
if (!isFirst) changePage(currentPage - 1);
};

Expand Down
2 changes: 2 additions & 0 deletions src/lib/components/pagination/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { ChangeEvent } from "react";
import { useEffect, useMemo } from "react";

import { CustomIcon } from "../icon";
import { AmpTrackPaginationPage } from "lib/services/amplitude";
import { scrollToComponent, scrollToTop, scrollYPosition } from "lib/utils";

import { Next } from "./Next";
Expand Down Expand Up @@ -31,6 +32,7 @@ export const Pagination = ({
}: PaginationProps) => {
useEffect(() => {
const windowPosition = scrollYPosition();
AmpTrackPaginationPage(pageSize, currentPage);
if (windowPosition) {
if (!scrollComponentId) {
scrollToTop();
Expand Down
9 changes: 8 additions & 1 deletion src/lib/components/table/proposals/Proposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ import { useGetAddressType } from "lib/app-provider";
import { ExplorerLink } from "lib/components/ExplorerLink";
import type { Addr, Option } from "lib/types";

export const Proposer = ({ proposer }: { proposer: Option<Addr> }) => {
export const Proposer = ({
proposer,
amptrackSection,
}: {
proposer: Option<Addr>;
amptrackSection?: string;
}) => {
const getAddressType = useGetAddressType();

return proposer ? (
<ExplorerLink
type={getAddressType(proposer)}
value={proposer}
showCopyOnHover
ampCopierSection={amptrackSection}
poomthiti marked this conversation as resolved.
Show resolved Hide resolved
/>
) : (
<Text color="text.dark">N/A</Text>
Expand Down
3 changes: 3 additions & 0 deletions src/lib/components/table/proposals/ResolvedHeight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ export const ResolvedHeight = ({
resolvedHeight,
isDepositFailed,
isDepositOrVoting,
amptrackSection,
}: {
resolvedHeight: ProposalsTableRowProps["proposal"]["resolvedHeight"];
isDepositFailed: boolean;
isDepositOrVoting: boolean;
amptrackSection?: string;
}) => {
if (isDepositOrVoting) return <Text color="text.dark">Pending</Text>;
if (!resolvedHeight || isDepositFailed)
Expand All @@ -21,6 +23,7 @@ export const ResolvedHeight = ({
type="block_height"
value={resolvedHeight.toString()}
showCopyOnHover
ampCopierSection={amptrackSection}
poomthiti marked this conversation as resolved.
Show resolved Hide resolved
/>
);
};
7 changes: 7 additions & 0 deletions src/lib/pages/proposals/components/ProposalStatusFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { DropdownContainer } from "lib/components/filter/FilterComponents";
import { FilterDropdownItem } from "lib/components/filter/FilterDropdownItem";
import { FilterInput } from "lib/components/filter/FilterInput";
import { StatusChip } from "lib/components/table/proposals/StatusChip";
import { AmpEvent, AmpTrackUseFilter } from "lib/services/amplitude";
import { ProposalStatus } from "lib/types";

export interface ProposalStatusFilterProps extends InputProps {
Expand Down Expand Up @@ -59,8 +60,14 @@ export const ProposalStatusFilter = forwardRef<
inputRef.current.value = "";
}
if (result.includes(option)) {
AmpTrackUseFilter(
AmpEvent.USE_FILTER_PROPOSALS_STATUS,
result,
"remove"
);
setResult((prevState) => prevState.filter((value) => value !== option));
} else {
AmpTrackUseFilter(AmpEvent.USE_FILTER_PROPOSALS_STATUS, result, "add");
setResult((prevState) => [...prevState, option]);
}
};
Expand Down
3 changes: 3 additions & 0 deletions src/lib/pages/proposals/components/ProposalTypeFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { DropdownContainer } from "lib/components/filter/FilterComponents";
import { FilterDropdownItem } from "lib/components/filter/FilterDropdownItem";
import { FilterInput } from "lib/components/filter/FilterInput";
import { CustomIcon } from "lib/components/icon";
import { AmpEvent, AmpTrackUseFilter } from "lib/services/amplitude";
import { useProposalTypes } from "lib/services/proposalService";
import type { ProposalType } from "lib/types";
import { ProposalTypeCosmos } from "lib/types";
Expand Down Expand Up @@ -75,8 +76,10 @@ export const ProposalTypeFilter = forwardRef<
inputRef.current.value = "";
}
if (result.includes(option)) {
AmpTrackUseFilter(AmpEvent.USE_FILTER_PROPOSALS_TYPE, result, "remove");
setResult((prevState) => prevState.filter((value) => value !== option));
} else {
AmpTrackUseFilter(AmpEvent.USE_FILTER_PROPOSALS_TYPE, result, "add");
setResult((prevState) => [...prevState, option]);
}
};
Expand Down
9 changes: 8 additions & 1 deletion src/lib/pages/proposals/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const Proposals = () => {
);

useEffect(() => {
if (router.isReady) AmpTrack(AmpEvent.TO_PROPOSALS);
if (router.isReady) AmpTrack(AmpEvent.TO_PROPOSAL_LIST);
}, [router.isReady]);

useEffect(() => {
Expand Down Expand Up @@ -99,6 +99,7 @@ const Proposals = () => {
onChange={(e) => setSearch(e.target.value)}
size="lg"
value={search}
action="proposal-list-search"
/>
<Tooltip
isDisabled={!!address}
Expand All @@ -122,8 +123,14 @@ const Proposals = () => {
disabled={!address}
onChange={(e) => {
if (e.target.checked && address) {
AmpTrack(AmpEvent.USE_FILTER_MY_PROPOSALS, {
toggle: "on",
});
setProposer(address as Addr);
} else {
AmpTrack(AmpEvent.USE_FILTER_MY_PROPOSALS, {
toggle: "off",
});
setProposer(undefined);
}
setIsSelected(e.target.checked);
Expand Down
33 changes: 23 additions & 10 deletions src/lib/pages/proposals/table/ProposalTableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Proposer } from "lib/components/table/proposals/Proposer";
import { ResolvedHeight } from "lib/components/table/proposals/ResolvedHeight";
import { StatusChip } from "lib/components/table/proposals/StatusChip";
import { VotingEndTime } from "lib/components/table/proposals/VotingEndTime";
import { AmpTrackMintscan } from "lib/services/amplitude";
import type { Proposal, Option } from "lib/types";
import { ProposalStatus } from "lib/types";

Expand Down Expand Up @@ -44,15 +45,22 @@ export const ProposalTableRow = ({
minW="min-content"
cursor={isDepositFailed ? "default" : "pointer"}
_hover={{ "> div": { bgColor: hoverBg } }}
onClick={() =>
!isDepositFailed &&
window.open(
`${getExplorerProposalUrl(
currentChainName
)}/${proposal.proposalId.toString()}`,
"_blank",
"noopener,noreferrer"
)
onClick={
!isDepositFailed
? () => {
AmpTrackMintscan("proposal-detail", {
type: proposal.type,
status: proposal.status,
});
window.open(
`${getExplorerProposalUrl(
currentChainName
)}/${proposal.proposalId.toString()}`,
"_blank",
"noopener,noreferrer"
);
}
: undefined
}
>
<TableRowFreeze left="0">
Expand All @@ -61,6 +69,7 @@ export const ProposalTableRow = ({
type="proposal_id"
value={proposal.proposalId.toString()}
showCopyOnHover
ampCopierSection="proposal-list"
/>
</TableRowFreeze>
<TableRowFreeze
Expand Down Expand Up @@ -89,10 +98,14 @@ export const ProposalTableRow = ({
resolvedHeight={proposal.resolvedHeight}
isDepositFailed={isDepositFailed}
isDepositOrVoting={isDepositOrVoting}
amptrackSection="proposal-list"
/>
</TableRow>
<TableRow>
<Proposer proposer={proposal.proposer} />
<Proposer
proposer={proposal.proposer}
amptrackSection="proposal-list"
/>
</TableRow>
</Grid>
);
Expand Down
40 changes: 35 additions & 5 deletions src/lib/services/amplitude.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { track } from "@amplitude/analytics-browser";

import type { AttachFundsType } from "lib/components/fund/types";
import type { Option } from "lib/types";
import type { Dict, Option } from "lib/types";

export enum AmpEvent {
INVALID_STATE = "To Invalid State",
Expand Down Expand Up @@ -35,7 +35,7 @@ export enum AmpEvent {
TO_DEPLOY = "To Deploy",
TO_UPLOAD = "To Upload",
TO_INSTANTIATE = "To Instantiate",
TO_PROPOSALS = "To Proposals",
TO_PROPOSAL_LIST = "To Proposal List",
TO_QUERY = "To Query",
TO_EXECUTE = "To Execute",
TO_MIGRATE = "To Migrate",
Expand Down Expand Up @@ -96,6 +96,13 @@ export enum AmpEvent {
USE_UNSUPPORTED_ASSETS = "Use Unsupported Assets",
USE_TX_MSG_EXPAND = "Use Transaction Message Expand",
USE_EXPAND = "Use General Expand",
USE_INPUT = "Use Input",
USE_FILTER_MY_PROPOSALS = "Use Filter My Proposals",
USE_FILTER_PROPOSALS_STATUS = "Use Filter Proposals Status",
USE_FILTER_PROPOSALS_TYPE = "Use Filter Proposals Types",
USE_PAGINATION_PAGE = "Use Pagination Page",
USE_PAGINATION_NAVIGATION = "Use Pagination Navigation",
USE_CREATE_NEW_PROPOSAL = "Use Create New Proposal",
// TX
TX_SUCCEED = "Tx Succeed",
TX_FAILED = "Tx Failed",
Expand Down Expand Up @@ -131,7 +138,12 @@ type SpecialAmpEvent =
| AmpEvent.USE_VIEW_JSON
| AmpEvent.USE_UNSUPPORTED_ASSETS
| AmpEvent.USE_COPIER
| AmpEvent.USE_EXPAND;
| AmpEvent.USE_EXPAND
| AmpEvent.USE_INPUT
| AmpEvent.USE_PAGINATION_PAGE
| AmpEvent.USE_PAGINATION_NAVIGATION
| AmpEvent.USE_FILTER_PROPOSALS_STATUS
| AmpEvent.USE_FILTER_PROPOSALS_TYPE;

export const AmpTrackInvalidState = (title: string) =>
track(AmpEvent.INVALID_STATE, { title });
Expand Down Expand Up @@ -174,8 +186,11 @@ export const AmpTrackUseRadio = (radio: string) =>
export const AmpTrackUseOtherModal = (title: string) =>
track(AmpEvent.USE_OTHER_MODAL, { title });

export const AmpTrackMintscan = (type: string) =>
track(AmpEvent.MINTSCAN, { type });
export const AmpTrackMintscan = (
type: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
properties?: Dict<string, any>
) => track(AmpEvent.MINTSCAN, { type, properties });

export const AmpTrackWebsite = (url: string) =>
track(AmpEvent.WEBSITE, { url });
Expand All @@ -199,3 +214,18 @@ export const AmpTrackExpand = (
component: "assets" | "json" | "permission_address" | "event_box",
section: Option<string>
) => track(AmpEvent.USE_EXPAND, { action, component, section });

export const AmpTrackUseInput = (action: string) =>
track(AmpEvent.USE_INPUT, { action });

export const AmpTrackUseFilter = (
ampEvent: AmpEvent,
filters: string[],
action: string
) => track(ampEvent, { action, filters });

export const AmpTrackPaginationPage = (pageSize: number, currentPage: number) =>
track(AmpEvent.USE_PAGINATION_PAGE, { pageSize, currentPage });

export const AmpTrackPaginationNavigate = (navigate: string) =>
track(AmpEvent.USE_PAGINATION_NAVIGATION, { navigate });
Loading