Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Fix analytics card bars

Tim Wilsonf4ab884cf51e
diff --git a/apps/web/ui/analytics/devices.tsx b/apps/web/ui/analytics/devices.tsx
index 4c4d3811e6..6ad6596c37 100644
--- a/apps/web/ui/analytics/devices.tsx
+++ b/apps/web/ui/analytics/devices.tsx
@@ -37,26 +37,28 @@ export default function Devices() {
<BarList
tab={singularTabName}
data={
- data?.map((d) => ({
- icon: (
- <DeviceIcon
- display={d[singularTabName]}
- tab={tab}
- className="h-4 w-4"
- />
- ),
- title: d[singularTabName],
- href: queryParams({
- set: {
- [singularTabName]: d[singularTabName],
- },
- getNewPath: true,
- }) as string,
- value: d[dataKey] || 0,
- })) || []
+ data
+ ?.map((d) => ({
+ icon: (
+ <DeviceIcon
+ display={d[singularTabName]}
+ tab={tab}
+ className="h-4 w-4"
+ />
+ ),
+ title: d[singularTabName],
+ href: queryParams({
+ set: {
+ [singularTabName]: d[singularTabName],
+ },
+ getNewPath: true,
+ }) as string,
+ value: d[dataKey] || 0,
+ }))
+ ?.sort((a, b) => b.value - a.value) || []
}
isCurrency={dataKey === "amount"}
- maxValue={(data && data[0]?.[dataKey]) || 0}
+ maxValue={Math.max(...data?.map((d) => d[dataKey] ?? 0)) ?? 0}
barBackground="bg-green-100"
hoverBackground="hover:bg-gradient-to-r hover:from-green-50 hover:to-transparent hover:border-green-500"
setShowModal={setShowModal}
diff --git a/apps/web/ui/analytics/locations.tsx b/apps/web/ui/analytics/locations.tsx
index cdfe33a587..15e1f5f018 100644
--- a/apps/web/ui/analytics/locations.tsx
+++ b/apps/web/ui/analytics/locations.tsx
@@ -35,26 +35,28 @@ export default function Locations() {
<BarList
tab={singularTabName}
data={
- data?.map((d) => ({
- icon: (
- <img
- alt={d.country}
- src={`https://flag.vercel.app/m/${d.country}.svg`}
- className="h-3 w-5"
- />
- ),
- title: tab === "countries" ? COUNTRIES[d.country] : d.city,
- href: queryParams({
- set: {
- [singularTabName]: d[singularTabName],
- },
- getNewPath: true,
- }) as string,
- value: d[dataKey] || 0,
- })) || []
+ data
+ ?.map((d) => ({
+ icon: (
+ <img
+ alt={d.country}
+ src={`https://flag.vercel.app/m/${d.country}.svg`}
+ className="h-3 w-5"
+ />
+ ),
+ title: tab === "countries" ? COUNTRIES[d.country] : d.city,
+ href: queryParams({
+ set: {
+ [singularTabName]: d[singularTabName],
+ },
+ getNewPath: true,
+ }) as string,
+ value: d[dataKey] || 0,
+ }))
+ ?.sort((a, b) => b.value - a.value) || []
}
isCurrency={dataKey === "amount"}
- maxValue={(data && data[0]?.[dataKey]) || 0}
+ maxValue={Math.max(...data?.map((d) => d[dataKey] ?? 0)) ?? 0}
barBackground="bg-blue-100"
hoverBackground="hover:bg-gradient-to-r hover:from-blue-50 hover:to-transparent hover:border-blue-500"
setShowModal={setShowModal}
diff --git a/apps/web/ui/analytics/referer.tsx b/apps/web/ui/analytics/referer.tsx
index 9608e9bc97..3f2a5f655b 100644
--- a/apps/web/ui/analytics/referer.tsx
+++ b/apps/web/ui/analytics/referer.tsx
@@ -29,31 +29,33 @@ export default function Referer() {
<BarList
tab="Referrer"
data={
- data?.map((d) => ({
- icon:
- d.referer === "(direct)" ? (
- <Link2 className="h-4 w-4" />
- ) : (
- <BlurImage
- src={`${GOOGLE_FAVICON_URL}${d.referer}`}
- alt={d.referer}
- width={20}
- height={20}
- className="h-4 w-4 rounded-full"
- />
- ),
- title: d.referer,
- href: queryParams({
- set: {
- referer: d.referer,
- },
- getNewPath: true,
- }) as string,
- value: d[dataKey] || 0,
- })) || []
+ data
+ ?.map((d) => ({
+ icon:
+ d.referer === "(direct)" ? (
+ <Link2 className="h-4 w-4" />
+ ) : (
+ <BlurImage
+ src={`${GOOGLE_FAVICON_URL}${d.referer}`}
+ alt={d.referer}
+ width={20}
+ height={20}
+ className="h-4 w-4 rounded-full"
+ />
+ ),
+ title: d.referer,
+ href: queryParams({
+ set: {
+ referer: d.referer,
+ },
+ getNewPath: true,
+ }) as string,
+ value: d[dataKey] || 0,
+ }))
+ ?.sort((a, b) => b.value - a.value) || []
}
isCurrency={dataKey === "amount"}
- maxValue={(data && data[0]?.[dataKey]) || 0}
+ maxValue={Math.max(...data?.map((d) => d[dataKey] ?? 0)) ?? 0}
barBackground="bg-red-100"
hoverBackground="hover:bg-gradient-to-r hover:from-red-50 hover:to-transparent hover:border-red-500"
setShowModal={setShowModal}
diff --git a/apps/web/ui/analytics/top-links.tsx b/apps/web/ui/analytics/top-links.tsx
index 6829db3f41..45d12190d5 100644
--- a/apps/web/ui/analytics/top-links.tsx
+++ b/apps/web/ui/analytics/top-links.tsx
@@ -35,33 +35,35 @@ export default function TopLinks() {
<BarList
tab={showUrls ? "url" : "link"}
data={
- data?.map((d) => ({
- icon: (
- <LinkLogo
- apexDomain={getApexDomain(d.url)}
- className="h-5 w-5 sm:h-5 sm:w-5"
- />
- ),
- title:
- !showUrls && d["shortLink"]
- ? d["shortLink"].replace(/^https?:\/\//, "")
- : d.url?.replace(/^https?:\/\//, ""),
- href: queryParams({
- set: {
- ...(!showUrls
- ? { domain: d.domain, key: d.key || "_root" }
- : {
- url: d.url,
- }),
- },
- getNewPath: true,
- }) as string,
- value: d[dataKey] || 0,
- ...(!showUrls && { linkData: d }),
- })) || []
+ data
+ ?.map((d) => ({
+ icon: (
+ <LinkLogo
+ apexDomain={getApexDomain(d.url)}
+ className="h-5 w-5 sm:h-5 sm:w-5"
+ />
+ ),
+ title:
+ !showUrls && d["shortLink"]
+ ? d["shortLink"].replace(/^https?:\/\//, "")
+ : d.url?.replace(/^https?:\/\//, ""),
+ href: queryParams({
+ set: {
+ ...(!showUrls
+ ? { domain: d.domain, key: d.key || "_root" }
+ : {
+ url: d.url,
+ }),
+ },
+ getNewPath: true,
+ }) as string,
+ value: d[dataKey] || 0,
+ ...(!showUrls && { linkData: d }),
+ }))
+ ?.sort((a, b) => b.value - a.value) || []
}
isCurrency={dataKey === "amount"}
- maxValue={(data && data[0]?.[dataKey]) || 0}
+ maxValue={Math.max(...data?.map((d) => d[dataKey] ?? 0)) ?? 0}
barBackground="bg-orange-100"
hoverBackground="hover:bg-gradient-to-r hover:from-orange-50 hover:to-transparent hover:border-orange-500"
setShowModal={setShowModal}