Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/app/(app)/painel/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import { buildDayMatrix } from "@/lib/report-days";
import { toSearchParams } from "@/lib/schemas/report";
import { formatHms } from "@/lib/time";
import { getTenant } from "@/server/get-tenant";
import { loadCatalog } from "../views";
import { ReportChartsSection } from "../relatorios/charts";
import { loadReport } from "../relatorios/load-report";
import { PanelFilters } from "./panel-filters";
import { ReportFilters } from "../relatorios/report-filters";

export const metadata: Metadata = { title: "Painel" };

Expand All @@ -26,15 +27,15 @@ export default function PanelPage({ searchParams }: PageProps<"/painel">) {

async function Panel({ searchParams }: Pick<PageProps<"/painel">, "searchParams">) {
const { ctx, tenant } = await getTenant();
const report = await loadReport(tenant, ctx, await searchParams);
const [catalog, report] = await Promise.all([loadCatalog(tenant), loadReport(tenant, ctx, await searchParams)]);
const { query, period, isAdmin } = report;

const summary = summarize(report.rows, "descricao");
const summary = summarize(report.rows, query.agrupar);
const matrix = buildDayMatrix(report.rows, period, ctx.timezone, { includePeople: false });
const charts = buildCharts(summary, matrix);
const h = buildHighlights(report.rows, summary, ctx.timezone);
// The same period and people, opened in the full report (filters by client/project live there).
const reportHref = `/relatorios?${toSearchParams({ ...query, cliente: undefined, projeto: undefined, tarefa: undefined, agrupar: undefined })}`;
// The same filters, opened in the full report.
const reportHref = `/relatorios?${toSearchParams(query)}`;

return (
<section className="flex flex-col gap-4">
Expand All @@ -51,7 +52,7 @@ async function Panel({ searchParams }: Pick<PageProps<"/painel">, "searchParams"
</Button>
</div>

<PanelFilters people={report.people} query={query} />
<ReportFilters catalog={catalog} people={report.people} query={query} action="/painel" submitLabel="Atualizar painel" />

{report.periodError && (
<p role="alert" className="rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive">
Expand Down Expand Up @@ -80,7 +81,7 @@ async function Panel({ searchParams }: Pick<PageProps<"/painel">, "searchParams"
/>
</div>

<ReportChartsSection charts={charts} activityTitle="Principais descrições" showPeople={isAdmin} />
<ReportChartsSection charts={charts} activityTitle={`Principais ${summary.groupBy === "tarefa" ? "tarefas" : "descrições"}`} showPeople={isAdmin} />
</>
)}
</section>
Expand Down
92 changes: 0 additions & 92 deletions src/app/(app)/painel/panel-filters.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/app/(app)/relatorios/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async function Reports({ searchParams }: Pick<PageProps<"/relatorios">, "searchP
for (const id of query.pessoas) params.append("pessoas", id);
return `/relatorios?${params}`;
})();
const panelHref = `/painel?${toSearchParams({ ...query, cliente: undefined, projeto: undefined, tarefa: undefined, agrupar: undefined })}`;
const panelHref = `/painel?${toSearchParams(query)}`;
const summary = summarize(result.rows, query.agrupar);
const dayMatrix = buildDayMatrix(result.rows, period, tz, { includePeople: isAdmin });
const showPerson = isAdmin;
Expand Down
11 changes: 8 additions & 3 deletions src/app/(app)/relatorios/report-filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ export function ReportFilters({
catalog,
people,
query,
action = "/relatorios",
submitLabel = "Gerar relatório",
}: {
catalog: CatalogView;
/** Null for members: they only ever see their own hours, so there is nothing to pick. */
people: PersonOption[] | null;
query: ReportQuery;
/** Page the form submits to; the dashboard reuses these filters. */
action?: "/relatorios" | "/painel";
submitLabel?: string;
}) {
const [period, setPeriod] = useState<PeriodPreset>(query.periodo);
const [clientId, setClientId] = useState(query.cliente ?? "");
Expand All @@ -37,7 +42,7 @@ export function ReportFilters({
const tasks = catalog.tasks.filter((t) => t.projectId === projectId);

return (
<form method="get" action="/relatorios" className="grid gap-3 rounded-lg border p-4 sm:grid-cols-2 lg:grid-cols-4">
<form method="get" action={action} className="grid gap-3 rounded-lg border p-4 sm:grid-cols-2 lg:grid-cols-4">
<label className="grid gap-1.5 text-sm font-medium">
Período
<select name="periodo" className={selectClass} value={period} onChange={(e) => setPeriod(e.target.value as PeriodPreset)}>
Expand Down Expand Up @@ -169,9 +174,9 @@ export function ReportFilters({
)}

<div className="flex items-end gap-2 sm:col-span-2 lg:col-span-4">
<Button type="submit">Gerar relatório</Button>
<Button type="submit">{submitLabel}</Button>
<Button asChild variant="ghost">
<Link href="/relatorios">Limpar</Link>
<Link href={action}>Limpar</Link>
</Button>
</div>
</form>
Expand Down
Loading