Skip to content

Commit 81add0c

Browse files
committed
Unify main graph icons
1 parent 93d1530 commit 81add0c

File tree

6 files changed

+86
-55
lines changed

6 files changed

+86
-55
lines changed

assets/js/dashboard/stats/graph/interval-picker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export function IntervalPicker({
142142
shouldIgnoreWhen={[isModifierPressed, isTyping]}
143143
/>
144144
)}
145-
<Popover className="relative inline-block pl-2">
145+
<Popover className="relative inline-block">
146146
<BlurMenuButtonOnEscape targetRef={menuElement} />
147147
<PopoverButton
148148
ref={menuElement}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React from 'react'
2+
import { Tooltip } from '../../util/tooltip'
3+
4+
export const NoticesIcon = ({ notices }: { notices: string[] }) => {
5+
if (!notices.length) {
6+
return null
7+
}
8+
return (
9+
<Tooltip
10+
info={
11+
<div className="w-[200px] font-normal flex flex-col gap-y-2">
12+
{notices.map((notice, id) => (
13+
<p key={id}>{notice}</p>
14+
))}
15+
</div>
16+
}
17+
className="cursor-pointer w-4 h-4"
18+
>
19+
<svg
20+
className="absolute w-4 h-4 dark:text-gray-300 text-gray-700"
21+
xmlns="http://www.w3.org/2000/svg"
22+
fill="none"
23+
viewBox="0 0 24 24"
24+
stroke="currentColor"
25+
>
26+
<path
27+
strokeLinecap="round"
28+
strokeLinejoin="round"
29+
strokeWidth="2"
30+
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
31+
/>
32+
</svg>
33+
</Tooltip>
34+
)
35+
}
36+
37+
export function getSamplingNotice(topStatData: { samplePercent?: number }) {
38+
const samplePercent = topStatData?.samplePercent
39+
40+
if (samplePercent && samplePercent < 100) {
41+
return `Stats based on a ${samplePercent}% sample of all visitors`
42+
}
43+
44+
return null
45+
}

assets/js/dashboard/stats/graph/sampling-notice.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

assets/js/dashboard/stats/graph/stats-export.js renamed to assets/js/dashboard/stats/graph/stats-export.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as api from '../../api'
33
import { getCurrentInterval } from './interval-picker'
44
import { useSiteContext } from '../../site-context'
55
import { useQueryContext } from '../../query-context'
6+
import { Tooltip } from '../../util/tooltip'
67

78
export default function StatsExport() {
89
const site = useSiteContext()
@@ -56,7 +57,12 @@ export default function StatsExport() {
5657
const endpoint = `/${encodeURIComponent(site.domain)}/export?${queryParams}`
5758

5859
return (
59-
<a href={endpoint} download onClick={startExport}>
60+
<a
61+
className="block h-4 w-4"
62+
href={endpoint}
63+
download
64+
onClick={startExport}
65+
>
6066
<svg
6167
className="absolute text-gray-700 feather dark:text-gray-300 hover:text-indigo-600 dark:hover:text-indigo-600"
6268
xmlns="http://www.w3.org/2000/svg"
@@ -76,9 +82,12 @@ export default function StatsExport() {
7682
}
7783

7884
return (
79-
<div className="w-4 h-4 mx-2">
85+
<Tooltip
86+
info={<div className="font-normal truncate">Click to export stats</div>}
87+
className="w-4 h-4"
88+
>
8089
{exporting && renderLoading()}
8190
{!exporting && renderExportLink()}
82-
</div>
91+
</Tooltip>
8392
)
8493
}

assets/js/dashboard/stats/graph/visitor-graph.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ import TopStats from './top-stats'
66
import { IntervalPicker, getCurrentInterval } from './interval-picker'
77
import StatsExport from './stats-export'
88
import WithImportedSwitch from './with-imported-switch'
9-
import SamplingNotice from './sampling-notice'
9+
import { getSamplingNotice, NoticesIcon } from './notices'
1010
import FadeIn from '../../fade-in'
1111
import * as url from '../../util/url'
1212
import { isComparisonEnabled } from '../../query-time-periods'
1313
import LineGraphWithRouter from './line-graph'
1414
import { useQueryContext } from '../../query-context'
1515
import { useSiteContext } from '../../site-context'
16-
import { ExclamationCircleIcon } from '@heroicons/react/24/outline'
1716

1817
function fetchTopStats(site, query) {
1918
const q = { ...query }
@@ -152,23 +151,18 @@ export default function VisitorGraph({ updateImportedDataInView }) {
152151
)
153152
}
154153

155-
function renderImportedIntervalUnsupportedWarning() {
154+
function getImportedIntervalUnsupportedNotice() {
156155
const unsupportedInterval = ['hour', 'minute'].includes(
157156
getCurrentInterval(site, query)
158157
)
159158
const showingImported =
160159
importedSwitchVisible() && query.with_imported === true
161160

162-
return (
163-
<FadeIn
164-
show={showingImported && unsupportedInterval}
165-
className="h-6 mr-1"
166-
>
167-
<span tooltip={'Interval is too short to graph imported data'}>
168-
<ExclamationCircleIcon className="w-6 h-6 text-gray-700 dark:text-gray-300" />
169-
</span>
170-
</FadeIn>
171-
)
161+
if (showingImported && unsupportedInterval) {
162+
return 'Interval is too short to graph imported data'
163+
}
164+
165+
return null
172166
}
173167

174168
return (
@@ -194,10 +188,14 @@ export default function VisitorGraph({ updateImportedDataInView }) {
194188
</div>
195189
<div className="relative px-2">
196190
{graphRefreshing && renderLoader()}
197-
<div className="absolute right-4 -top-8 py-1 flex items-center">
198-
{renderImportedIntervalUnsupportedWarning()}
191+
<div className="absolute right-4 -top-8 py-1 flex items-center gap-x-4">
192+
<NoticesIcon
193+
notices={[
194+
getImportedIntervalUnsupportedNotice(),
195+
getSamplingNotice(topStatData)
196+
].filter((n) => !!n)}
197+
/>
199198
{!isRealtime && <StatsExport />}
200-
<SamplingNotice samplePercent={topStatData} />
201199
{importedSwitchVisible() && (
202200
<WithImportedSwitch
203201
tooltipMessage={topStatData.with_imported_switch.tooltip_msg}

assets/js/dashboard/stats/graph/with-imported-switch.js renamed to assets/js/dashboard/stats/graph/with-imported-switch.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,28 @@ import { BarsArrowUpIcon } from '@heroicons/react/20/solid'
33
import classNames from 'classnames'
44
import { useQueryContext } from '../../query-context'
55
import { AppNavigationLink } from '../../navigation/use-app-navigate'
6+
import { Tooltip } from '../../util/tooltip'
67

7-
export default function WithImportedSwitch({ tooltipMessage, disabled }) {
8+
export default function WithImportedSwitch({
9+
tooltipMessage,
10+
disabled
11+
}: {
12+
tooltipMessage: string
13+
disabled?: boolean
14+
}) {
815
const { query } = useQueryContext()
916
const importsSwitchedOn = query.with_imported
1017

11-
const iconClass = classNames('mt-0.5', {
18+
const iconClass = classNames({
1219
'dark:text-gray-300 text-gray-700': importsSwitchedOn,
1320
'dark:text-gray-500 text-gray-400': !importsSwitchedOn
1421
})
1522

1623
return (
17-
<div tooltip={tooltipMessage} className="w-4 h-4 mx-2">
24+
<Tooltip
25+
info={<div className="font-normal truncate">{tooltipMessage}</div>}
26+
className="w-4 h-4"
27+
>
1828
<AppNavigationLink
1929
search={
2030
disabled
@@ -24,6 +34,6 @@ export default function WithImportedSwitch({ tooltipMessage, disabled }) {
2434
>
2535
<BarsArrowUpIcon className={iconClass} />
2636
</AppNavigationLink>
27-
</div>
37+
</Tooltip>
2838
)
2939
}

0 commit comments

Comments
 (0)