Skip to content

Commit a5ec97b

Browse files
authored
fix(categories): filter null/empty segments before saving class name (#902)
* fix(categories): filter null/empty segments before saving class name When editing a category with the Parent field set to "None" and the name untouched, [].concat(this.editing.name) could produce [null] because this.editing.name is initialized from cat.subname which may be null/undefined for freshly-created or corrupted classes. Any such null value gets written into settings.json under classes[].name and later serialized into the categorize() query, where the query interpreter treats it as a variable reference and raises QueryInterpretException: Tried to reference variable 'null' which is not defined breaking every chart that uses categorize(). Guard handleSubmit() so that: - parent is coerced to [] if it is not an array - null/undefined/empty-string segments are dropped from the final name - if nothing remains (no parent, no name), save is aborted silently Fixes ActivityWatch/activitywatch#1355 * fix(categories): require leaf name to be valid; do not collapse into parent Address greptile review on #902: the previous version filtered null/undef/'' from the concatenated (parent + name) array as a whole. If the user cleared the Name field on a child category, the leaf would be dropped and the resulting name would equal the parent's name, effectively overwriting the child into a duplicate of its parent. Split the check: - filter null/undef/'' out of the parent segments - abort the save entirely if the leaf (editing.name) itself is invalid, so an empty name never silently collapses a child into its parent. --------- Co-authored-by: fanxing11 <fanxing11@users.noreply.github.com>
1 parent 464405d commit a5ec97b

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

‎src/components/CategoryEditModal.vue‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,23 @@ export default {
145145
}
146146
147147
// Save the category
148+
// Guard against null/undefined/empty segments (e.g. when parent is "None"
149+
// and subname was never touched, or when a corrupted class was loaded).
150+
// Without this, [].concat(null) or [null].concat(x) writes `null` into
151+
// classes[].name, which the query engine then tries to resolve as the
152+
// variable `null` and throws QueryInterpretException, breaking all
153+
// charts that call categorize(). See #1355.
154+
const isValid = s => s !== null && s !== undefined && s !== '';
155+
const parent = Array.isArray(this.editing.parent) ? this.editing.parent.filter(isValid) : [];
156+
// The leaf name must be valid on its own — do NOT let a blank name
157+
// silently collapse a child into its parent's path.
158+
if (!isValid(this.editing.name)) {
159+
return;
160+
}
161+
const nameSegments = parent.concat(this.editing.name);
148162
const new_class = {
149163
id: this.editing.id,
150-
name: this.editing.parent.concat(this.editing.name),
164+
name: nameSegments,
151165
rule: this.editing.rule.type !== 'none' ? this.editing.rule : { type: 'none' },
152166
data: {
153167
color: this.editing.inherit_color === true ? undefined : this.editing.color,

0 commit comments

Comments
 (0)