Skip to content

Commit

Permalink
Browser icon improvements (plausible#4246)
Browse files Browse the repository at this point in the history
* Use png for Safari icon

* Fix spacing for screen sizes

* Add browser icon to version drilldown
  • Loading branch information
ukutaht authored Jun 20, 2024
1 parent 766807e commit 486ee68
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
36 changes: 26 additions & 10 deletions assets/js/dashboard/stats/devices/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import ImportedQueryUnsupportedWarning from '../imported-query-unsupported-warni
// Icons copied from https://github.com/alrra/browser-logos
const BROWSER_ICONS = {
'Chrome': 'chrome.svg',
'Safari': 'safari.svg',
'Safari': 'safari.png',
'Firefox': 'firefox.svg',
'Microsoft Edge': 'edge.svg',
'Vivaldi': 'vivaldi.svg',
Expand All @@ -28,6 +28,17 @@ const BROWSER_ICONS = {
'vivo Browser': 'vivo.png'
}

function browserIconFor(browser) {
const filename = BROWSER_ICONS[browser] || 'fallback.svg'

return (
<img
src={`/images/icon/browser/${filename}`}
className="w-4 h-4 mr-2"
/>
)
}

function Browsers({ query, site, afterFetchData }) {
function fetchData() {
return api.get(url.apiPath(site, '/browsers'), query)
Expand All @@ -41,14 +52,7 @@ function Browsers({ query, site, afterFetchData }) {
}

function renderIcon(listItem) {
const filename = BROWSER_ICONS[listItem.name] || 'fallback.svg'

return (
<img
src={`/images/icon/browser/${filename}`}
className="w-4 h-4 mr-2"
/>
)
return browserIconFor(listItem.name)
}

return (
Expand All @@ -67,6 +71,15 @@ function Browsers({ query, site, afterFetchData }) {
function BrowserVersions({ query, site, afterFetchData }) {
function fetchData() {
return api.get(url.apiPath(site, '/browser-versions'), query)
.then(res => {
return {...res, results: res.results.map((row => {
return {...row, name: `${row.browser} ${row.name}`}
}))}
})
}

function renderIcon(listItem) {
return browserIconFor(listItem.browser)
}

function getFilterFor(listItem) {
Expand All @@ -86,6 +99,7 @@ function BrowserVersions({ query, site, afterFetchData }) {
getFilterFor={getFilterFor}
keyLabel="Browser version"
metrics={maybeWithCR([VISITORS_METRIC, PERCENTAGE_METRIC], query)}
renderIcon={renderIcon}
query={query}
/>
)
Expand Down Expand Up @@ -150,7 +164,9 @@ function ScreenSizes({ query, site, afterFetchData }) {
}

function renderIcon(screenSize) {
return iconFor(screenSize.name)
return (
<span className="mr-1.5">{iconFor(screenSize.name)}</span>
)
}

function getFilterFor(listItem) {
Expand Down
Binary file added priv/static/images/icon/browser/safari.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion priv/static/images/icon/browser/safari.svg

This file was deleted.

0 comments on commit 486ee68

Please sign in to comment.