-
Notifications
You must be signed in to change notification settings - Fork 158
fix: Inline validation for empty and duplicate tags in Tag Editor #586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -99,17 +99,27 @@ class TagsRouteState extends State<TagsRoute> { | |||||
| Map<String, TagMetadata>? _pendingTags; | ||||||
| ListBuilder<String>? draftTags; | ||||||
|
|
||||||
| void _addTag(String tag) { | ||||||
| if (tag.isNotEmpty) { | ||||||
| // Add this condition to ensure the tag is not empty | ||||||
| if (draftTags == null) { | ||||||
| draftTags = ListBuilder([tag]); | ||||||
| } else { | ||||||
| List<String> _parseTags(String input) { | ||||||
| return input | ||||||
| .split(',') | ||||||
| .map((e) => e.trim()) | ||||||
| .where((e) => e.isNotEmpty) | ||||||
| .toList(); | ||||||
| } | ||||||
|
|
||||||
| void _addTags(List<String> tags) { | ||||||
| if (tags.isEmpty) return; | ||||||
|
|
||||||
| draftTags ??= ListBuilder<String>(); | ||||||
|
|
||||||
| for (final tag in tags) { | ||||||
| if (!draftTags!.build().contains(tag)) { | ||||||
| draftTags!.add(tag); | ||||||
| } | ||||||
| widget.callback(draftTags); | ||||||
| setState(() {}); | ||||||
| } | ||||||
|
|
||||||
| widget.callback(draftTags); | ||||||
| setState(() {}); | ||||||
| } | ||||||
|
|
||||||
| void _removeTag(String tag) { | ||||||
|
|
@@ -197,7 +207,7 @@ class TagsRouteState extends State<TagsRoute> { | |||||
| !(draftTags?.build().contains(tag.key) ?? false))) | ||||||
| FilterChip( | ||||||
| backgroundColor: TaskWarriorColors.grey, | ||||||
| onSelected: (_) => _addTag(tag.key), | ||||||
| onSelected: (_) => _addTags([tag.key]), | ||||||
| label: Text( | ||||||
| '${tag.key} ${tag.value.frequency}', | ||||||
| ), | ||||||
|
|
@@ -234,11 +244,22 @@ class TagsRouteState extends State<TagsRoute> { | |||||
| color: tColors.primaryTextColor, | ||||||
| ), | ||||||
| validator: (value) { | ||||||
| if (value != null) { | ||||||
| if (value.isNotEmpty && value.contains(" ")) { | ||||||
| final tags = _parseTags(value ?? ''); | ||||||
|
|
||||||
| if (tags.isEmpty) { | ||||||
| return "Please enter a tag"; | ||||||
| } | ||||||
|
|
||||||
| for (final tag in tags) { | ||||||
| if (tag.contains(' ')) { | ||||||
| return "Tags cannot contain spaces"; | ||||||
| } | ||||||
|
|
||||||
| if (draftTags?.build().contains(tag) ?? false) { | ||||||
|
||||||
| if (draftTags?.build().contains(tag) ?? false) { | |
| if (draftTags?.contains(tag) ?? false) { |
Copilot
AI
Feb 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validator introduces hard-coded English error strings ("Please enter a tag", "Tags cannot contain spaces", "Tag already exists"), which bypasses the app’s localization approach via SentenceManager (e.g., sentences.tagAlreadyExists, sentences.tagShouldNotContainSpaces). Please switch these to localized SentenceManager(...).sentences entries, and add a new sentences key for the empty-input message so it’s translated consistently.
Copilot
AI
Feb 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change introduces new validation behavior (empty input, duplicates, comma-separated submission, and keeping the dialog open on invalid submit), but there are no widget tests covering it. Please add a widget test for TagsRoute that asserts inline errors are shown and that the dialog only closes when a valid tag (or tag list) is submitted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
_addTags, callingdraftTags!.build()inside the loop allocates a new immutable list on every iteration. UsedraftTags!.contains(tag)(ListBuilder supportscontains) or build once before the loop / keep aSetfor membership checks to avoid repeated allocations and quadratic behavior as tags grow.