From 35b921bdb4d966d6bc0500edfe0acc6bcc0ab77b Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Fri, 25 Sep 2020 23:38:28 -0700 Subject: [PATCH] Convert buttons to links. --- components/WebsiteDetails.js | 22 ++++++----------- components/WebsiteDetails.module.css | 1 - components/common/Button.js | 2 +- components/common/Button.module.css | 16 ++++++------ components/common/Link.js | 15 ++++++++++-- components/common/Link.module.css | 27 +++++++++++++++++++++ components/metrics/BrowsersTable.js | 3 +-- components/metrics/CountriesTable.js | 9 +------ components/metrics/DevicesTable.js | 3 +-- components/metrics/EventsTable.js | 3 +-- components/metrics/MetricsTable.js | 16 ++++++++---- components/metrics/MetricsTable.module.css | 7 +++--- components/metrics/OSTable.js | 3 +-- components/metrics/PagesTable.js | 26 +++++++++++--------- components/metrics/PagesTable.module.css | 8 ++++++ components/metrics/ReferrersTable.js | 10 +------- components/metrics/WebsiteChart.js | 2 +- components/metrics/WebsiteHeader.js | 5 ++-- components/metrics/WebsiteHeader.module.css | 5 ---- package.json | 2 +- pages/api/website/[id]/rankings.js | 2 +- 21 files changed, 108 insertions(+), 79 deletions(-) create mode 100644 components/metrics/PagesTable.module.css diff --git a/components/WebsiteDetails.js b/components/WebsiteDetails.js index 0fa20284..f24332ba 100644 --- a/components/WebsiteDetails.js +++ b/components/WebsiteDetails.js @@ -5,7 +5,8 @@ import WebsiteChart from 'components/metrics/WebsiteChart'; import WorldMap from 'components/common/WorldMap'; import Page from 'components/layout/Page'; import MenuLayout from 'components/layout/MenuLayout'; -import Button from 'components/common/Button'; +import Link from 'components/common/Link'; +import Loading from 'components/common/Loading'; import Arrow from 'assets/arrow-right.svg'; import styles from './WebsiteDetails.module.css'; import PagesTable from './metrics/PagesTable'; @@ -17,8 +18,7 @@ import CountriesTable from './metrics/CountriesTable'; import EventsTable from './metrics/EventsTable'; import EventsChart from './metrics/EventsChart'; import useFetch from 'hooks/useFetch'; -import Loading from 'components/common/Loading'; -import usePageQuery from '../hooks/usePageQuery'; +import usePageQuery from 'hooks/usePageQuery'; const views = { url: PagesTable, @@ -36,22 +36,21 @@ export default function WebsiteDetails({ websiteId, token }) { const [countryData, setCountryData] = useState(); const [eventsData, setEventsData] = useState(); const { - pathname, resolve, - router, query: { view }, } = usePageQuery(); const BackButton = () => ( - + ); const menuOptions = [ @@ -93,7 +92,6 @@ export default function WebsiteDetails({ websiteId, token }) { token, websiteDomain: data?.domain, limit: 10, - onExpand: handleExpand, }; const DetailsComponent = views[view]; @@ -104,10 +102,6 @@ export default function WebsiteDetails({ websiteId, token }) { } } - function handleExpand(value) { - router.push(resolve({ view: value })); - } - if (!data) { return null; } diff --git a/components/WebsiteDetails.module.css b/components/WebsiteDetails.module.css index ca80dca0..0e1065c6 100644 --- a/components/WebsiteDetails.module.css +++ b/components/WebsiteDetails.module.css @@ -16,7 +16,6 @@ } .backButton { - align-self: flex-start; margin-bottom: 16px; } diff --git a/components/common/Button.js b/components/common/Button.js index f769ba6f..5e92d0d8 100644 --- a/components/common/Button.js +++ b/components/common/Button.js @@ -38,7 +38,7 @@ export default function Button({ {...props} > {icon && } - {children &&
{children}
} + {children &&
{children}
} {tooltip && {tooltip}} ); diff --git a/components/common/Button.module.css b/components/common/Button.module.css index 51341fee..f4fd8546 100644 --- a/components/common/Button.module.css +++ b/components/common/Button.module.css @@ -10,7 +10,6 @@ border: 0; outline: none; cursor: pointer; - white-space: nowrap; position: relative; } @@ -22,12 +21,15 @@ color: var(--gray900); } -.large { - font-size: var(--font-size-large); +.label { + white-space: nowrap; + text-overflow: ellipsis; + overflow: hidden; + max-width: 300px; } -.medium { - font-size: var(--font-size-normal); +.large { + font-size: var(--font-size-large); } .small { @@ -65,7 +67,7 @@ background: inherit; } -.button .icon + div { +.button .icon + * { margin-left: 10px; } @@ -74,7 +76,7 @@ margin-left: 10px; } -.button.iconRight .icon + div { +.button.iconRight .icon + * { margin: 0; } diff --git a/components/common/Link.js b/components/common/Link.js index c3a5fa7e..466e018c 100644 --- a/components/common/Link.js +++ b/components/common/Link.js @@ -1,12 +1,23 @@ import React from 'react'; import classNames from 'classnames'; import NextLink from 'next/link'; +import Icon from './Icon'; import styles from './Link.module.css'; -export default function Link({ className, children, ...props }) { +export default function Link({ className, icon, children, size, iconRight, ...props }) { return ( - {children} + + {icon && } + {children} + ); } diff --git a/components/common/Link.module.css b/components/common/Link.module.css index 24d8f84c..ea6d281d 100644 --- a/components/common/Link.module.css +++ b/components/common/Link.module.css @@ -4,6 +4,8 @@ a.link:visited { position: relative; color: var(--gray900); text-decoration: none; + display: inline-flex; + align-items: center; } a.link:before { @@ -21,3 +23,28 @@ a.link:hover:before { width: 100%; transition: width 100ms; } + +a.link.large { + font-size: var(--font-size-large); +} + +a.link.small { + font-size: var(--font-size-small); +} + +a.link.xsmall { + font-size: var(--font-size-xsmall); +} + +a.link .icon + * { + margin-left: 10px; +} + +a.link.iconRight .icon { + order: 1; + margin-left: 10px; +} + +a.link.iconRight .icon + * { + margin: 0; +} diff --git a/components/metrics/BrowsersTable.js b/components/metrics/BrowsersTable.js index f092e62f..97f9bfbd 100644 --- a/components/metrics/BrowsersTable.js +++ b/components/metrics/BrowsersTable.js @@ -3,7 +3,7 @@ import { FormattedMessage } from 'react-intl'; import MetricsTable from './MetricsTable'; import { browserFilter } from 'lib/filters'; -export default function BrowsersTable({ websiteId, token, limit, onExpand }) { +export default function BrowsersTable({ websiteId, token, limit }) { return ( } @@ -13,7 +13,6 @@ export default function BrowsersTable({ websiteId, token, limit, onExpand }) { token={token} limit={limit} dataFilter={browserFilter} - onExpand={onExpand} /> ); } diff --git a/components/metrics/CountriesTable.js b/components/metrics/CountriesTable.js index 1f516653..58548d06 100644 --- a/components/metrics/CountriesTable.js +++ b/components/metrics/CountriesTable.js @@ -3,13 +3,7 @@ import MetricsTable from './MetricsTable'; import { countryFilter, percentFilter } from 'lib/filters'; import { FormattedMessage } from 'react-intl'; -export default function CountriesTable({ - websiteId, - token, - limit, - onDataLoad = () => {}, - onExpand, -}) { +export default function CountriesTable({ websiteId, token, limit, onDataLoad = () => {} }) { return ( } @@ -20,7 +14,6 @@ export default function CountriesTable({ limit={limit} dataFilter={countryFilter} onDataLoad={data => onDataLoad(percentFilter(data))} - onExpand={onExpand} /> ); } diff --git a/components/metrics/DevicesTable.js b/components/metrics/DevicesTable.js index 85d2bdfd..7d87d1c1 100644 --- a/components/metrics/DevicesTable.js +++ b/components/metrics/DevicesTable.js @@ -4,7 +4,7 @@ import { deviceFilter } from 'lib/filters'; import { FormattedMessage } from 'react-intl'; import { getDeviceMessage } from 'components/messages'; -export default function DevicesTable({ websiteId, token, limit, onExpand }) { +export default function DevicesTable({ websiteId, token, limit }) { return ( } @@ -15,7 +15,6 @@ export default function DevicesTable({ websiteId, token, limit, onExpand }) { limit={limit} dataFilter={deviceFilter} renderLabel={({ x }) => getDeviceMessage(x)} - onExpand={onExpand} /> ); } diff --git a/components/metrics/EventsTable.js b/components/metrics/EventsTable.js index 948b9f7a..9a7a09cb 100644 --- a/components/metrics/EventsTable.js +++ b/components/metrics/EventsTable.js @@ -3,7 +3,7 @@ import { FormattedMessage } from 'react-intl'; import MetricsTable from './MetricsTable'; import styles from './EventsTable.module.css'; -export default function EventsTable({ websiteId, token, limit, onExpand, onDataLoad }) { +export default function EventsTable({ websiteId, token, limit, onDataLoad }) { return ( } @@ -13,7 +13,6 @@ export default function EventsTable({ websiteId, token, limit, onExpand, onDataL token={token} limit={limit} renderLabel={({ x }) =>