Skip to content

Commit

Permalink
Added button to show/hide charts, closes umami-software#577.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecao committed Apr 28, 2021
1 parent 041c773 commit 6675940
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 17 deletions.
1 change: 1 addition & 0 deletions assets/chart-bar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 10 additions & 7 deletions components/metrics/WebsiteChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default function WebsiteChart({
domain,
stickyHeader = false,
showLink = false,
hideChart = false,
onDataLoad = () => {},
}) {
const shareToken = useShareToken();
Expand Down Expand Up @@ -91,13 +92,15 @@ export default function WebsiteChart({
<div className="row">
<div className="col">
{error && <ErrorMessage />}
<PageviewsChart
websiteId={websiteId}
data={chartData}
unit={unit}
records={getDateLength(startDate, endDate, unit)}
loading={loading}
/>
{!hideChart && (
<PageviewsChart
websiteId={websiteId}
data={chartData}
unit={unit}
records={getDateLength(startDate, endDate, unit)}
loading={loading}
/>
)}
</div>
</div>
</div>
Expand Down
37 changes: 27 additions & 10 deletions components/pages/WebsiteList.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
import React from 'react';
import React, { useState } from 'react';
import { FormattedMessage } from 'react-intl';
import Link from 'components/common/Link';
import WebsiteChart from 'components/metrics/WebsiteChart';
import Page from 'components/layout/Page';
import EmptyPlaceholder from 'components/common/EmptyPlaceholder';
import Button from 'components/common/Button';
import useFetch from 'hooks/useFetch';
import Arrow from 'assets/arrow-right.svg';
import Chart from 'assets/chart-bar.svg';
import styles from './WebsiteList.module.css';

export default function WebsiteList({ userId }) {
const { data } = useFetch('/api/websites', { params: { user_id: userId } });
const [hideCharts, setHideCharts] = useState(false);

if (!data) {
return null;
}

return (
<Page>
{data.map(({ website_id, name, domain }) => (
<div key={website_id} className={styles.website}>
<WebsiteChart websiteId={website_id} title={name} domain={domain} showLink />
</div>
))}
{data.length === 0 && (
if (data.length === 0) {
return (
<Page>
<EmptyPlaceholder
msg={
<FormattedMessage
Expand All @@ -35,7 +33,26 @@ export default function WebsiteList({ userId }) {
<FormattedMessage id="message.go-to-settings" defaultMessage="Go to settings" />
</Link>
</EmptyPlaceholder>
)}
</Page>
);
}

return (
<Page>
<div className={styles.menubar}>
<Button icon={<Chart />} onClick={() => setHideCharts(!hideCharts)} />
</div>
{data.map(({ website_id, name, domain }) => (
<div key={website_id} className={styles.website}>
<WebsiteChart
websiteId={website_id}
title={name}
domain={domain}
hideChart={hideCharts}
showLink
/>
</div>
))}
</Page>
);
}
7 changes: 7 additions & 0 deletions components/pages/WebsiteList.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@
border-bottom: 0;
margin-bottom: 0;
}

.menubar {
display: flex;
align-items: center;
justify-content: flex-end;
padding-top: 10px;
}

0 comments on commit 6675940

Please sign in to comment.