Skip to content

Commit

Permalink
Tasks edit: Simplified task selection
Browse files Browse the repository at this point in the history
  • Loading branch information
MangoCubes committed Jul 16, 2023
1 parent f245798 commit ee51609
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/Tasks/TaskEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default class TaskEdit extends React.PureComponent<PropsType> {
constructor(props: PropsType) {
super(props);
this.state = {
parentEntry: "",
parentEntry: props.item?.relatedTo ?? "",
uid: "",
title: "",
status: TaskStatusType.NeedsAction,
Expand Down Expand Up @@ -552,8 +552,8 @@ export default class TaskEdit extends React.PureComponent<PropsType> {
entries={this.filterChildren()}
orig={this.state.parentEntry}
open={this.state.showSelectorDialog}
onConfirm={(entry) => console.log(entry)}
onCancel={() => this.setState({ openSelector: false })}
onConfirm={(entry) => this.setState({ showSelectorDialog: false, parentEntry: entry })}
onCancel={() => this.setState({ showSelectorDialog: false })}
/>
</React.Fragment>
);
Expand Down
17 changes: 1 addition & 16 deletions src/Tasks/TaskSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useState } from "react";
import { TaskType } from "../pim-types";
import { Button, Dialog, DialogActions, DialogContent, DialogTitle, List } from "@material-ui/core";
import React from "react";
Expand All @@ -13,22 +12,14 @@ interface PropsType {
}

export default function TaskSelector(props: PropsType) {
const [itemId, setItemId] = useState<string | null>(props.orig);

const select = () => {
if (itemId) {
props.onConfirm(itemId);
}
};

const itemList = props.entries.filter((e) => !e.relatedTo)
.map((e) =>
<TaskSelectorListItem
key={e.uid}
entries={props.entries}
thisEntry={e}
onClick={setItemId}
selected={itemId}
onClick={props.onConfirm}
/>
);

Expand All @@ -43,15 +34,9 @@ export default function TaskSelector(props: PropsType) {
</List>
</DialogContent>
<DialogActions>
<Button color="primary" onClick={props.onCancel}>
Cancel
</Button>
<Button color="primary" onClick={() => props.onConfirm(null)}>
Clear
</Button>
<Button color="primary" onClick={select}>
Select
</Button>
</DialogActions>
</Dialog>
);
Expand Down
3 changes: 0 additions & 3 deletions src/Tasks/TaskSelectorListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import React from "react";
interface PropsType {
entries: TaskType[];
onClick: (uid: string) => void;
selected: string | null;
thisEntry: TaskType;
}

Expand All @@ -15,15 +14,13 @@ export default function TaskSelectorListItem(props: PropsType) {
return (
<ListItem
primaryText={props.thisEntry.title}
selected={props.selected === props.thisEntry.uid}
key={props.thisEntry.uid}
onClick={() => props.onClick(props.thisEntry.uid)}
nestedItems={tasks.map((e) =>
<TaskSelectorListItem
key={e.uid}
entries={props.entries}
onClick={props.onClick}
selected={props.selected}
thisEntry={e}
/>
)}
Expand Down

0 comments on commit ee51609

Please sign in to comment.