import React, { FunctionComponent, useState, useEffect, ChangeEvent, MouseEvent } from "react"; import style from "./style.module.css"; import { Project } from "../../models/project"; import { newTask, Task, TaskID, EstimationConfidence } from "../../models/task"; import EditableText from "../../components/editable-text"; import { usePrintMediaQuery } from "../../hooks/use-media-query"; import { defaults, getTimeUnit } from "../../models/params"; import ProjectTimeUnit from "../../components/project-time-unit"; export interface TaskTableProps { project: Project onTaskAdd: (task: Task) => void onTaskRemove: (taskId: TaskID) => void onEstimationChange: (taskId: TaskID, confidence: EstimationConfidence, value: number) => void onTaskLabelUpdate: (taskId: TaskID, label: string) => void } export type EstimationTotals = { [confidence in EstimationConfidence]: number } const TaskTable: FunctionComponent = ({ project, onTaskAdd, onEstimationChange, onTaskRemove, onTaskLabelUpdate }) => { const defaultTaskCategory = Object.keys(project.params.taskCategories)[0]; const [ task, setTask ] = useState(newTask("", defaultTaskCategory)); const [ totals, setTotals ] = useState({ [EstimationConfidence.Optimistic]: 0, [EstimationConfidence.Likely]: 0, [EstimationConfidence.Pessimistic]: 0, } as EstimationTotals); const isPrint = usePrintMediaQuery(); useEffect(() => { let optimistic = 0; let likely = 0; let pessimistic = 0; Object.values(project.tasks).forEach(t => { optimistic += t.estimations.optimistic; likely += t.estimations.likely; pessimistic += t.estimations.pessimistic; }); setTotals({ optimistic, likely, pessimistic }); }, [project.tasks]); const onNewTaskLabelChange = (evt: ChangeEvent) => { const value = (evt.currentTarget as HTMLInputElement).value; setTask({...task, label: value}); }; const onNewTaskCategoryChange = (evt: ChangeEvent) => { const value = (evt.currentTarget as HTMLInputElement).value; setTask({...task, category: value}); }; const onTaskLabelChange = (taskId: TaskID, value: string) => { onTaskLabelUpdate(taskId, value); }; const onAddTaskClick = (evt: MouseEvent) => { onTaskAdd(task); setTask(newTask("", defaultTaskCategory)); }; const onTaskRemoveClick = (taskId: TaskID, evt: MouseEvent) => { onTaskRemove(taskId); }; const withEstimationChange = (confidence: EstimationConfidence, taskID: TaskID, evt: ChangeEvent) => { const textValue = (evt.currentTarget as HTMLInputElement).value; const value = parseFloat(textValue); onEstimationChange(taskID, confidence, value); }; const onOptimisticChange = withEstimationChange.bind(null, EstimationConfidence.Optimistic); const onLikelyChange = withEstimationChange.bind(null, EstimationConfidence.Likely); const onPessimisticChange = withEstimationChange.bind(null, EstimationConfidence.Pessimistic); return (
{ Object.values(project.tasks).map(t => { const category = project.params.taskCategories[t.category]; const categoryLabel = category ? category.label : '???'; return ( ) }) } { Object.keys(project.tasks).length === 0 ? : null }
Tâche Catégorie Estimation (en )
Optimiste Probable Pessimiste
({value})} onChange={onTaskLabelChange.bind(null, t.id)} value={t.label} /> { categoryLabel } { isPrint ? {t.estimations.optimistic} : } { isPrint ? {t.estimations.likely} : } { isPrint ? {t.estimations.pessimistic} : }
Aucune tâche pour l'instant.

Ajouter

Total
{totals.optimistic} {totals.likely} {totals.pessimistic}
); }; export default TaskTable;