Skip to content

Commit 4d9c5af

Browse files
committed
fix: clearing tags, project, due or wait never reached the replica
The recur and priority fixes established the convention: a cleared field is transmitted as an empty string, because toJson drops null keys and an absent key tells the FFI nothing. Four fields had not followed it: - tags were sent only when non-empty, so deleting the last chip transmitted nothing and the task kept its old tags while the editor claimed otherwise. The set is now sent on every save — the FFI already replaces the whole tag set, so an empty value removes them all - project sent null for None (clear never transmitted) and passed an emptied field through as "", which set_value stored — a task whose project is literally named "". None and empty now both send '', the FFI treats empty as removal on update and as "not set" at creation, and a stored "" from an older build renders as None and is scrubbed on the next save - due and wait sent null for None, so even if a clear had existed in the UI it would not have transmitted. They now send '' (parse_datetime treats empty as removal). A parse failure still sends nothing: omitting keeps the old date, which is the right failure mode when the alternative is deleting a date the user never asked to lose There was also no way to clear a date at all — the picker offers no "no date" option, so a due or wait, once set, was permanent. The rows now carry a clear button when a date is present. It is withheld for due while a repeat is set, because a recurring task without a due date is exactly the state the FFI refuses (the desktop CLI deletes such a task on its next run). Tested: four new Rust tests pin the clear semantics for project, tags and due (39 pass). Verified on device against fresh replica reads: cleared the last tag, the project and the due date, saved, reopened — all three stayed cleared.
1 parent 77a30cc commit 4d9c5af

6 files changed

Lines changed: 171 additions & 9 deletions

File tree

-104 Bytes
Binary file not shown.
216 Bytes
Binary file not shown.
128 Bytes
Binary file not shown.

‎lib/app/modules/taskc_details/controllers/taskc_details_controller.dart‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ class TaskcDetailsController extends GetxController {
7070
isBlocking = false.obs;
7171
} else if (task is TaskForReplica) {
7272
description = (task.description ?? '').obs;
73-
project = (task.project ?? 'None').obs;
73+
// Empty-string is what an older build stored when the project field was
74+
// cleared; render it as None like a missing one.
75+
project = ((task.project == null || task.project!.isEmpty)
76+
? 'None'
77+
: task.project!)
78+
.obs;
7479
status = (task.status ?? '').obs;
7580
// Normalise the sentinels older builds stored as literal priorities ('X'
7681
// from the add sheet's "no priority" chip, 'None' from this screen) so
@@ -537,7 +542,11 @@ class TaskcDetailsController extends GetxController {
537542
final modifiedTask = TaskForReplica(
538543
modified: nowEpoch,
539544
due: () {
540-
if (due.string == 'None' || due.string.isEmpty) return null;
545+
// Empty transmits the clear (the FFI removes the date); null would
546+
// drop the key and the old date would silently survive. A parse
547+
// failure still returns null — omitting is the safe direction there,
548+
// since sending '' would delete a date the user never asked to lose.
549+
if (due.string == 'None' || due.string.isEmpty) return '';
541550
try {
542551
final parsed = DateFormat(datePattern).parse(due.string);
543552
return parsed.toUtc().toIso8601String();
@@ -570,7 +579,8 @@ class TaskcDetailsController extends GetxController {
570579
}
571580
}(),
572581
wait: () {
573-
if (wait.string == 'None' || wait.string.isEmpty) return null;
582+
// Same clear semantics as due.
583+
if (wait.string == 'None' || wait.string.isEmpty) return '';
574584
try {
575585
final parsed = DateFormat(datePattern).parse(wait.string);
576586
return parsed.toUtc().toIso8601String();
@@ -596,14 +606,21 @@ class TaskcDetailsController extends GetxController {
596606
? (status.string == 'recurring' ? 'pending' : status.string)
597607
: null),
598608
description: description.string.isNotEmpty ? description.string : null,
599-
tags: tags.isNotEmpty ? tags.toList() : null,
609+
// Always sent, even empty: the FFI replaces the whole tag set on every
610+
// save, and null just drops the key — so deleting the last chip used
611+
// to transmit nothing and the task kept its old tags.
612+
tags: tags.toList(),
600613
uuid: initialTask.uuid ?? '',
601614
// 'None' maps to an empty string, which the FFI treats as removal —
602615
// null would simply drop the key from the payload, so picking None
603616
// used to store the literal string "None" and a clear never
604617
// transmitted (the same trap recur had).
605618
priority: priority.string == 'None' ? '' : priority.string,
606-
project: project.string != 'None' ? project.string : null,
619+
// 'None' and an emptied field both mean "no project", sent as an empty
620+
// string because the FFI treats empty as removal — null drops the key
621+
// and transmits nothing, so clearing a project used to either do
622+
// nothing or (via an emptied field) store a project literally named "".
623+
project: project.string == 'None' ? '' : project.string.trim(),
607624
// Sent as part of the same edit rather than as its own write, because
608625
// the FFI validates recurrence against the due date — and the user may
609626
// legitimately set both in one go.

‎lib/app/modules/taskc_details/views/taskc_details_view.dart‎

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ class TaskcDetailsView extends GetView<TaskcDetailsController> {
8383
'${SentenceManager(currentLanguage: AppSettings.selectedLanguage).sentences.homePageDue}:',
8484
controller.due.value,
8585
() => controller.pickDateTime(controller.due),
86+
// No clear while a repeat is set: a recurring task without a
87+
// due date is exactly what the FFI refuses (the desktop CLI
88+
// deletes such a task), so don't offer the dead end.
89+
onClear: controller.isReplicaTask &&
90+
controller.due.value != 'None' &&
91+
controller.due.value.isNotEmpty &&
92+
controller.recur.value.trim().isEmpty
93+
? () => controller.updateField(controller.due, 'None')
94+
: null,
8695
),
8796
// Start / Wait: editable date pickers for replica tasks, read-only otherwise
8897
if (controller.isReplicaTask) ...[
@@ -106,6 +115,10 @@ class TaskcDetailsView extends GetView<TaskcDetailsController> {
106115
'${SentenceManager(currentLanguage: AppSettings.selectedLanguage).sentences.detailPageWait}:',
107116
controller.wait.value,
108117
() => controller.pickDateTime(controller.wait),
118+
onClear: controller.wait.value != 'None' &&
119+
controller.wait.value.isNotEmpty
120+
? () => controller.updateField(controller.wait, 'None')
121+
: null,
109122
),
110123
] else ...[
111124
_buildDetail(
@@ -266,11 +279,28 @@ class TaskcDetailsView extends GetView<TaskcDetailsController> {
266279
}
267280

268281
Widget _buildDatePickerDetail(
269-
BuildContext context, String label, String value, VoidCallback onTap) {
270-
return InkWell(
282+
BuildContext context, String label, String value, VoidCallback onTap,
283+
{VoidCallback? onClear}) {
284+
final TaskwarriorColorTheme tColors =
285+
Theme.of(context).extension<TaskwarriorColorTheme>()!;
286+
final Widget row = InkWell(
271287
onTap: onTap,
272288
child: _buildDetail(context, label, value),
273289
);
290+
// The picker has no "no date" option, so without this a date, once set,
291+
// could never be removed.
292+
if (onClear == null) return row;
293+
return Stack(
294+
alignment: Alignment.centerRight,
295+
children: [
296+
row,
297+
IconButton(
298+
icon: Icon(Icons.clear, size: 18, color: tColors.secondaryTextColor),
299+
tooltip: 'Clear',
300+
onPressed: onClear,
301+
),
302+
],
303+
);
274304
}
275305

276306
/// Tasks this one is waiting on, with add and remove.

‎rust/src/api.rs‎

Lines changed: 117 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,20 @@ fn update_task_impl(
165165
}
166166
}
167167
"project" => {
168-
let _ = t.set_value("project", Some(value), &mut ops);
168+
// Empty removes, mirroring priority and recur. Storing
169+
// Some("") left a blank-valued property behind: the task
170+
// then had a project named "", which surfaced in project
171+
// lists and never matched anything.
172+
let trimmed = value.trim();
173+
let _ = t.set_value(
174+
"project",
175+
if trimmed.is_empty() {
176+
None
177+
} else {
178+
Some(trimmed.to_string())
179+
},
180+
&mut ops,
181+
);
169182
}
170183
// Stored like `project`: an opaque string TaskChampion keeps but
171184
// never interprets. Unlike `project`, nothing in this app acts on
@@ -282,7 +295,12 @@ fn add_task_impl(taskdb_dir_path: &str, map: HashMap<String, String>) -> Result<
282295
}
283296
}
284297
"project" => {
285-
let _ = t.set_user_defined_attribute("project", value, &mut ops);
298+
// Nothing to clear on a brand-new task; empty means "not set".
299+
let trimmed = value.trim();
300+
if !trimmed.is_empty() {
301+
let _ =
302+
t.set_user_defined_attribute("project", trimmed.to_string(), &mut ops);
303+
}
286304
}
287305
// Both of these used to fall into the catch-all below. Replica.attrs
288306
// on the Dart side lists them as round-trippable and sends them
@@ -1555,3 +1573,100 @@ mod priority_tests {
15551573
fs::remove_dir_all(&tmp).ok();
15561574
}
15571575
}
1576+
1577+
#[cfg(test)]
1578+
mod clear_semantics_tests {
1579+
//! Clearing a field must remove its property, not leave a blank-valued
1580+
//! one behind — and the Dart side clears by sending an empty string,
1581+
//! because an omitted key transmits nothing at all.
1582+
use super::*;
1583+
use serde_json::Value;
1584+
use std::{collections::HashMap, env, fs};
1585+
1586+
fn fixture(pairs: &[(&str, &str)]) -> (std::path::PathBuf, String, String) {
1587+
let tmp = env::temp_dir().join(format!("taskdb_clear_{}", Uuid::new_v4()));
1588+
fs::create_dir_all(&tmp).expect("create temp taskdb dir");
1589+
let path = tmp.to_string_lossy().into_owned();
1590+
1591+
let uuid = Uuid::new_v4().to_string();
1592+
let mut map: HashMap<String, String> = HashMap::new();
1593+
map.insert("uuid".to_string(), uuid.clone());
1594+
map.insert("description".to_string(), "chore".to_string());
1595+
for (k, v) in pairs {
1596+
map.insert(k.to_string(), v.to_string());
1597+
}
1598+
add_task(path.clone(), map).expect("add_task");
1599+
(tmp, path, uuid)
1600+
}
1601+
1602+
fn task_json(path: &str, uuid: &str) -> Value {
1603+
let json = get_all_tasks_json(path.to_string()).expect("get_all_tasks_json");
1604+
let tasks: Vec<Value> = serde_json::from_str(&json).expect("parse json");
1605+
tasks
1606+
.into_iter()
1607+
.find(|t| t.get("uuid").and_then(|u| u.as_str()) == Some(uuid))
1608+
.expect("task exists")
1609+
}
1610+
1611+
fn update(path: &str, uuid: &str, pairs: &[(&str, &str)]) {
1612+
let map: HashMap<String, String> = pairs
1613+
.iter()
1614+
.map(|(k, v)| (k.to_string(), v.to_string()))
1615+
.collect();
1616+
update_task(uuid.to_string(), path.to_string(), map).expect("update_task");
1617+
}
1618+
1619+
#[test]
1620+
fn empty_project_on_update_removes_the_property() {
1621+
let (tmp, path, uuid) = fixture(&[("project", "work")]);
1622+
assert_eq!(
1623+
task_json(&path, &uuid)["project"].as_str(),
1624+
Some("work")
1625+
);
1626+
1627+
update(&path, &uuid, &[("project", "")]);
1628+
1629+
// Removed, not stored as a task whose project is named "".
1630+
assert!(task_json(&path, &uuid).get("project").is_none());
1631+
fs::remove_dir_all(&tmp).ok();
1632+
}
1633+
1634+
#[test]
1635+
fn empty_project_at_creation_is_not_stored() {
1636+
let (tmp, path, uuid) = fixture(&[("project", "")]);
1637+
assert!(task_json(&path, &uuid).get("project").is_none());
1638+
fs::remove_dir_all(&tmp).ok();
1639+
}
1640+
1641+
#[test]
1642+
fn empty_tags_on_update_removes_every_tag() {
1643+
let (tmp, path, uuid) = fixture(&[("tags", "one two")]);
1644+
let json = task_json(&path, &uuid);
1645+
let mut stored: Vec<&str> = json["tags"]
1646+
.as_str()
1647+
.unwrap_or("")
1648+
.split_whitespace()
1649+
.collect();
1650+
stored.sort_unstable();
1651+
// Order is unspecified (the taskmap is a hash map), so compare as a set.
1652+
assert_eq!(stored, vec!["one", "two"], "both tags stored at creation");
1653+
1654+
// The Dart side sends the full replacement set on every save; deleting
1655+
// the last chip makes that set empty.
1656+
update(&path, &uuid, &[("tags", "")]);
1657+
1658+
assert_eq!(task_json(&path, &uuid)["tags"].as_str(), Some(""));
1659+
fs::remove_dir_all(&tmp).ok();
1660+
}
1661+
1662+
#[test]
1663+
fn empty_due_on_update_removes_it_for_a_plain_task() {
1664+
let (tmp, path, uuid) = fixture(&[("due", "2026-09-01T09:00:00Z")]);
1665+
assert!(task_json(&path, &uuid).get("due").is_some());
1666+
1667+
update(&path, &uuid, &[("due", "")]);
1668+
1669+
assert!(task_json(&path, &uuid).get("due").is_none());
1670+
fs::remove_dir_all(&tmp).ok();
1671+
}
1672+
}

0 commit comments

Comments
 (0)