Added SideNav component.

This commit is contained in:
Mike Cao 2023-03-23 11:46:49 -07:00
parent 1666e5e3af
commit c2789d70bc
14 changed files with 115 additions and 39 deletions

View File

@ -9,8 +9,10 @@ import ProfileButton from 'components/input/ProfileButton';
import styles from './NavBar.module.css'; import styles from './NavBar.module.css';
import useConfig from 'hooks/useConfig'; import useConfig from 'hooks/useConfig';
import useMessages from 'hooks/useMessages'; import useMessages from 'hooks/useMessages';
import { useRouter } from 'next/router';
export default function NavBar() { export default function NavBar() {
const { pathname } = useRouter();
const { cloudMode } = useConfig(); const { cloudMode } = useConfig();
const { formatMessage, labels } = useMessages(); const { formatMessage, labels } = useMessages();
const [minimized, setMinimized] = useState(false); const [minimized, setMinimized] = useState(false);
@ -34,8 +36,11 @@ export default function NavBar() {
<div className={styles.links}> <div className={styles.links}>
{links.map(({ url, icon, label }) => { {links.map(({ url, icon, label }) => {
return ( return (
<Link key={url} href={url}> <Link
<Icon>{icon}</Icon> key={url}
href={url}
className={classNames({ [styles.selected]: pathname.startsWith(url) })}
>
<Text>{label}</Text> <Text>{label}</Text>
</Link> </Link>
); );

View File

@ -5,7 +5,7 @@
align-items: center; align-items: center;
height: 60px; height: 60px;
background: var(--base75); background: var(--base75);
border-bottom: 1px solid var(--base200); border-bottom: 2px solid var(--base300);
padding: 0 20px; padding: 0 20px;
} }
@ -23,7 +23,7 @@
.links { .links {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
gap: 20px; gap: 30px;
padding: 0 40px; padding: 0 40px;
flex: 1; flex: 1;
font-weight: 700; font-weight: 700;
@ -33,11 +33,19 @@
display: flex; display: flex;
align-items: center; align-items: center;
gap: 10px; gap: 10px;
color: var(--font-color100); line-height: 60px;
color: var(--font-color200);
border-bottom: 2px solid transparent;
} }
.links a:hover { .links a:hover {
color: var(--primary400); color: var(--font-color100);
border-bottom: 2px solid var(--primary400);
}
.links .selected {
color: var(--font-color100);
border-bottom: 2px solid var(--primary400);
} }
.actions { .actions {

View File

@ -0,0 +1,26 @@
import AppLayout from './AppLayout';
import styles from './SettingsLayout.module.css';
import useMessages from 'hooks/useMessages';
import SideNav from './SideNav';
export default function SettingsLayout({ children }) {
const { formatMessage, labels } = useMessages();
const items = [
{ label: formatMessage(labels.websites), url: '/settings/websites' },
{ label: formatMessage(labels.teams), url: '/settings/teams' },
{ label: formatMessage(labels.users), url: '/settings/users' },
{ label: formatMessage(labels.profile), url: '/settings/profile' },
];
return (
<AppLayout>
<div className={styles.container}>
<div className={styles.menu}>
<SideNav items={items} />
</div>
<div className={styles.content}>{children}</div>
</div>
</AppLayout>
);
}

View File

@ -0,0 +1,17 @@
.container {
display: grid;
grid-template-columns: max-content 1fr;
grid-template-rows: 1fr;
}
.menu {
display: flex;
flex-direction: column;
width: 200px;
padding: 40px 0;
}
.content {
display: flex;
flex-direction: column;
}

View File

@ -0,0 +1,17 @@
import { Menu, Item } from 'react-basics';
import Link from 'next/link';
import styles from './SideNav.module.css';
export default function SideNav({ selectedKey, items, shallow }) {
return (
<Menu items={items} selectedKey={selectedKey} className={styles.menu}>
{({ key, label, url }) => (
<Item key={key} className={styles.item}>
<Link href={url} shallow={shallow}>
{label}
</Link>
</Item>
)}
</Menu>
);
}

View File

@ -0,0 +1,14 @@
.menu {
display: flex;
flex-direction: column;
}
.item a {
color: var(--font-color100);
flex: 1;
padding: var(--size300) var(--size600);
}
.item {
padding: 0;
}

View File

@ -38,7 +38,6 @@ export default function PagesTable({ websiteId, showFilters, ...props }) {
type="url" type="url"
metric={formatMessage(labels.views)} metric={formatMessage(labels.views)}
websiteId={websiteId} websiteId={websiteId}
dataFilter={filters[filter]}
renderLabel={renderLink} renderLabel={renderLink}
{...props} {...props}
/> />

View File

@ -2,6 +2,7 @@
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
margin-bottom: 20px;
} }
.metrics { .metrics {

View File

@ -12,7 +12,7 @@ import { DOMAIN_REGEX } from 'lib/constants';
import useMessages from 'hooks/useMessages'; import useMessages from 'hooks/useMessages';
export default function WebsiteAddForm({ onSave, onClose }) { export default function WebsiteAddForm({ onSave, onClose }) {
const { formatMessage, labels } = useMessages(); const { formatMessage, labels, messages } = useMessages();
const { post, useMutation } = useApi(); const { post, useMutation } = useApi();
const { mutate, error, isLoading } = useMutation(data => post('/websites', data)); const { mutate, error, isLoading } = useMutation(data => post('/websites', data));
@ -37,7 +37,7 @@ export default function WebsiteAddForm({ onSave, onClose }) {
name="domain" name="domain"
rules={{ rules={{
required: formatMessage(labels.required), required: formatMessage(labels.required),
pattern: { value: DOMAIN_REGEX, message: formatMessage(labels.invalidDomain) }, pattern: { value: DOMAIN_REGEX, message: formatMessage(messages.invalidDomain) },
}} }}
> >
<TextField autoComplete="off" /> <TextField autoComplete="off" />

View File

@ -11,10 +11,11 @@ import QueryParametersTable from 'components/metrics/QueryParametersTable';
import ReferrersTable from 'components/metrics/ReferrersTable'; import ReferrersTable from 'components/metrics/ReferrersTable';
import ScreenTable from 'components/metrics/ScreenTable'; import ScreenTable from 'components/metrics/ScreenTable';
import EventsTable from 'components/metrics/EventsTable'; import EventsTable from 'components/metrics/EventsTable';
import usePageQuery from 'hooks/usePageQuery';
import Icons from 'components/icons'; import Icons from 'components/icons';
import styles from './WebsiteMenuView.module.css'; import SideNav from 'components/layout/SideNav';
import usePageQuery from 'hooks/usePageQuery';
import useMessages from 'hooks/useMessages'; import useMessages from 'hooks/useMessages';
import styles from './WebsiteMenuView.module.css';
const views = { const views = {
url: PagesTable, url: PagesTable,
@ -40,42 +41,52 @@ export default function WebsiteMenuView({ websiteId, websiteDomain }) {
{ {
key: 'url', key: 'url',
label: formatMessage(labels.pages), label: formatMessage(labels.pages),
url: resolveUrl({ view: 'url' }),
}, },
{ {
key: 'referrer', key: 'referrer',
label: formatMessage(labels.referrers), label: formatMessage(labels.referrers),
url: resolveUrl({ view: 'referrer' }),
}, },
{ {
key: 'browser', key: 'browser',
label: formatMessage(labels.browsers), label: formatMessage(labels.browsers),
url: resolveUrl({ view: 'browser' }),
}, },
{ {
key: 'os', key: 'os',
label: formatMessage(labels.os), label: formatMessage(labels.os),
url: resolveUrl({ view: 'os' }),
}, },
{ {
key: 'device', key: 'device',
label: formatMessage(labels.devices), label: formatMessage(labels.devices),
url: resolveUrl({ view: 'device' }),
}, },
{ {
key: 'country', key: 'country',
label: formatMessage(labels.countries), label: formatMessage(labels.countries),
url: resolveUrl({ view: 'country' }),
}, },
{ {
key: 'language', key: 'language',
label: formatMessage(labels.languages), label: formatMessage(labels.languages),
url: resolveUrl({ view: 'language' }),
}, },
{ {
key: 'screen', key: 'screen',
label: formatMessage(labels.screens), label: formatMessage(labels.screens),
url: resolveUrl({ view: 'screen' }),
}, },
{ {
key: 'event', key: 'event',
label: formatMessage(labels.events), label: formatMessage(labels.events),
url: resolveUrl({ view: 'event' }),
}, },
{ {
key: 'query', key: 'query',
label: formatMessage(labels.query), label: formatMessage(labels.query),
url: resolveUrl({ view: 'query' }),
}, },
]; ];
@ -94,15 +105,7 @@ export default function WebsiteMenuView({ websiteId, websiteDomain }) {
</Button> </Button>
</Flexbox> </Flexbox>
</Link> </Link>
<Menu items={items} selectedKey={view}> <SideNav items={items} selectedKey={view} shallow={true} />
{({ key, label }) => (
<Item key={key} className={styles.item}>
<Link href={resolveUrl({ view: key })} shallow={true}>
{label}
</Link>
</Item>
)}
</Menu>
</GridColumn> </GridColumn>
<GridColumn xs={12} sm={12} md={12} defaultSize={9} className={styles.data}> <GridColumn xs={12} sm={12} md={12} defaultSize={9} className={styles.data}>
<DetailsComponent <DetailsComponent

View File

@ -1,17 +1,3 @@
.menu {
gap: 20px;
}
.item a {
color: var(--font-color100);
flex: 1;
padding: var(--size300) var(--size600);
}
.item {
padding: 0;
}
.data { .data {
min-height: 600px; min-height: 600px;
} }

View File

@ -1,4 +1,4 @@
import AppLayout from 'components/layout/AppLayout'; import SettingsLayout from 'components/layout/SettingsLayout';
import WebsitesList from 'components/pages/settings/websites/WebsitesList'; import WebsitesList from 'components/pages/settings/websites/WebsitesList';
export default function WebsitesPage({ disabled }) { export default function WebsitesPage({ disabled }) {
@ -7,9 +7,9 @@ export default function WebsitesPage({ disabled }) {
} }
return ( return (
<AppLayout> <SettingsLayout>
<WebsitesList /> <WebsitesList />
</AppLayout> </SettingsLayout>
); );
} }

View File

@ -31,7 +31,7 @@ function clickhouseQuery(websiteId: string, startAt: Date) {
session_id as sessionId, session_id as sessionId,
created_at as createdAt, created_at as createdAt,
toUnixTimestamp(created_at) as timestamp, toUnixTimestamp(created_at) as timestamp,
url, url_path,
event_name as eventName event_name as eventName
from event from event
where event_type = ${EVENT_TYPE.customEvent} where event_type = ${EVENT_TYPE.customEvent}

View File

@ -30,7 +30,7 @@ async function clickhouseQuery(websiteId: string, startAt: Date) {
session_id as sessionId, session_id as sessionId,
created_at as createdAt, created_at as createdAt,
toUnixTimestamp(created_at) as timestamp, toUnixTimestamp(created_at) as timestamp,
url url_path
from event from event
where event_type = ${EVENT_TYPE.pageView} where event_type = ${EVENT_TYPE.pageView}
and website_id = {websiteId:UUID} and website_id = {websiteId:UUID}