informe-comercial-alfa/app/components/pipeline/ExecMatrix.js

89 lines
3.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React from "react";
import { money } from "../../lib/constants";
import { MTZ_DIMS, nomCorto } from "../../lib/derive";
import SegTabs from "../SegTabs";
import FilterableRow from "../FilterableRow";
// Matriz de ejecutivos × dimensión conmutable — puerto de mtzEjePanel() (assets/js/tables.js).
// `dims`/`activeDim` dejan elegir la columna (Plan/Categoría Previsión/Actividad/Temperatura/Fase)
// con pestañas — mismo patrón `SegTabs` + searchParam que el resto de la interactividad (Fase 1).
export default function ExecMatrix({ arr, titulo, hint, valor, dims = MTZ_DIMS, activeDim }) {
const val = valor || ((o) => o.est);
const d = dims.find((x) => x.k === activeDim) || dims[0];
const corto = d.corto;
let cols = [...new Set(arr.map((o) => o[d.k]).filter(Boolean))];
cols = d.orden ? cols.sort(d.orden) : cols;
const ejes = [...new Set(arr.map((o) => o.owner))].sort(
(a, b) => arr.filter((o) => o.owner === b).reduce((s, o) => s + val(o), 0) - arr.filter((o) => o.owner === a).reduce((s, o) => s + val(o), 0)
);
const cel = (ow, cv) => arr.filter((o) => o.owner === ow && o[d.k] === cv);
const maxN = Math.max(...ejes.flatMap((ow) => cols.map((c) => cel(ow, c).length)), 1);
return (
<div className="panel">
<h3>{titulo || "Tubería por ejecutivo"}</h3>
<p className="hint">{hint || "La intensidad del azul es la cantidad de oportunidades"}</p>
<div style={{ marginBottom: 12 }}>
<SegTabs tabs={dims.map((x) => ({ k: x.k, lbl: x.lbl }))} activeKey={d.k} paramName="mze" />
</div>
<div
className="mze"
style={{ gridTemplateColumns: `minmax(120px,1.4fr) repeat(${cols.length},minmax(58px,1fr)) minmax(74px,.9fr)` }}
>
<div className="mze-h eje" />
{cols.map((c) => <div className="mze-h" key={c} title={c}>{corto(c)}</div>)}
<div className="mze-h tot">Total</div>
{ejes.map((ow) => {
const tot = arr.filter((o) => o.owner === ow);
return (
<React.Fragment key={ow}>
<FilterableRow as="div" pairs={[["owner", ow]]} className="mze-r">
{nomCorto(ow)}
</FilterableRow>
{cols.map((c) => {
const e = cel(ow, c);
const alpha = e.length ? (0.1 + 0.55 * (e.length / maxN)).toFixed(2) : 0;
return (
<FilterableRow
as="div"
key={`${ow}-${c}`}
pairs={[["owner", ow], [d.k, c]]}
className={`mze-c${e.length ? "" : " vacia"}`}
style={e.length ? { background: `rgba(30,113,184,${alpha})` } : undefined}
>
{e.length ? (
<>
<span className="n">{e.length}</span>
<span className="v">{money(e.reduce((s, o) => s + val(o), 0))}</span>
</>
) : (
<span className="n vacio">·</span>
)}
</FilterableRow>
);
})}
<div className="mze-c tot">
<span className="n">{tot.length}</span>
<span className="v">{money(tot.reduce((s, o) => s + val(o), 0))}</span>
</div>
</React.Fragment>
);
})}
<div className="mze-r tot">Total</div>
{cols.map((c) => {
const e = arr.filter((o) => o[d.k] === c);
return (
<div className="mze-c tot" key={`pie-${c}`}>
<span className="n">{e.length}</span>
<span className="v">{money(e.reduce((s, o) => s + val(o), 0))}</span>
</div>
);
})}
<div className="mze-c tot">
<span className="n">{arr.length}</span>
<span className="v">{money(arr.reduce((s, o) => s + val(o), 0))}</span>
</div>
</div>
</div>
);
}