Skip to content

Commit

Permalink
Fix dashboard (#23)
Browse files Browse the repository at this point in the history
* WIP: Fix dashboard

* Use raw queries to fetch dashboard data

* Update bar chart

* Add back apexcharts

* Reimplement bar charts

* Change brush chart with timeseries chart
  • Loading branch information
AntonioVdlC committed Aug 6, 2023
1 parent 92999d7 commit f466511
Show file tree
Hide file tree
Showing 61 changed files with 6,753 additions and 6,876 deletions.
2 changes: 1 addition & 1 deletion app/components/AppContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { FC, ReactChild, useEffect, useState } from "react";
import { useLocation } from "remix";
import {
GlobeIcon,
DocumentReportIcon,
Expand All @@ -12,6 +11,7 @@ import type { User, Website } from "@prisma/client";
import AppNavigationMobile from "~/components/AppNavigationMobile";
import AppNavigationSide from "~/components/AppNavigationSide";
import AppNavigationTop from "~/components/AppNavigationTop";
import { useLocation } from "@remix-run/react";

export type NavigationItem = {
name: string;
Expand Down
4 changes: 2 additions & 2 deletions app/components/AppNavigationMobile.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Fragment } from "react";
import { Link } from "remix";
import { Transition, Dialog } from "@headlessui/react";
import { XIcon } from "@heroicons/react/outline";

Expand All @@ -8,6 +7,7 @@ import classNames from "~/utils/class-names";
import Logo from "~/components/Logo";

import type { NavigationItem } from "~/components/AppContainer";
import { Link } from "@remix-run/react";

type Props = {
sidebarOpen: boolean;
Expand Down Expand Up @@ -60,7 +60,7 @@ export default function AppNavigationMobile({
leaveFrom="opacity-100"
leaveTo="opacity-0"
>
<div className="absolute top-0 right-0 -mr-12 pt-2">
<div className="absolute right-0 top-0 -mr-12 pt-2">
<button
type="button"
className="ml-1 flex h-10 w-10 items-center justify-center rounded-full focus:outline-none focus:ring-2 focus:ring-inset focus:ring-white"
Expand Down
3 changes: 1 addition & 2 deletions app/components/AppNavigationSide.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Link } from "remix";

import classNames from "~/utils/class-names";

import Logo from "~/components/Logo";

import type { NavigationItem } from "~/components/AppContainer";
import { Link } from "@remix-run/react";

type Props = {
navigation: {
Expand Down
166 changes: 86 additions & 80 deletions app/components/BarChart.client.tsx
Original file line number Diff line number Diff line change
@@ -1,117 +1,123 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */

import { useState } from "react";
import { useEffect, useState } from "react";
import ReactApexChart from "react-apexcharts";
import { DashboardElement } from "~/types/dashboard";

import type { ApexOptions } from "apexcharts";

type Props = {
categories: string[];
data: number[];
elements: Array<{ id: string }>;
data: DashboardElement[];
limit?: number;
onClick?: (id: string) => void;
};

const VIEW_LIMIT = 5;
const VIEW_LIMIT = 4;

export default function BarChart({
categories,
data,
elements,
limit = VIEW_LIMIT,
onClick = () => null,
}: Props) {
const [viewAll, setViewAll] = useState(false);
const [series, setSeries] = useState<ApexOptions["series"]>([]);
const [options, setOptions] = useState<ApexOptions>({});

const options = {
chart: {
type: "bar",
height: 55 * (viewAll || data.length < limit ? data.length : limit) + 55,
offsetX: -25,
offsetY: -25,
toolbar: {
show: true,
offsetX: -30,
offsetY: -23,
useEffect(() => {
const displayData = viewAll ? data : data.slice(0, limit);

setSeries([
{
name: "Views",
data: displayData.map(({ count, label }) => ({ x: label, y: count })),
},
events: {
click(_: never, __: never, config: { dataPointIndex: number }) {
onClick(elements[config.dataPointIndex].id);
]);

setOptions({
chart: {
type: "bar",
height:
55 *
(viewAll || displayData.length < limit
? displayData.length
: limit) +
55,
offsetX: -25,
offsetY: -25,
toolbar: {
show: true,
offsetX: -30,
offsetY: -23,
},
},
},
plotOptions: {
bar: {
borderRadius: 4,
horizontal: true,
barHeight: "80%",
dataLabels: {
position: "bottom",
events: {
click(_: never, __: never, config: { dataPointIndex: number }) {
onClick(data[config.dataPointIndex].id);
},
},
},
},
dataLabels: {
enabled: true,
textAnchor: "start",
style: {
colors: ["#1e293b"],
fontWeight: 400,
},
formatter: function (_: any, opt: any) {
return opt.w.globals.labels[opt.dataPointIndex];
},
offsetX: 10,
dropShadow: {
enabled: false,
},
},
colors: ["#e2e8f0"],
tooltip: {
y: {
formatter(val: number) {
return Math.round(val);
plotOptions: {
bar: {
borderRadius: 4,
horizontal: true,
barHeight: "80%",
dataLabels: {
position: "bottom",
},
},
},
},
xaxis: {
categories,
axisBorder: {
show: true,
color: "#1e293b",
dataLabels: {
enabled: true,
textAnchor: "start",
style: {
colors: ["#1e293b"],
fontWeight: 400,
},
formatter: function (_: any, opt: any) {

Check warning on line 73 in app/components/BarChart.client.tsx

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

Check warning on line 73 in app/components/BarChart.client.tsx

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

Check warning on line 73 in app/components/BarChart.client.tsx

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type

Check warning on line 73 in app/components/BarChart.client.tsx

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
return opt.w.globals.labels[opt.dataPointIndex];
},
offsetX: 10,
dropShadow: {
enabled: false,
},
},
axisTicks: {
show: false,
colors: ["#e2e8f0"],
tooltip: {
y: {
formatter(val: number) {
return String(Math.round(val));
},
},
},
labels: {
formatter(val: number) {
return Math.round(val);
xaxis: {
axisBorder: {
show: true,
color: "#1e293b",
},
axisTicks: {
show: false,
},
labels: {
formatter(val: string) {
return String(Math.round(Number(val)));
},
},
},
},
yaxis: {
labels: {
show: false,
yaxis: {
labels: {
show: false,
},
},
},
};

const series = [
{
name: "Page Views",
data: viewAll ? data : data.slice(0, limit),
},
];
});
}, [viewAll, data, limit]);

return (
<div className="relative">
{/* @ts-ignore */}
<ReactApexChart
options={options}
series={series}
type={options.chart.type}
height={options.chart.height}
type={"bar"}
height={options.chart?.height || 350}
/>
{data.length > limit ? (
<div className="absolute top-[-20px] right-[70px] text-xs text-slate-500 hover:text-slate-400">
<div className="absolute right-[70px] top-[-20px] text-xs text-slate-500 hover:text-slate-400">
<a onClick={() => setViewAll(!viewAll)}>
{viewAll ? "View Less" : "View More"}
</a>
Expand Down
2 changes: 1 addition & 1 deletion app/components/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useState, useEffect } from "react";
import { Link, useLocation } from "remix";
import { ChevronRightIcon } from "@heroicons/react/outline";
import { HomeIcon } from "@heroicons/react/solid";

import type { Website } from "@prisma/client";

import isUUID from "~/utils/is-uuid";
import { useLocation, Link } from "@remix-run/react";

type CrumbItem = {
name: string;
Expand Down
Loading

0 comments on commit f466511

Please sign in to comment.