|
|
@@ -4,22 +4,21 @@ import { UserStateContext } from "../../../context/auth/AuthProvider";
|
|
|
import { StateContext } from "../../../context/dashboard/Provider";
|
|
|
import { DegreeDays } from "../../../types";
|
|
|
import * as classes from "../tables.module.css";
|
|
|
+import { campString, greenScale } from "../../../utils";
|
|
|
|
|
|
-interface DegreesProps {
|
|
|
- title: String;
|
|
|
- periodString: String;
|
|
|
-}
|
|
|
+interface DegreesProps {}
|
|
|
|
|
|
-// TODO: Computar el string de temporada
|
|
|
-// Consigue un string para que el usuario identifique la temporada que esta viendo
|
|
|
-const campString = (ISOFrom: string, ISOTo: string) => {
|
|
|
- const from = new Date(Date.parse(ISOFrom));
|
|
|
- const to = new Date(Date.parse(ISOTo));
|
|
|
+const colorScale = greenScale([0, 60]);
|
|
|
+const ResultTd = ({ value }: any) => (
|
|
|
+ <td
|
|
|
+ className={classes.cell}
|
|
|
+ style={{ backgroundColor: colorScale(value).css() as any }}
|
|
|
+ >
|
|
|
+ {value ?? "-"}
|
|
|
+ </td>
|
|
|
+);
|
|
|
|
|
|
- return `${ISOFrom.slice(0, 10)} / ${ISOTo.slice(0, 10)}`;
|
|
|
-};
|
|
|
-
|
|
|
-const DegreeDay: FC<DegreesProps> = ({ title, periodString }) => {
|
|
|
+const DegreeDay: FC<DegreesProps> = () => {
|
|
|
const [data, setData] = useState<DegreeDays[] | null>(null);
|
|
|
const { userToken } = useContext(UserStateContext);
|
|
|
const { from, to, sector } = useContext(StateContext);
|
|
|
@@ -29,30 +28,27 @@ const DegreeDay: FC<DegreesProps> = ({ title, periodString }) => {
|
|
|
monthlyDegrees(from, to, sector, userToken).then(setData);
|
|
|
}, [from, to, userToken, sector]);
|
|
|
|
|
|
- const suffix = "Grados días promedio mensuales";
|
|
|
-
|
|
|
const rows = data?.map((x) => (
|
|
|
<tr key={x.initial_date}>
|
|
|
<th className={classes.cell}>
|
|
|
{campString(x.initial_date, x.final_date)}
|
|
|
</th>
|
|
|
- <td className={classes.cell}>{x.months[10] ?? "-"}</td>
|
|
|
- <td className={classes.cell}>{x.months[11] ?? "-"}</td>
|
|
|
- <td className={classes.cell}>{x.months[12] ?? "-"}</td>
|
|
|
- <td className={classes.cell}>{x.months[1] ?? "-"}</td>
|
|
|
- <td className={classes.cell}>{x.months[2] ?? "-"}</td>
|
|
|
- <td className={classes.cell}>{x.months[3] ?? "-"}</td>
|
|
|
+ <ResultTd value={x.months[10]} />
|
|
|
+ <ResultTd value={x.months[11]} />
|
|
|
+ <ResultTd value={x.months[12]} />
|
|
|
+ <ResultTd value={x.months[1]} />
|
|
|
+ <ResultTd value={x.months[2]} />
|
|
|
+ <ResultTd value={x.months[3]} />
|
|
|
</tr>
|
|
|
));
|
|
|
|
|
|
return (
|
|
|
<section>
|
|
|
- <h3>{`${title} - ${suffix}`}</h3>
|
|
|
-
|
|
|
+ <h5>Grados días promedio mensuales</h5>
|
|
|
<table className={classes.table}>
|
|
|
<thead>
|
|
|
<tr>
|
|
|
- <th className={classes.cell}>{periodString}</th>
|
|
|
+ <th className={classes.cell}>Temporada</th>
|
|
|
<td className={classes.cell}>Octubre</td>
|
|
|
<td className={classes.cell}>Noviembre</td>
|
|
|
<td className={classes.cell}>Diciembre</td>
|