Skip to content

Commit 3daf033

Browse files
committed
Tasks edit: Added parent task selector
1 parent b2a7b1d commit 3daf033

4 files changed

Lines changed: 117 additions & 1 deletion

File tree

src/Tasks/Main.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export default function TasksMain() {
7272
history.goBack();
7373
}
7474

75-
const flatEntries = [];
75+
const flatEntries: TaskType[] = [];
7676
for (const col of entries.values()) {
7777
for (const item of col.values()) {
7878
flatEntries.push(item);
@@ -113,6 +113,7 @@ export default function TasksMain() {
113113
exact
114114
>
115115
<TaskEdit
116+
entries={flatEntries}
116117
collections={cachedCollections}
117118
onSave={onItemSave}
118119
onDelete={onItemDelete}
@@ -154,6 +155,7 @@ export default function TasksMain() {
154155
exact
155156
>
156157
<TaskEdit
158+
entries={flatEntries}
157159
key={itemUid}
158160
initialCollection={item.collectionUid}
159161
item={item}

src/Tasks/TaskEdit.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ import { History } from "history";
4242
import ColoredRadio from "../widgets/ColoredRadio";
4343
import RRule, { RRuleOptions } from "../widgets/RRule";
4444
import { CachedCollection } from "../Pim/helpers";
45+
import TaskSelector from "./TaskSelector";
4546

4647
interface PropsType {
48+
entries: TaskType[];
4749
collections: CachedCollection[];
4850
initialCollection?: string;
4951
item?: TaskType;
@@ -68,6 +70,8 @@ export default class TaskEdit extends React.PureComponent<PropsType> {
6870
description: string;
6971
tags: string[];
7072
collectionUid: string;
73+
showSelectorDialog: boolean;
74+
parentEntry: string;
7175

7276
error?: string;
7377
showDeleteDialog: boolean;
@@ -76,6 +80,7 @@ export default class TaskEdit extends React.PureComponent<PropsType> {
7680
constructor(props: PropsType) {
7781
super(props);
7882
this.state = {
83+
parentEntry: "",
7984
uid: "",
8085
title: "",
8186
status: TaskStatusType.NeedsAction,
@@ -85,6 +90,7 @@ export default class TaskEdit extends React.PureComponent<PropsType> {
8590
description: "",
8691
tags: [],
8792
timezone: null,
93+
showSelectorDialog: false,
8894

8995
collectionUid: "",
9096
showDeleteDialog: false,
@@ -322,6 +328,17 @@ export default class TaskEdit extends React.PureComponent<PropsType> {
322328
</Select>
323329
</FormControl>
324330

331+
<Button onClick={() => this.setState({ showSelectorDialog: true })} style={styles.fullWidth}>
332+
Select parent task
333+
</Button>
334+
<TextField
335+
style={styles.fullWidth}
336+
label="Parent task"
337+
name="parent"
338+
disabled
339+
value={this.props.entries.find((e) => e.uid === this.state.parentEntry)?.title ?? "None"}
340+
/>
341+
325342
<FormControl style={styles.fullWidth}>
326343
<InputLabel>
327344
Status
@@ -492,6 +509,13 @@ export default class TaskEdit extends React.PureComponent<PropsType> {
492509
>
493510
Are you sure you would like to delete this task?
494511
</ConfirmationDialog>
512+
<TaskSelector
513+
entries={this.props.entries}
514+
orig=""
515+
open={this.state.showSelectorDialog}
516+
onConfirm={(entry) => console.log(entry)}
517+
onCancel={() => this.setState({ openSelector: false })}
518+
/>
495519
</React.Fragment>
496520
);
497521
}

src/Tasks/TaskSelector.tsx

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { useState } from "react";
2+
import { TaskType } from "../pim-types";
3+
import { Button, Dialog, DialogActions, DialogContent, DialogTitle, List } from "@material-ui/core";
4+
import React from "react";
5+
import TaskSelectorListItem from "./TaskSelectorListItem";
6+
7+
interface PropsType {
8+
entries: TaskType[];
9+
orig: string;
10+
open: boolean;
11+
onConfirm: (entry: string | null) => void;
12+
onCancel: () => void;
13+
}
14+
15+
export default function TaskSelector(props: PropsType) {
16+
const [itemId, setItemId] = useState<string | null>(props.orig);
17+
18+
const select = () => {
19+
if (itemId) {
20+
props.onConfirm(itemId);
21+
}
22+
};
23+
24+
const itemList = props.entries.filter((e) => !e.relatedTo)
25+
.map((e) =>
26+
<TaskSelectorListItem
27+
key={e.uid}
28+
entries={props.entries}
29+
thisEntry={e}
30+
onClick={setItemId}
31+
selected={itemId}
32+
/>
33+
);
34+
35+
return (
36+
<Dialog open={props.open} onClose={props.onCancel} fullWidth>
37+
<DialogTitle>
38+
Select parent task
39+
</DialogTitle>
40+
<DialogContent>
41+
<List>
42+
{itemList}
43+
</List>
44+
</DialogContent>
45+
<DialogActions>
46+
<Button color="primary" onClick={props.onCancel}>
47+
Cancel
48+
</Button>
49+
<Button color="primary" onClick={() => props.onConfirm(null)}>
50+
Clear
51+
</Button>
52+
<Button color="primary" onClick={select}>
53+
Select
54+
</Button>
55+
</DialogActions>
56+
</Dialog>
57+
);
58+
}

src/Tasks/TaskSelectorListItem.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { TaskType } from "../pim-types";
2+
import { ListItem } from "../widgets/List";
3+
import React from "react";
4+
5+
interface PropsType {
6+
entries: TaskType[];
7+
onClick: (uid: string) => void;
8+
selected: string | null;
9+
thisEntry: TaskType;
10+
}
11+
12+
export default function TaskSelectorListItem(props: PropsType) {
13+
const tasks = props.entries.filter((e) => e.relatedTo === props.thisEntry.uid);
14+
15+
return (
16+
<ListItem
17+
primaryText={props.thisEntry.title}
18+
selected={props.selected === props.thisEntry.uid}
19+
key={props.thisEntry.uid}
20+
onClick={() => props.onClick(props.thisEntry.uid)}
21+
nestedItems={tasks.map((e) =>
22+
<TaskSelectorListItem
23+
key={e.uid}
24+
entries={props.entries}
25+
onClick={props.onClick}
26+
selected={props.selected}
27+
thisEntry={e}
28+
/>
29+
)}
30+
/>
31+
);
32+
}

0 commit comments

Comments
 (0)