Skip to content

Commit

Permalink
Feat: Application summary page access (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
brunomenezes authored May 6, 2024
1 parent b90c729 commit 3e27275
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 67 deletions.
77 changes: 46 additions & 31 deletions apps/web/src/components/applications/applicationRow.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { ActionIcon, Table, Tooltip } from "@mantine/core";
import { ActionIcon, Group, Table, Tooltip } from "@mantine/core";
import Link from "next/link";
import { FC } from "react";
import { TbInbox, TbPlugConnected, TbPlugConnectedX } from "react-icons/tb";
import {
TbInbox,
TbPlugConnected,
TbPlugConnectedX,
TbStack2,
} from "react-icons/tb";
import { Address as AddressType } from "viem";
import { Application } from "../../graphql/explorer/types";
import { useConnectionConfig } from "../../providers/connectionConfig/hooks";
Expand Down Expand Up @@ -40,39 +45,49 @@ const ApplicationRow: FC<ApplicationRowProps> = (props) => {
</Table.Td>
<Table.Td>{connection?.url ?? "N/A"}</Table.Td>
<Table.Td>
<Tooltip label="Inputs">
<Link
href={`/applications/${appId}/inputs`}
data-testid="applications-link"
>
<ActionIcon variant="default">
<TbInbox />
</ActionIcon>
</Link>
</Tooltip>
{hasConnection(appId) ? (
<Tooltip label="Remove connection">
<ActionIcon
data-testid="remove-connection"
variant="default"
ml={4}
onClick={() => removeConnection(appId)}
<Group gap="xs">
<Tooltip label="Summary">
<Link
href={`/applications/${appId}`}
data-testid="applications-summary-link"
>
<TbPlugConnectedX />
</ActionIcon>
<ActionIcon variant="default">
<TbStack2 />
</ActionIcon>
</Link>
</Tooltip>
) : (
<Tooltip label="Add a connection">
<ActionIcon
data-testid="add-connection"
variant="default"
ml={4}
onClick={() => showConnectionModal(appId)}
<Tooltip label="Inputs">
<Link
href={`/applications/${appId}/inputs`}
data-testid="applications-link"
>
<TbPlugConnected />
</ActionIcon>
<ActionIcon variant="default">
<TbInbox />
</ActionIcon>
</Link>
</Tooltip>
)}
{hasConnection(appId) ? (
<Tooltip label="Remove connection">
<ActionIcon
data-testid="remove-connection"
variant="default"
onClick={() => removeConnection(appId)}
>
<TbPlugConnectedX />
</ActionIcon>
</Tooltip>
) : (
<Tooltip label="Add a connection">
<ActionIcon
data-testid="add-connection"
variant="default"
onClick={() => showConnectionModal(appId)}
>
<TbPlugConnected />
</ActionIcon>
</Tooltip>
)}
</Group>
</Table.Td>
</Table.Tr>
);
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/applications/applications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const AllApplications: FC = () => {

export const Applications = () => {
return (
<Tabs defaultValue="all-apps">
<Tabs defaultValue="all-apps" keepMounted={false}>
<Tabs.List>
<Tabs.Tab value="all-apps">All Apps</Tabs.Tab>
<Tabs.Tab value="my-apps">My Apps</Tabs.Tab>
Expand Down
79 changes: 48 additions & 31 deletions apps/web/src/components/applications/userApplicationsRow.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { ActionIcon, Box, Table, Text, Tooltip } from "@mantine/core";
import { ActionIcon, Box, Group, Table, Text, Tooltip } from "@mantine/core";
import Link from "next/link";
import prettyMilliseconds from "pretty-ms";
import { FC } from "react";
import { TbInbox, TbPlugConnected, TbPlugConnectedX } from "react-icons/tb";
import {
TbInbox,
TbPlugConnected,
TbPlugConnectedX,
TbStack2,
} from "react-icons/tb";
import { Address as AddressType } from "viem";
import { useConnectionConfig } from "../../providers/connectionConfig/hooks";
import Address from "../address";
Expand Down Expand Up @@ -41,39 +46,51 @@ const UserApplicationsRow: FC<ApplicationRowProps> = (props) => {
</Box>
</Table.Td>
<Table.Td>
<Tooltip label="Inputs">
<Link
href={`/applications/${appId}/inputs`}
data-testid="applications-link"
>
<ActionIcon variant="default">
<TbInbox />
</ActionIcon>
</Link>
</Tooltip>
{hasConnection(appId) ? (
<Tooltip label="Remove connection">
<ActionIcon
data-testid="remove-connection"
variant="default"
ml={4}
onClick={() => removeConnection(appId)}
<Group gap="xs">
<Tooltip label="Summary">
<Link
href={`/applications/${appId}`}
data-testid="applications-summary-link"
>
<TbPlugConnectedX />
</ActionIcon>
<ActionIcon variant="default">
<TbStack2 />
</ActionIcon>
</Link>
</Tooltip>
) : (
<Tooltip label="Add a connection">
<ActionIcon
data-testid="add-connection"
variant="default"
ml={4}
onClick={() => showConnectionModal(appId)}
<Tooltip label="Inputs">
<Link
href={`/applications/${appId}/inputs`}
data-testid="applications-link"
>
<TbPlugConnected />
</ActionIcon>
<ActionIcon variant="default">
<TbInbox />
</ActionIcon>
</Link>
</Tooltip>
)}
{hasConnection(appId) ? (
<Tooltip label="Remove connection">
<ActionIcon
data-testid="remove-connection"
variant="default"
ml={4}
onClick={() => removeConnection(appId)}
>
<TbPlugConnectedX />
</ActionIcon>
</Tooltip>
) : (
<Tooltip label="Add a connection">
<ActionIcon
data-testid="add-connection"
variant="default"
ml={4}
onClick={() => showConnectionModal(appId)}
>
<TbPlugConnected />
</ActionIcon>
</Tooltip>
)}
</Group>
</Table.Td>
</Table.Tr>
);
Expand Down
18 changes: 14 additions & 4 deletions apps/web/test/components/applications/applicationRow.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { afterEach, beforeEach, describe, it } from "vitest";
import type { FC } from "react";
import { Table } from "@mantine/core";
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
import type { FC } from "react";
import { afterEach, beforeEach, describe, it } from "vitest";
import ApplicationRow, {
ApplicationRowProps,
} from "../../../src/components/applications/applicationRow";
import { withMantineTheme } from "../../utils/WithMantineTheme";
import { Table } from "@mantine/core";
import { useConnectionConfig } from "../../../src/providers/connectionConfig/hooks";
import { withMantineTheme } from "../../utils/WithMantineTheme";

vi.mock("../../../src/providers/connectionConfig/hooks");
const useConnectionConfigMock = vi.mocked(useConnectionConfig, true);
Expand Down Expand Up @@ -111,6 +111,16 @@ describe("ApplicationRow component", () => {
expect(screen.getByText(defaultConnection.url)).toBeInTheDocument();
});

it("should display link to the application summary page", () => {
render(<Component {...defaultProps} />);
const link = screen.getByTestId("applications-summary-link");

expect(link).toBeInTheDocument();
expect(link.getAttribute("href")).toBe(
`/applications/${defaultProps.application.id}`,
);
});

it("should display link to application inputs page", () => {
render(<Component {...defaultProps} />);
const link = screen.getByTestId("applications-link");
Expand Down
10 changes: 10 additions & 0 deletions apps/web/test/components/applications/userApplicationRow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ describe("ApplicationRow component", () => {
expect(screen.getByText(defaultConnection.url)).toBeInTheDocument();
});

it("should display link to application summary page", () => {
render(<Component {...defaultProps} />);
const link = screen.getByTestId("applications-summary-link");

expect(link).toBeInTheDocument();
expect(link.getAttribute("href")).toBe(
`/applications/${defaultProps.application.id}`,
);
});

it("should display link to application inputs page", () => {
render(<Component {...defaultProps} />);
const link = screen.getByTestId("applications-link");
Expand Down

0 comments on commit 3e27275

Please sign in to comment.