App.tsx
Copy
Ask AI
import {
QuillProvider,
useDashboard,
useDashboardReport,
format,
} from "@quillsql/react";
import { Card, CardHeader } from "@/components/ui/card";
import { Skeleton } from "@/components/ui/skeleton";
function App() {
return (
<QuillProvider
tenants={[{ tenantField: "customer_id", tenantIds: [2] }]}
publicKey="6579031b3e41c378aa8180ec"
>
<CustomDashboard />
</QuillProvider>
);
}
function CustomDashboard() {
const { sections, isLoading } = useDashboard("quill demo dashboard");
return (
<>
<MetricReportsSection reports={sections["metrics"]} />
</>
);
}
function MetricsSection({ reports }: { reports: any[] }) {
return (
<div className="grid grid-cols-1 lg:grid-cols-6 gap-6">
{reports.map((report: any) => (
<MetricCard key={report.id} reportId={report.id} name={report.name} />
))}
</div>
);
}
interface MetricCardProps {
reportId: string;
name: string;
}
export function MetricCard({ reportId, name }: MetricCardProps) {
const { report, loading } = useDashboardReport(reportId);
if (loading) {
return (
<div className="lg:col-span-1">
<Card className="h-full shadow-none bg-transparent border-none">
<CardHeader className="pb-4">
<div className="space-y-1">
<Skeleton className="h-10 w-24" />
<Skeleton className="h-4 w-32" />
<p className="text-sm text-muted-foreground">{name}</p>
</div>
</CardHeader>
</Card>
</div>
);
}
if (!report) return null;
const mainValue = format({
value: report.pivotRows?.[0]?.[report.xAxisField],
format: report.xAxisFormat,
});
return (
<Card className="h-full shadow-none bg-transparent border-none">
<CardHeader className="pb-4 bg-transparent">
<div className="space-y-1">
<h1 className="text-4xl font-bold tracking-tight">{mainValue}</h1>
<p className="text-sm text-muted-foreground">{name}</p>
</div>
</CardHeader>
</Card>
);
}
The name of the dashboard to load
Configuration options for the dashboard
Show config properties
Show config properties
The number of rows per page for the tabular rows of a report. Defaults to
10.
Whether the dashboard data is currently loading
The dashboard sections containing reports, organized by section name
Show properties
Show properties
The report’s unique id
The name of the report
The name of the dashboard this report belongs to
The rows of data returned from this report’s query
The columns data returned from this report’s query
The type of this chart
The table and field this report uses for date filtering, if any
The pivot used in this query, if any
The label of the xAxis
The field to use for this report’s xAxis
The format for this report’s xAxis
The template flag for a report
A list of metadata about the yAxes of this report
The relative ordering of this report in relation to its siblings. Ordering
starts at 1 and counts up (eg. 1, 2, 3, etc.). Reports in the same section are
first grouped by chartType and then each group is sorted by order.
The rows of data returned from this report’s query over the comparison date
range as opposed to the primary date range
An array filters that have been applied to this query
A page prop used for smart table pagination
A sort prop used for smart table pagination
A total row count used for SQL pagination
A query for the report used by the report builder on initial load of report
A map of dashboard filters to the appropriate table and field for the report
A list of reference lines to render on compatible charts
Resolved reference line y values
A flag to determine whether to automatically display custom fields
Columns with custom fields
The pivot row info
A list of metadata about the pivot yAxes of this report
Total pivot row count
Available filters for the dashboard. These are typically rendered with html
select or similar UI components.
applyFilters
(filters: Array<{ label: string; value: string | string[] | { startDate?: Date; endDate?: Date }; } | Filter>) => void
Function to apply filters to the dashboard