Add quantitative tasks with checklist controls to the planner
All checks were successful
Validate and deploy Sokko G / validate (push) Successful in 17m38s
Validate and deploy Sokko G / deploy (push) Successful in 9s

This commit is contained in:
Shinuwa 2026-10-24 15:02:33 +02:00
parent 29fcb50fcd
commit c08452d5a4
22 changed files with 434 additions and 33 deletions

View file

@ -2,11 +2,13 @@
import { Icon } from "../../../components/Icon.jsx";
import { useInlineEdit } from "../../../hooks/useInlineEdit.js";
import { MissingPrerequisitesTooltip, TaskPlannerItemDetails } from "./TaskPlannerItemPanels.jsx";
import { TaskPlannerQuantity } from "./TaskPlannerQuantity.jsx";
import {
TASK_TYPES,
getTaskCategoryDataset,
getTaskTypeLabel,
isTaskResetSoon
isTaskResetSoon,
updateTaskQuantity
} from "./taskPlannerUtils.js";
export function TaskPlannerItem({
@ -51,14 +53,9 @@ export function TaskPlannerItem({
onCommit: (title) => onUpdateTask(task.id, (current) => ({ ...current, title }))
});
function updateChecked(event) {
const checked = event.target.checked;
if (checked && missingPrerequisites.length > 0) onPrerequisiteNotice(task.id);
onUpdateTask(task.id, (current) => ({
...current,
checked,
checkedAt: checked ? Date.now() : 0
}));
function updateQuantity(value) {
if (Number(value) >= (task.qtyTarget || 1) && !task.checked && missingPrerequisites.length > 0) onPrerequisiteNotice(task.id);
onUpdateTask(task.id, (current) => updateTaskQuantity(current, value));
}
return (
@ -75,14 +72,18 @@ export function TaskPlannerItem({
>
<Icon name="drag" />
</button>
<input
className="nds-checkbox"
data-size="sm"
type="checkbox"
checked={task.checked}
onChange={updateChecked}
aria-label={`${task.checked ? textContent.uncheckTitle || "Marquer non effectué" : textContent.checkTitle || "Marquer effectué"} ${task.title}`}
/>
{task.qtyTarget > 1 ? (
<TaskPlannerQuantity task={task} textContent={textContent} onChange={updateQuantity} />
) : (
<input
className="nds-checkbox"
data-size="sm"
type="checkbox"
checked={task.checked}
onChange={(event) => updateQuantity(event.target.checked ? 1 : 0)}
aria-label={`${task.checked ? textContent.uncheckTitle || "Marquer non effectué" : textContent.checkTitle || "Marquer effectué"} ${task.title}`}
/>
)}
<input
{...titleEdit.getInputProps({
className: "tool-split-entry-label task-planner-title-input nds-inline-input",

View file

@ -3,6 +3,7 @@ import { Icon } from "../../../components/Icon.jsx";
import { InlineNotice } from "../../../components/AppOverlays.jsx";
import { Tooltip } from "../../../components/Tooltip.jsx";
import { useInlineEdit } from "../../../hooks/useInlineEdit.js";
import { TaskPlannerQuantityTarget } from "./TaskPlannerQuantity.jsx";
import {
WEEK_DAYS,
getEffectiveTaskCategory,
@ -65,7 +66,10 @@ export function TaskPlannerItemDetails({
)}
{settingsOpen && (
<div className="task-planner-task-settings">
<TaskResetSettings task={task} data={data} textContent={textContent} onUpdateTask={onUpdateTask} />
<div className="task-planner-task-fields">
<TaskPlannerQuantityTarget task={task} textContent={textContent} onUpdateTask={onUpdateTask} />
<TaskResetSettings task={task} data={data} textContent={textContent} onUpdateTask={onUpdateTask} />
</div>
<LinksEditor
label={textContent.linksLabel || "Parent"}
relations={relations}

View file

@ -9,14 +9,15 @@ import { TaskPlannerTopbar } from "./TaskPlannerTopbar.jsx";
import { TextExchangeActions } from "./TextExchangeActions.jsx";
import {
applyDueResets,
getTaskParentMap
getTaskParentMap,
updateTaskQuantityTarget
} from "./taskPlannerUtils.js";
import { useTaskPlannerReorder } from "./useTaskPlannerReorder.js";
export function TaskPlannerModule({ toolboxId, moduleId, context, editing, configurationTarget }) {
const data = context.normalizeTaskPlannerData(context.getModuleData(toolboxId, moduleId, { tasks: [] }));
const textContent = context.moduleText?.taskPlanner || {};
const taskDraft = useDraftForm({ title: "", type: "daily", category: "" });
const taskDraft = useDraftForm({ title: "", type: "daily", category: "", qtyTarget: "1" });
const categoryOptions = useMemo(() => [
...data.categoryOrder,
...data.tasks.map((task) => task.category).filter(Boolean).filter((category) => !data.categoryOrder.includes(category))
@ -63,7 +64,7 @@ export function TaskPlannerModule({ toolboxId, moduleId, context, editing, confi
if (category) task.category = category;
save({
...data,
tasks: [...data.tasks, task],
tasks: [...data.tasks, updateTaskQuantityTarget(task, draft.qtyTarget)],
categoryOrder: category && !data.categoryOrder.includes(category) ? [...data.categoryOrder, category] : data.categoryOrder
});
reset();

View file

@ -0,0 +1,40 @@
// Rôle : affiche la progression quantitative et l'édition de la cible d'une tâche.
import { useInlineEdit } from "../../../hooks/useInlineEdit.js";
import { updateTaskQuantityTarget } from "./taskPlannerUtils.js";
import { parsePositiveInt } from "../storage/modules/shared.js";
export function TaskPlannerQuantity({ task, textContent, onChange }) {
return (
<div className="task-planner-quantity nds-quantity-stepper" data-size="md">
<button type="button" onClick={() => onChange(task.qtyCurrent - 1)} aria-label={`${textContent.decrementLabel} ${task.title}`}>-</button>
<label className="nds-quantity-stepper-value">
<input
className="nds-quantity-stepper-input"
type="number"
max={task.qtyTarget}
step="1"
value={task.qtyCurrent}
style={{ "--qty-current-digits": String(task.qtyCurrent).length }}
onChange={(event) => onChange(event.target.value)}
aria-label={`${textContent.currentQuantityLabel} ${task.title}`}
/>
<span>/ {task.qtyTarget}</span>
</label>
<button type="button" onClick={() => onChange(task.qtyCurrent + 1)} aria-label={`${textContent.incrementLabel} ${task.title}`}>+</button>
</div>
);
}
export function TaskPlannerQuantityTarget({ task, textContent, onUpdateTask }) {
const targetEdit = useInlineEdit({
value: task.qtyTarget || 1,
transform: (value) => parsePositiveInt(value, 1),
onCommit: (value) => onUpdateTask(task.id, (current) => updateTaskQuantityTarget(current, value))
});
return (
<label className="task-planner-reset-override">
<span>{textContent.quantityLabel}</span>
<input {...targetEdit.getInputProps({ className: "nds-input", "data-size": "sm", type: "number", min: 1, step: 1, "aria-label": `${textContent.quantityLabel} ${task.title}` })} />
</label>
);
}

View file

@ -39,6 +39,7 @@ export function TaskPlannerTopbar({
<select {...taskDraft.getFieldProps("type", { className: "nds-select", "data-size": "sm", "aria-label": textContent.typeLabel || "Type" })}>
{TASK_TYPES.map((taskType) => <option key={taskType} value={taskType}>{getTaskTypeLabel(taskType, textContent)}</option>)}
</select>
<input {...taskDraft.getFieldProps("qtyTarget", { className: "task-planner-quantity-target nds-input", "data-size": "sm", type: "number", min: 1, step: 1, "aria-label": textContent.quantityLabel, title: textContent.quantityLabel })} />
<button className="nds-button" data-size="sm" data-variant="primary">{textContent.addButton || "Ajouter"}</button>
</form>
</div>

View file

@ -1,10 +1,36 @@
// Rôle : regroupe les constantes et helpers purs de l'outil task planner.
import { getLatestDailyReset, getLatestWeeklyReset, parseResetTime } from "./resetUtils.js";
import { clampQty } from "../storage/modules/checklist.js";
import { parsePositiveInt } from "../storage/modules/shared.js";
export const TASK_TYPES = ["daily", "weekly", "unique"];
const DAILY_RESET_SOON_MS = 6 * 60 * 60 * 1000;
const WEEKLY_RESET_SOON_MS = 48 * 60 * 60 * 1000;
export function updateTaskQuantity(task, value, now = Date.now()) {
const qtyCurrent = clampQty(value, task.qtyTarget || 1);
const checked = qtyCurrent >= (task.qtyTarget || 1);
const next = { ...task, checked, checkedAt: checked ? now : 0 };
if (task.qtyTarget > 1) {
next.qtyCurrent = qtyCurrent;
next.progressAt = qtyCurrent !== 0 ? now : 0;
}
return next;
}
export function updateTaskQuantityTarget(task, value, now = Date.now()) {
const qtyTarget = parsePositiveInt(value, 1);
if (qtyTarget === (task.qtyTarget || 1)) return task;
const qtyCurrent = task.qtyTarget > 1 ? task.qtyCurrent : task.checked ? 1 : 0;
const next = updateTaskQuantity({ ...task, qtyTarget }, qtyCurrent, now);
if (qtyTarget === 1) {
delete next.qtyTarget;
delete next.qtyCurrent;
delete next.progressAt;
}
return next;
}
export const WEEK_DAYS = [
{ value: 1, label: "Lundi" },
{ value: 2, label: "Mardi" },
@ -63,9 +89,10 @@ export function applyDueResets(data, now = Date.now()) {
? getLatestDailyReset(now, task.dailyResetTime || data.resetTime)
: getLatestWeeklyReset(now, data.resetTime, task.weeklyResetDay ?? data.weeklyResetDay);
latestResetAt = Math.max(latestResetAt, resetAt);
if (!task.checked || resetAt <= (task.checkedAt || data.lastResetAt)) return task;
const hasProgress = task.checked || (task.qtyTarget > 1 && task.qtyCurrent !== 0);
if (!hasProgress || resetAt <= (task.progressAt || task.checkedAt || data.lastResetAt)) return task;
changed = true;
return { ...task, checked: false, checkedAt: 0 };
return updateTaskQuantity(task, 0, now);
});
if (latestResetAt > data.lastResetAt) changed = true;

View file

@ -16,6 +16,7 @@ export function exportTaskPlannerText(data) {
function writeTask(task, depth = 0) {
const prefix = " ".repeat(depth);
lines.push(`${prefix}- ${task.type || "unique"} ${task.title}`);
if (task.qtyTarget > 1) lines.push(`${prefix} @qtyTarget: ${task.qtyTarget}`);
if (task.description) lines.push(`${prefix} @description: ${task.description.replace(/\n/g, "\\n")}`);
if (task.dailyResetTime) lines.push(`${prefix} @dailyResetTime: ${task.dailyResetTime}`);
if (task.weeklyResetDay !== undefined) lines.push(`${prefix} @weeklyResetDay: ${task.weeklyResetDay}`);
@ -61,6 +62,11 @@ export function importTaskPlannerText(text, context) {
if (meta) {
const task = stack[Math.max(0, depth - 1)];
if (!task) throw lineError(index, `meta de tâche sans tâche: ${cleanLine}`);
if (meta.key === "qtyTarget") {
const target = Number(meta.value);
if (!Number.isSafeInteger(target) || target < 1) throw lineError(index, "quantité cible invalide.");
task.qtyTarget = target;
}
if (meta.key === "description") task.description = meta.value.replace(/\\n/g, "\n");
if (meta.key === "dailyResetTime") task.dailyResetTime = meta.value;
if (meta.key === "weeklyResetDay") task.weeklyResetDay = parseInteger(meta.value, 1);

View file

@ -1,5 +1,6 @@
// Rôle : normalise et compacte les données persistées du task planner.
import { normalizeTimestamp, uid } from "./shared.js";
import { normalizeTimestamp, parsePositiveInt, uid } from "./shared.js";
import { clampQty } from "./checklist.js";
export const DEFAULT_TASK_PLANNER_WEEKLY_RESET_DAY = 1;
export const DEFAULT_TASK_PLANNER_RESET_TIME = "00:00";
@ -28,6 +29,14 @@ function normalizeTaskPlannerTask(task) {
checked: task?.checked === true,
checkedAt: normalizeTimestamp(task?.checkedAt)
};
const qtyTarget = parsePositiveInt(task?.qtyTarget, 1);
if (qtyTarget > 1) {
normalized.qtyTarget = qtyTarget;
normalized.qtyCurrent = clampQty(task?.qtyCurrent, qtyTarget);
normalized.progressAt = normalized.qtyCurrent !== 0 ? normalizeTimestamp(task?.progressAt) : 0;
normalized.checked = normalized.qtyCurrent >= qtyTarget;
normalized.checkedAt = normalized.checked ? normalized.progressAt : 0;
}
if (category) normalized.category = category;
if (type === "daily" && isClockTimeString(task?.dailyResetTime)) normalized.dailyResetTime = task.dailyResetTime;
if (type === "weekly" && task?.weeklyResetDay !== undefined) normalized.weeklyResetDay = normalizeWeekDay(task.weeklyResetDay);
@ -110,8 +119,14 @@ export function compactTaskPlannerDataForStorage(value) {
const compactTask = { id: task.id, title: task.title, type: task.type };
if (task.description) compactTask.description = task.description;
if (task.category) compactTask.category = task.category;
if (task.checked) compactTask.checked = true;
if (task.checked && task.checkedAt) compactTask.checkedAt = task.checkedAt;
if (task.qtyTarget > 1) {
compactTask.qtyTarget = task.qtyTarget;
if (task.qtyCurrent !== 0) compactTask.qtyCurrent = task.qtyCurrent;
if (task.progressAt) compactTask.progressAt = task.progressAt;
} else {
if (task.checked) compactTask.checked = true;
if (task.checked && task.checkedAt) compactTask.checkedAt = task.checkedAt;
}
if (task.type === "daily" && task.dailyResetTime && task.dailyResetTime !== normalized.resetTime) compactTask.dailyResetTime = task.dailyResetTime;
if (task.type === "weekly" && task.weeklyResetDay !== undefined) compactTask.weeklyResetDay = task.weeklyResetDay;
return compactTask;

View file

@ -372,7 +372,7 @@
}
.task-planner-line {
grid-template-columns: 30px 24px minmax(0, 1fr) auto;
grid-template-columns: 30px minmax(24px, max-content) minmax(0, 1fr) auto;
}
.task-planner-type-select,

View file

@ -55,7 +55,7 @@
.task-planner-line {
display: grid;
grid-template-columns: 30px 24px minmax(0, 1fr) 134px auto auto;
grid-template-columns: 30px minmax(24px, max-content) minmax(0, 1fr) 134px auto auto;
gap: 8px;
align-items: center;
}
@ -127,3 +127,19 @@
text-overflow: ellipsis;
white-space: nowrap;
}
@container (max-width: 560px) {
.task-planner-line {
grid-template-columns: 30px minmax(24px, max-content) minmax(0, 1fr) auto;
}
.task-planner-type-select,
.task-planner-warning {
grid-column: 3 / -1;
}
.task-planner-actions {
grid-column: 4;
grid-row: 1;
}
}

View file

@ -62,6 +62,18 @@
align-items: center;
}
.task-planner-task-fields {
display: grid;
min-width: 0;
gap: 12px;
}
@container (max-width: 560px) {
.task-planner-task-settings {
grid-template-columns: minmax(0, 1fr);
}
}
.task-planner-reset-control button:disabled {
opacity: 0.42;
cursor: not-allowed;

View file

@ -2,6 +2,7 @@
@use "../../design-system/controls";
.task-planner-module {
container-type: inline-size;
display: grid;
gap: var(--space-4);
padding: var(--space-4);
@ -116,5 +117,21 @@
}
.task-planner-add-form {
grid-template-columns: minmax(0, 1fr) minmax(120px, 0.36fr) minmax(120px, 0.32fr) auto;
grid-template-columns: minmax(0, 1fr) minmax(100px, 0.36fr) minmax(110px, 0.32fr) 72px auto;
}
.task-planner-quantity-target {
width: 100%;
min-width: 0;
}
@container (max-width: 700px) {
.task-planner-add-form {
grid-template-columns: minmax(0, 1fr) 72px auto;
}
.task-planner-add-form > input[type="text"],
.task-planner-add-form > .nds-autocomplete-field {
grid-column: 1 / -1;
}
}