Skip to content

Commit

Permalink
Layout updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecao committed Oct 3, 2023
1 parent e4c5f42 commit 476dd52
Show file tree
Hide file tree
Showing 23 changed files with 97 additions and 86 deletions.
2 changes: 1 addition & 1 deletion src/app/(app)/settings/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { usePathname } from 'next/navigation';
import useUser from 'components/hooks/useUser';
import useMessages from 'components/hooks/useMessages';
import SideNav from './SideNav';
import SideNav from 'components/layout/SideNav';
import styles from './layout.module.css';

export default function SettingsLayout({ children }) {
Expand Down
4 changes: 2 additions & 2 deletions src/app/(app)/websites/[id]/WebsiteChart.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMemo } from 'react';
import PageviewsChart from 'components/metrics/PageviewsChart';
import { useApi, useDateRange, useTimezone, usePageQuery } from 'components/hooks';
import { useApi, useDateRange, useTimezone, useNavigation } from 'components/hooks';
import { getDateArray } from 'lib/date';

export function WebsiteChart({ websiteId }) {
Expand All @@ -9,7 +9,7 @@ export function WebsiteChart({ websiteId }) {
const [timezone] = useTimezone();
const {
query: { url, referrer, os, browser, device, country, region, city, title },
} = usePageQuery();
} = useNavigation();
const { get, useQuery } = useApi();

const { data, isLoading } = useQuery(
Expand Down
4 changes: 2 additions & 2 deletions src/app/(app)/websites/[id]/WebsiteDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Loading } from 'react-basics';
import { usePathname } from 'next/navigation';
import Page from 'components/layout/Page';
import FilterTags from 'components/metrics/FilterTags';
import usePageQuery from 'components/hooks/usePageQuery';
import useNavigation from 'components/hooks/useNavigation';
import { useWebsite } from 'components/hooks';
import WebsiteChart from './WebsiteChart';
import WebsiteMenuView from './WebsiteMenuView';
Expand All @@ -18,7 +18,7 @@ export default function WebsiteDetails({ websiteId }) {

const {
query: { view, url, referrer, os, browser, device, country, region, city, title },
} = usePageQuery();
} = useNavigation();

if (isLoading || error) {
return <Page isLoading={isLoading} error={error} />;
Expand Down
66 changes: 28 additions & 38 deletions src/app/(app)/websites/[id]/WebsiteMenuView.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Icon, Button, Flexbox, Text } from 'react-basics';
import Link from 'next/link';
import { GridRow, GridColumn } from 'components/layout/Grid';
import { Text } from 'react-basics';
import BrowsersTable from 'components/metrics/BrowsersTable';
import CountriesTable from 'components/metrics/CountriesTable';
import RegionsTable from 'components/metrics/RegionsTable';
Expand All @@ -13,12 +11,11 @@ import QueryParametersTable from 'components/metrics/QueryParametersTable';
import ReferrersTable from 'components/metrics/ReferrersTable';
import ScreenTable from 'components/metrics/ScreenTable';
import EventsTable from 'components/metrics/EventsTable';
import Icons from 'components/icons';
import SideNav from '../../settings/SideNav';
import usePageQuery from 'components/hooks/usePageQuery';
import SideNav from 'components/layout/SideNav';
import useNavigation from 'components/hooks/useNavigation';
import useMessages from 'components/hooks/useMessages';
import styles from './WebsiteMenuView.module.css';
import useLocale from 'components/hooks/useLocale';
import LinkButton from 'components/common/LinkButton';

const views = {
url: PagesTable,
Expand All @@ -38,93 +35,86 @@ const views = {

export default function WebsiteMenuView({ websiteId, websiteDomain }) {
const { formatMessage, labels } = useMessages();
const { dir } = useLocale();
const {
resolveUrl,
makeUrl,
pathname,
query: { view },
} = usePageQuery();
} = useNavigation();

const items = [
{
key: 'url',
label: formatMessage(labels.pages),
url: resolveUrl({ view: 'url' }),
url: makeUrl({ view: 'url' }),
},
{
key: 'referrer',
label: formatMessage(labels.referrers),
url: resolveUrl({ view: 'referrer' }),
url: makeUrl({ view: 'referrer' }),
},
{
key: 'browser',
label: formatMessage(labels.browsers),
url: resolveUrl({ view: 'browser' }),
url: makeUrl({ view: 'browser' }),
},
{
key: 'os',
label: formatMessage(labels.os),
url: resolveUrl({ view: 'os' }),
url: makeUrl({ view: 'os' }),
},
{
key: 'device',
label: formatMessage(labels.devices),
url: resolveUrl({ view: 'device' }),
url: makeUrl({ view: 'device' }),
},
{
key: 'country',
label: formatMessage(labels.countries),
url: resolveUrl({ view: 'country' }),
url: makeUrl({ view: 'country' }),
},
{
key: 'region',
label: formatMessage(labels.regions),
url: resolveUrl({ view: 'region' }),
url: makeUrl({ view: 'region' }),
},
{
key: 'city',
label: formatMessage(labels.cities),
url: resolveUrl({ view: 'city' }),
url: makeUrl({ view: 'city' }),
},
{
key: 'language',
label: formatMessage(labels.languages),
url: resolveUrl({ view: 'language' }),
url: makeUrl({ view: 'language' }),
},
{
key: 'screen',
label: formatMessage(labels.screens),
url: resolveUrl({ view: 'screen' }),
url: makeUrl({ view: 'screen' }),
},
{
key: 'event',
label: formatMessage(labels.events),
url: resolveUrl({ view: 'event' }),
url: makeUrl({ view: 'event' }),
},
{
key: 'query',
label: formatMessage(labels.queryParameters),
url: resolveUrl({ view: 'query' }),
url: makeUrl({ view: 'query' }),
},
];

const DetailsComponent = views[view] || (() => null);

return (
<GridRow>
<GridColumn xs={12} sm={12} md={12} defaultSize={3} className={styles.menu}>
<Link href={resolveUrl({ view: undefined })}>
<Flexbox justifyContent="center">
<Button variant="quiet">
<Icon rotate={dir === 'rtl' ? 0 : 180}>
<Icons.ArrowRight />
</Icon>
<Text>{formatMessage(labels.back)}</Text>
</Button>
</Flexbox>
</Link>
<div className={styles.layout}>
<div className={styles.menu}>
<LinkButton href={pathname} className={styles.back}>
<Text>{formatMessage(labels.back)}</Text>
</LinkButton>
<SideNav items={items} selectedKey={view} shallow={true} />
</GridColumn>
<GridColumn xs={12} sm={12} md={12} defaultSize={9} className={styles.content}>
</div>
<div className={styles.content}>
<DetailsComponent
websiteId={websiteId}
websiteDomain={websiteDomain}
Expand All @@ -133,7 +123,7 @@ export default function WebsiteMenuView({ websiteId, websiteDomain }) {
showFilters={true}
virtualize={true}
/>
</GridColumn>
</GridRow>
</div>
</div>
);
}
18 changes: 18 additions & 0 deletions src/app/(app)/websites/[id]/WebsiteMenuView.module.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
.layout {
display: grid;
grid-template-columns: 300px 1fr;
border-top: 1px solid var(--base300);
}

.menu {
display: flex;
flex-direction: column;
position: relative;
padding: 20px 20px 20px 0;
}

.back {
display: inline-flex;
align-items: center;
align-self: center;
margin-bottom: 20px;
}

.content {
min-height: 800px;
padding: 20px 0 20px 20px;
border-left: 1px solid var(--base300);
}
8 changes: 4 additions & 4 deletions src/app/(app)/websites/[id]/WebsiteMetricsBar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import classNames from 'classnames';
import { useApi, useDateRange, useMessages, usePageQuery, useSticky } from 'components/hooks';
import { useApi, useDateRange, useMessages, useNavigation, useSticky } from 'components/hooks';
import WebsiteDateFilter from 'components/input/WebsiteDateFilter';
import MetricCard from 'components/metrics/MetricCard';
import MetricsBar from 'components/metrics/MetricsBar';
Expand All @@ -17,10 +17,10 @@ export function WebsiteMetricsBar({ websiteId, showFilter = true, sticky }) {
const { startDate, endDate, modified } = dateRange;
const { ref, isSticky } = useSticky({ enabled: sticky });
const {
resolveUrl,
makeUrl,
router,
query: { url, referrer, title, os, browser, device, country, region, city },
} = usePageQuery();
} = useNavigation();

const { data, error, isLoading, isFetched } = useQuery(
[
Expand Down Expand Up @@ -64,7 +64,7 @@ export function WebsiteMetricsBar({ websiteId, showFilter = true, sticky }) {
};

const handleAddFilter = ({ name, value }) => {
router.push(resolveUrl({ [name]: value }));
router.push(makeUrl({ [name]: value }));
};

const WebsiteFilterButton = () => {
Expand Down
6 changes: 3 additions & 3 deletions src/app/(app)/websites/[id]/event-data/EventDataTable.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Link from 'next/link';
import { GridTable, GridColumn } from 'react-basics';
import { useMessages, usePageQuery } from 'components/hooks';
import { useMessages, useNavigation } from 'components/hooks';
import Empty from 'components/common/Empty';
import { DATA_TYPES } from 'lib/constants';

export function EventDataTable({ data = [] }) {
const { formatMessage, labels } = useMessages();
const { resolveUrl } = usePageQuery();
const { makeUrl } = useNavigation();

if (data.length === 0) {
return <Empty />;
Expand All @@ -16,7 +16,7 @@ export function EventDataTable({ data = [] }) {
<GridTable data={data}>
<GridColumn name="eventName" label={formatMessage(labels.event)}>
{row => (
<Link href={resolveUrl({ event: row.eventName })} shallow={true}>
<Link href={makeUrl({ event: row.eventName })} shallow={true}>
{row.eventName}
</Link>
)}
Expand Down
6 changes: 3 additions & 3 deletions src/app/(app)/websites/[id]/event-data/EventDataValueTable.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GridTable, GridColumn, Button, Icon, Text } from 'react-basics';
import { useMessages, usePageQuery } from 'components/hooks';
import { useMessages, useNavigation } from 'components/hooks';
import Link from 'next/link';
import Icons from 'components/icons';
import PageHeader from 'components/layout/PageHeader';
Expand All @@ -8,12 +8,12 @@ import { DATA_TYPES } from 'lib/constants';

export function EventDataValueTable({ data = [], event }) {
const { formatMessage, labels } = useMessages();
const { resolveUrl } = usePageQuery();
const { makeUrl } = useNavigation();

const Title = () => {
return (
<>
<Link href={resolveUrl({ event: undefined })}>
<Link href={makeUrl({ event: undefined })}>
<Button>
<Icon rotate={180}>
<Icons.ArrowRight />
Expand Down
4 changes: 2 additions & 2 deletions src/app/(app)/websites/[id]/event-data/WebsiteEventData.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Flexbox, Loading } from 'react-basics';
import EventDataTable from './EventDataTable';
import EventDataValueTable from './EventDataValueTable';
import { EventDataMetricsBar } from './EventDataMetricsBar';
import { useDateRange, useApi, usePageQuery } from 'components/hooks';
import { useDateRange, useApi, useNavigation } from 'components/hooks';
import styles from './WebsiteEventData.module.css';

function useData(websiteId, event) {
Expand All @@ -28,7 +28,7 @@ function useData(websiteId, event) {
export default function WebsiteEventData({ websiteId }) {
const {
query: { event },
} = usePageQuery();
} = useNavigation();
const { data, isLoading } = useData(websiteId, event);

return (
Expand Down
6 changes: 3 additions & 3 deletions src/components/common/FilterLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { Icon, Icons } from 'react-basics';
import classNames from 'classnames';
import Link from 'next/link';
import { safeDecodeURI } from 'next-basics';
import usePageQuery from 'components/hooks/usePageQuery';
import useNavigation from 'components/hooks/useNavigation';
import useMessages from 'components/hooks/useMessages';
import styles from './FilterLink.module.css';

export function FilterLink({ id, value, label, externalUrl, children, className }) {
const { formatMessage, labels } = useMessages();
const { resolveUrl, query } = usePageQuery();
const { makeUrl, query } = useNavigation();
const active = query[id] !== undefined;
const selected = query[id] === value;

Expand All @@ -22,7 +22,7 @@ export function FilterLink({ id, value, label, externalUrl, children, className
{children}
{!value && `(${label || formatMessage(labels.unknown)})`}
{value && (
<Link href={resolveUrl({ [id]: value })} className={styles.label} replace>
<Link href={makeUrl({ [id]: value })} className={styles.label} replace>
{safeDecodeURI(label || value)}
</Link>
)}
Expand Down
10 changes: 7 additions & 3 deletions src/components/common/LinkButton.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import classNames from 'classnames';
import Link from 'next/link';
import { Icon, Icons, Text } from 'react-basics';
import styles from './LinkButton.module.css';
import { useLocale } from 'components/hooks';

export function LinkButton({ href, icon, className, children }) {
const { dir } = useLocale();

export function LinkButton({ href, icon, children }) {
return (
<Link className={styles.button} href={href}>
<Icon>{icon || <Icons.ArrowRight />}</Icon>
<Link className={classNames(styles.button, className)} href={href}>
<Icon rotate={dir === 'rtl' ? 0 : 180}>{icon || <Icons.ArrowRight />}</Icon>
<Text>{children}</Text>
</Link>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export * from './useFormat';
export * from './useLanguageNames';
export * from './useLocale';
export * from './useMessages';
export * from './usePageQuery';
export * from './useNavigation';
export * from './useReport';
export * from './useReports';
export * from './useRequireLogin';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useMemo } from 'react';
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
import { buildUrl } from 'next-basics';

export function usePageQuery() {
export function useNavigation() {
const router = useRouter();
const pathname = usePathname();
const params = useSearchParams();
Expand All @@ -17,11 +17,11 @@ export function usePageQuery() {
return obj;
}, [params]);

function resolveUrl(params, reset) {
return buildUrl(pathname, { ...(reset ? {} : query) });
function makeUrl(params, reset) {
return reset ? pathname : buildUrl(pathname, { ...query, ...params });
}

return { pathname, query, resolveUrl, router };
return { pathname, query, router, makeUrl };
}

export default usePageQuery;
export default useNavigation;
2 changes: 1 addition & 1 deletion src/components/layout/Grid.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import classNames from 'classnames';
import styles from './Grid.module.css';
import { mapChildren } from 'react-basics';
import styles from './Grid.module.css';

export function Grid({ className, ...otherProps }) {
return <div {...otherProps} className={classNames(styles.grid, className)} />;
Expand Down
Loading

0 comments on commit 476dd52

Please sign in to comment.