Skip to content

Commit

Permalink
feat: minor tuning in ui
Browse files Browse the repository at this point in the history
  • Loading branch information
hartym committed Mar 21, 2024
1 parent 837c361 commit f8ad886
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 41 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ frontend:
# QA, tests and other CI/CD related stuff
########################################################################################################################

.PHONY: clean preqa qa qa-full types format format-backend format-frontend test test-backend coverage test-frontend lint-frontend test-ui test-ui-update test-ui-build
.PHONY: clean preqa qa qa-full types format format-backend format-frontend test test-backend coverage test-frontend test-frontend-update lint-frontend test-ui test-ui-update test-ui-build

clean:
(cd docs; $(MAKE) clean)
Expand Down Expand Up @@ -101,6 +101,9 @@ coverage:
test-frontend: install-frontend lint-frontend
cd frontend; pnpm test

test-frontend-update: install-frontend lint-frontend
cd frontend; pnpm test:unit:update

lint-frontend: install-frontend
cd frontend; pnpm build

Expand Down
11 changes: 7 additions & 4 deletions frontend/src/Components/Page/Page.test.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import { render, screen } from "@testing-library/react"
import { ErrorBoundary } from "react-error-boundary"
import { describe, test, expect, vi, afterEach } from "vitest"
import { afterEach, describe, expect, test, vi } from "vitest"

import { Page, Error as ErrorFunc } from "./Page"
import { Error as ErrorFunc, Page } from "./Page"
import { PageTitle } from "./PageTitle.tsx"

describe("Page", () => {
afterEach(() => {
vi.restoreAllMocks()
})

test("renders without error", () => {
const { container } = render(<Page children={<div />} title="Test Title" description="Test Description" />)
const { container } = render(
<Page children={<div />} title={<PageTitle title="Test Title" description="Test Description" />} />,
)
expect(container).toMatchSnapshot()
})

test("renders title and description", () => {
render(<Page children={<div />} title="Test Title" description="Test Description" />)
render(<Page children={<div />} title={<PageTitle title="Test Title" description="Test Description" />} />)
expect(screen.getByText("Test Title")).toBeInTheDocument()
expect(screen.getByText("Test Description")).toBeInTheDocument()
})
Expand Down
17 changes: 7 additions & 10 deletions frontend/src/Components/Page/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import * as Sentry from "@sentry/browser"
import { ReactNode } from "react"
import { ErrorBoundary, FallbackProps } from "react-error-boundary"

import { H1, P } from "mkui/Components/Typography"

export function Error(props: FallbackProps) {
return (
<div>
Expand Down Expand Up @@ -43,17 +41,16 @@ export function Error(props: FallbackProps) {
)
}

export function Page({ children, title, description }: { children: ReactNode; title?: string; description?: string }) {
interface PageProps {
children: ReactNode
title?: ReactNode
}

export function Page({ children, title }: PageProps) {
return (
<ErrorBoundary FallbackComponent={Error}>
<main>
{title ? (
<div className="mt-4 mb-4">
<H1>{title}</H1>
{description ? <P>{description}</P> : null}
</div>
) : null}

{title ?? null}
<div className="mt-4">
<div className="sm:-mx-6 lg:-mx-8">
<section className="inline-block min-w-full max-w-full py-2 align-middle sm:px-6 lg:px-8">
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/Components/Page/PageTitle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { H1, P } from "mkui/Components/Typography"

export function PageTitle({ description, title }: { title?: string; description?: string }) {
return (
<>
{title ? (
<div className="mt-4 mb-4">
<H1>{title}</H1>
{description ? <P>{description}</P> : null}
</div>
) : null}
</>
)
}
1 change: 1 addition & 0 deletions frontend/src/Components/Page/index.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { Page } from "./Page"
export { PageTitle } from "./PageTitle"
export { Error } from "./Page"
4 changes: 2 additions & 2 deletions frontend/src/Pages/Overview/OverviewPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from "react"

import { Page } from "Components/Page"
import { Page, PageTitle } from "Components/Page"
import { OnQuerySuccess } from "Components/Utilities/OnQuerySuccess"
import { useSystemSettingsQuery } from "Domain/System"
import { ButtonGroup } from "mkui/Components/ButtonGroup"
Expand Down Expand Up @@ -28,7 +28,7 @@ export const OverviewPage = () => {
]

return (
<Page title="Overview" description="Useful insights">
<Page title={<PageTitle title="Overview" />}>
<div className="flex justify-end my-2">
<ButtonGroup buttonProps={buttonProps} current={timeRange} setCurrent={setCurrentTimeRange} />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ exports[`renders the title and data when the query is successful 1`] = `
>
Overview
</h1>
<p
class="css-11bp3eh"
>
Useful insights
</p>
</div>
<div
class="mt-4"
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/Pages/System/SystemPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Page } from "Components/Page"
import { Page, PageTitle } from "Components/Page"
import { Tab } from "mkui/Components/Tabs"

import { SystemDependenciesTabPanel } from "./SystemDependenciesTabPanel.tsx"
Expand All @@ -7,7 +7,7 @@ import { SystemTopologyTabPanel } from "./SystemTopologyTabPanel.tsx"

export const SystemPage = () => {
return (
<Page title="System" description="Informations about the running instance.">
<Page title={<PageTitle title="System" description="Informations about the running instance." />}>
<Tab.Group>
<Tab.List as="nav" aria-label="Tabs">
<Tab>Topology</Tab>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ export function FiltersSidebar({ filters, setFilters }: FiltersSidebarProps) {
const setFlagsFilter = _createSetFilterFor("flag")

return (
<Pane
as="aside"
hasDefaultPadding={false}
className="divide-y divide-gray-100 overflow-hidden text-gray-900 sm:text-sm"
>
<Pane hasDefaultPadding={false} className="divide-y divide-gray-100 overflow-hidden text-gray-900 sm:text-sm">
{/* TODO implement search
<input className="h-12 w-full border-0 bg-transparent px-4 focus:ring-0" placeholder="Search..." />
*/}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`renders the title and data when the query is successful 1`] = `
<div>
<aside
<div
class="divide-y divide-gray-100 overflow-hidden text-gray-900 sm:text-sm css-o0j4j7"
>
<div
Expand Down Expand Up @@ -583,6 +583,6 @@ exports[`renders the title and data when the query is successful 1`] = `
</div>
</fieldset>
</div>
</aside>
</div>
</div>
`;
29 changes: 25 additions & 4 deletions frontend/src/Pages/Transactions/TransactionListPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { ChevronDoubleLeftIcon, ChevronDoubleRightIcon } from "@heroicons/react/16/solid"
import { useEffect, useState } from "react"
import { QueryObserverSuccessResult } from "react-query/types/core/types"

import { Page } from "Components/Page"
import { PageTitle } from "Components/Page/PageTitle.tsx"
import { OnQuerySuccess } from "Components/Utilities/OnQuerySuccess"
import { ItemList } from "Domain/Api/Types"
import { useTransactionsDetailQuery, useTransactionsListQuery } from "Domain/Transactions"
Expand All @@ -28,6 +30,9 @@ function TransactionListPageOnQuerySuccess({
}) {
const [selected, setSelected] = useState<Transaction | null>(null)
const hasSelection = selected && selected.id

const [isFiltersOpen, setIsFiltersOpen] = useState(true)

const detailQuery = useTransactionsDetailQuery(selected?.id)
const paginatorProps = {
current: page,
Expand All @@ -38,9 +43,23 @@ function TransactionListPageOnQuerySuccess({
}
return (
<div className="flex w-full items-start gap-x-8 relative">
<aside className="sticky top-8 hidden w-1/5 min-w-56 max-w-96 shrink-0 lg:block">
<FiltersSidebar filters={filters} setFilters={setFilters} />
</aside>
{isFiltersOpen ? (
<aside className="sticky top-8 hidden w-1/5 min-w-56 max-w-96 shrink-0 lg:block">
<div className="text-right">
<button onClick={() => setIsFiltersOpen(false)} className="text-gray-400 mx-1 font-medium text-xs">
<ChevronDoubleLeftIcon className="h-3 w-3 inline-block" /> hide
</button>
</div>
<FiltersSidebar filters={filters} setFilters={setFilters} />
</aside>
) : (
<button onClick={() => setIsFiltersOpen(true)} className="text-gray-400 mx-1 font-medium text-xs">
<ChevronDoubleRightIcon className="h-3 w-3 inline-block" />
<div className="w-4">
<div className="rotate-90">filters</div>
</div>
</button>
)}

<main className="flex-1 overflow-auto">
<TransactionDataTable
Expand Down Expand Up @@ -85,7 +104,7 @@ export function TransactionListPage() {
}, [page, query])

return (
<Page title="Transactions" description="Explore transactions that went through the proxy">
<Page title={<PageTitle title="Transactions" />}>
<OnQuerySuccess query={query}>
{(query) => (
<TransactionListPageOnQuerySuccess
Expand All @@ -100,3 +119,5 @@ export function TransactionListPage() {
</Page>
)
}

//title="Transactions" description="Explore transactions that went through the proxy"
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ exports[`renders well when the query is successful 1`] = `
>
Transactions
</h1>
<p
class="css-11bp3eh"
>
Explore transactions that went through the proxy
</p>
</div>
<div
class="mt-4"
Expand All @@ -32,7 +27,30 @@ exports[`renders well when the query is successful 1`] = `
<aside
class="sticky top-8 hidden w-1/5 min-w-56 max-w-96 shrink-0 lg:block"
>
<aside
<div
class="text-right"
>
<button
class="text-gray-400 mx-1 font-medium text-xs"
>
<svg
aria-hidden="true"
class="h-3 w-3 inline-block"
data-slot="icon"
fill="currentColor"
viewBox="0 0 16 16"
xmlns="http://www.w3.org/2000/svg"
>
<path
clip-rule="evenodd"
d="M3.22 7.595a.75.75 0 0 0 0 1.06l3.25 3.25a.75.75 0 0 0 1.06-1.06l-2.72-2.72 2.72-2.72a.75.75 0 0 0-1.06-1.06l-3.25 3.25Zm8.25-3.25-3.25 3.25a.75.75 0 0 0 0 1.06l3.25 3.25a.75.75 0 1 0 1.06-1.06l-2.72-2.72 2.72-2.72a.75.75 0 0 0-1.06-1.06Z"
fill-rule="evenodd"
/>
</svg>
hide
</button>
</div>
<div
class="divide-y divide-gray-100 overflow-hidden text-gray-900 sm:text-sm css-o0j4j7"
/>
</aside>
Expand Down

0 comments on commit f8ad886

Please sign in to comment.