Skip to content

Commit 12d4c7d

Browse files
committed
refactor: - Rename Task.blockedBy to Task.dependsOn
This is to separate out the concepts of dependency and blocking.
1 parent 40d32ea commit 12d4c7d

24 files changed

+64
-63
lines changed

resources/sample_vaults/Tasks-Demo/Manual Testing/Dependencies Samples.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
- [ ] #task Craft a conclusion 🆔 0wigip ⛔️ mvplec
88
- [ ] #task Proofread and edit 🆔 5ti6bf ⛔️ 0wigip
99
- [ ] #task Publish the article ⛔️ 5ti6bf
10-
- [ ] #task Do something on a different project
10+
- [ ] #task Do something on a different project 🆔 g2q2hg
11+
- [ ] #task sadfadfa ⛔️ g2q2hg
1112

1213
---
1314

src/Commands/CreateOrEditTaskParser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export const taskFromLine = ({ line, path }: { line: string; path: string }): Ta
9191
doneDate: null,
9292
cancelledDate: null,
9393
recurrence: null,
94-
blockedBy: [],
94+
dependsOn: [],
9595
id: '',
9696
blockLink: '',
9797
tags: [],
@@ -136,6 +136,6 @@ export const taskFromLine = ({ line, path }: { line: string; path: string }): Ta
136136
// Not needed since the inferred status is always re-computed after submitting.
137137
scheduledDateIsInferred: false,
138138
id: '',
139-
blockedBy: [],
139+
dependsOn: [],
140140
});
141141
};

src/Layout/TaskLayoutOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export enum TaskLayoutComponent {
88
// NEW_TASK_FIELD_EDIT_REQUIRED
99
Description = 'description',
1010
Id = 'id',
11-
DependsOn = 'blockedBy',
11+
DependsOn = 'dependsOn',
1212
Priority = 'priority',
1313
RecurrenceRule = 'recurrenceRule',
1414
CreatedDate = 'createdDate',

src/Query/Filter/BlockedByField.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export class BlockedByField extends Field {
88

99
constructor() {
1010
super();
11-
this.filterInstructions.add('has blocked by', (task: Task) => task.blockedBy.length > 0);
12-
this.filterInstructions.add('no blocked by', (task: Task) => task.blockedBy.length === 0);
11+
this.filterInstructions.add('has blocked by', (task: Task) => task.dependsOn.length > 0);
12+
this.filterInstructions.add('no blocked by', (task: Task) => task.dependsOn.length === 0);
1313
}
1414

1515
// -----------------------------------------------------------------------------------------------------------------

src/Renderer/TaskFieldRenderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ const taskFieldHTMLData: { [c in TaskLayoutComponent]: TaskFieldHTMLData } = {
167167

168168
description: createFieldWithoutDataAttributes('task-description'),
169169
recurrenceRule: createFieldWithoutDataAttributes('task-recurring'),
170-
blockedBy: createFieldWithoutDataAttributes('task-blockedBy'),
170+
dependsOn: createFieldWithoutDataAttributes('task-blockedBy'),
171171
id: createFieldWithoutDataAttributes('task-id'),
172172
blockLink: createFieldWithoutDataAttributes('task-block-link'),
173173
};

src/Task/Task.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class Task {
5959

6060
public readonly recurrence: Recurrence | null;
6161

62-
public readonly blockedBy: string[];
62+
public readonly dependsOn: string[];
6363
public readonly id: string;
6464

6565
/** The blockLink is a "^" annotation after the dates/recurrence rules.
@@ -91,7 +91,7 @@ export class Task {
9191
doneDate,
9292
cancelledDate,
9393
recurrence,
94-
blockedBy,
94+
dependsOn,
9595
id,
9696
blockLink,
9797
tags,
@@ -112,7 +112,7 @@ export class Task {
112112
doneDate: moment.Moment | null;
113113
cancelledDate: moment.Moment | null;
114114
recurrence: Recurrence | null;
115-
blockedBy: string[] | [];
115+
dependsOn: string[] | [];
116116
id: string;
117117
blockLink: string;
118118
tags: string[] | [];
@@ -139,7 +139,7 @@ export class Task {
139139

140140
this.recurrence = recurrence;
141141

142-
this.blockedBy = blockedBy;
142+
this.dependsOn = dependsOn;
143143
this.id = id;
144144

145145
this.blockLink = blockLink;
@@ -458,15 +458,15 @@ export class Task {
458458
* @param allTasks - all the tasks in the vault. In custom queries, this is available via query.allTasks.
459459
*/
460460
public isBlocked(allTasks: Readonly<Task[]>) {
461-
if (this.blockedBy.length === 0) {
461+
if (this.dependsOn.length === 0) {
462462
return false;
463463
}
464464

465465
if (this.isDone) {
466466
return false;
467467
}
468468

469-
for (const depId of this.blockedBy) {
469+
for (const depId of this.dependsOn) {
470470
const depTask = allTasks.find((task) => task.id === depId && !task.isDone);
471471
if (!depTask) {
472472
// There is no not-done task with this id.
@@ -481,7 +481,7 @@ export class Task {
481481
}
482482

483483
/**
484-
* A Task is blocking if there is any other not-done task blockedBy value with its id.
484+
* A Task is blocking if there is any other not-done task dependsOn value with its id.
485485
*
486486
* 'Done' tasks (with status DONE, CANCELLED or NON_TASK) are never blocking.
487487
* Only direct dependencies are considered.
@@ -501,7 +501,7 @@ export class Task {
501501
return false;
502502
}
503503

504-
return task.blockedBy.includes(this.id);
504+
return task.dependsOn.includes(this.id);
505505
});
506506
}
507507

@@ -784,7 +784,7 @@ export class Task {
784784
'blockLink',
785785
'scheduledDateIsInferred',
786786
'id',
787-
'blockedBy',
787+
'dependsOn',
788788
];
789789
for (const el of args) {
790790
if (this[el]?.toString() !== other[el]?.toString()) return false;
@@ -861,15 +861,15 @@ export class Task {
861861
* @param allTasks
862862
*/
863863
export function isBlocked(thisTask: Task, allTasks: Task[]) {
864-
if (thisTask.blockedBy.length === 0) {
864+
if (thisTask.dependsOn.length === 0) {
865865
return false;
866866
}
867867

868868
if (thisTask.isDone) {
869869
return false;
870870
}
871871

872-
for (const depId of thisTask.blockedBy) {
872+
for (const depId of thisTask.dependsOn) {
873873
const depTask = allTasks.find((task) => task.id === depId && !task.isDone);
874874
if (!depTask) {
875875
// There is no not-done task with this id.

src/Task/TaskDependency.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ export function setDependenciesOnTasksWithIds(parent: Task, childrenWithIds: Tas
2828
return task.id;
2929
});
3030
let newParent = parent;
31-
if (parent.blockedBy.toString() !== newBlockedBy.toString()) {
32-
newParent = new Task({ ...parent, blockedBy: newBlockedBy });
31+
if (parent.dependsOn.toString() !== newBlockedBy.toString()) {
32+
newParent = new Task({ ...parent, dependsOn: newBlockedBy });
3333
}
3434

3535
return newParent;
3636
}
3737

3838
export function addDependencyToParent(parent: Task, child: Task) {
3939
let newParent = parent;
40-
if (!parent.blockedBy.includes(child.id)) {
41-
const newBlockedBy = [...parent.blockedBy, child.id];
42-
newParent = new Task({ ...parent, blockedBy: newBlockedBy });
40+
if (!parent.dependsOn.includes(child.id)) {
41+
const newBlockedBy = [...parent.dependsOn, child.id];
42+
newParent = new Task({ ...parent, dependsOn: newBlockedBy });
4343
}
4444
return newParent;
4545
}
@@ -52,9 +52,9 @@ export function addDependency(parent: Task, child: Task, existingIds: string[])
5252

5353
export function removeDependency(parent: Task, child: Task) {
5454
let newParent = parent;
55-
if (parent.blockedBy.includes(child.id)) {
56-
const newBlockedBy = parent.blockedBy.filter((blockedBy) => blockedBy !== child.id);
57-
newParent = new Task({ ...parent, blockedBy: newBlockedBy });
55+
if (parent.dependsOn.includes(child.id)) {
56+
const newBlockedBy = parent.dependsOn.filter((blockedBy) => blockedBy !== child.id);
57+
newParent = new Task({ ...parent, dependsOn: newBlockedBy });
5858
}
5959

6060
return newParent;

src/TaskSerializer/DefaultTaskSerializer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ export class DefaultTaskSerializer implements TaskSerializer {
171171
if (!task.recurrence) return '';
172172
return symbolAndStringValue(shortMode, recurrenceSymbol, task.recurrence.toText());
173173
case TaskLayoutComponent.DependsOn: {
174-
if (task.blockedBy.length === 0) return '';
175-
return symbolAndStringValue(shortMode, dependsOnSymbol, task.blockedBy.join(','));
174+
if (task.dependsOn.length === 0) return '';
175+
return symbolAndStringValue(shortMode, dependsOnSymbol, task.dependsOn.join(','));
176176
}
177177
case TaskLayoutComponent.Id:
178178
return symbolAndStringValue(shortMode, idSymbol, task.id);
@@ -364,7 +364,7 @@ export class DefaultTaskSerializer implements TaskSerializer {
364364
cancelledDate,
365365
recurrence,
366366
id,
367-
blockedBy: dependsOn,
367+
dependsOn,
368368
tags: Task.extractHashtags(line),
369369
};
370370
}

src/TaskSerializer/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export type TaskDetails = Writeable<
2121
| 'doneDate'
2222
| 'cancelledDate'
2323
| 'recurrence'
24-
| 'blockedBy'
24+
| 'dependsOn'
2525
| 'id'
2626
| 'tags'
2727
>

src/ui/EditTask.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,15 @@
301301
302302
const blockedBy: Task[] = [];
303303
304-
for (const taskId of task.blockedBy) {
304+
for (const taskId of task.dependsOn) {
305305
const depTask = allTasks.find(cacheTask => cacheTask.id === taskId);
306306
307307
if (!depTask) continue;
308308
309309
blockedBy.push(depTask);
310310
}
311311
312-
originalBlocking = allTasks.filter(cacheTask => cacheTask.blockedBy.includes(task.id));
312+
originalBlocking = allTasks.filter(cacheTask => cacheTask.dependsOn.includes(task.id));
313313
314314
editableTask = {
315315
// NEW_TASK_FIELD_EDIT_REQUIRED
@@ -443,7 +443,7 @@
443443
doneDate,
444444
createdDate,
445445
cancelledDate,
446-
blockedBy: blockedByWithIds.map(task => task.id),
446+
dependsOn: blockedByWithIds.map(task => task.id),
447447
id
448448
});
449449

0 commit comments

Comments
 (0)