Skip to content

Commit f245798

Browse files
committed
Tasks edit: Basic functionality for task selector
1 parent 3daf033 commit f245798

2 files changed

Lines changed: 43 additions & 4 deletions

File tree

src/Tasks/TaskEdit.tsx

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export default class TaskEdit extends React.PureComponent<PropsType> {
7171
tags: string[];
7272
collectionUid: string;
7373
showSelectorDialog: boolean;
74-
parentEntry: string;
74+
parentEntry: string | null;
7575

7676
error?: string;
7777
showDeleteDialog: boolean;
@@ -150,6 +150,44 @@ export default class TaskEdit extends React.PureComponent<PropsType> {
150150

151151
}
152152

153+
public filterChildren() {
154+
if (!this.props.item) {
155+
return this.props.entries;
156+
}
157+
const idsToRemove: string[] = [this.props.item.uid];
158+
const parentMap: {[itemId: string]: TaskType[]} = { "": [] };
159+
for (const e of this.props.entries) {
160+
if (e.uid === this.props.item.uid) {
161+
continue;
162+
}
163+
if (!e.relatedTo) {
164+
parentMap[""].push(e);
165+
} else {
166+
if (parentMap[e.relatedTo]) {
167+
parentMap[e.relatedTo].push(e);
168+
} else {
169+
parentMap[e.relatedTo] = [e];
170+
}
171+
}
172+
}
173+
while (idsToRemove.length > 0) {
174+
const current = idsToRemove.shift()!;
175+
const children = parentMap[current];
176+
if (!children) {
177+
continue;
178+
}
179+
for (const c of children) {
180+
idsToRemove.push(c.uid);
181+
}
182+
delete parentMap[current];
183+
}
184+
const ret: TaskType[] = [];
185+
for (const k in parentMap) {
186+
ret.push(...parentMap[k]);
187+
}
188+
return ret;
189+
}
190+
153191
public handleInputChange(event: React.ChangeEvent<any>) {
154192
const name = event.target.name;
155193
const value = event.target.value;
@@ -220,6 +258,7 @@ export default class TaskEdit extends React.PureComponent<PropsType> {
220258
task.status = this.state.status;
221259
task.priority = this.state.priority;
222260
task.tags = this.state.tags;
261+
task.relatedTo = this.state.parentEntry ?? undefined;
223262
if (startDate) {
224263
task.startDate = startDate;
225264
}
@@ -510,8 +549,8 @@ export default class TaskEdit extends React.PureComponent<PropsType> {
510549
Are you sure you would like to delete this task?
511550
</ConfirmationDialog>
512551
<TaskSelector
513-
entries={this.props.entries}
514-
orig=""
552+
entries={this.filterChildren()}
553+
orig={this.state.parentEntry}
515554
open={this.state.showSelectorDialog}
516555
onConfirm={(entry) => console.log(entry)}
517556
onCancel={() => this.setState({ openSelector: false })}

src/Tasks/TaskSelector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import TaskSelectorListItem from "./TaskSelectorListItem";
66

77
interface PropsType {
88
entries: TaskType[];
9-
orig: string;
9+
orig: string | null;
1010
open: boolean;
1111
onConfirm: (entry: string | null) => void;
1212
onCancel: () => void;

0 commit comments

Comments
 (0)