Preselect default task (#22)
This commit is contained in:
committed by
Tobias Miesel
parent
5e62e16751
commit
8a72f242f9
@@ -14,6 +14,7 @@ import {
|
||||
findProjectByValue,
|
||||
findProjectByIdentifier,
|
||||
findTask,
|
||||
defaultTask,
|
||||
formatDate,
|
||||
} from "utils"
|
||||
import { parseISO } from "date-fns"
|
||||
@@ -73,7 +74,7 @@ class App extends Component {
|
||||
const { service, lastTaskId } = this.props
|
||||
return (
|
||||
findTask(this.changeset.task_id || service?.taskId || lastTaskId)(this.project) ||
|
||||
head(this.project?.tasks)
|
||||
defaultTask(this.project?.tasks)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -121,7 +122,7 @@ class App extends Component {
|
||||
|
||||
if (name === "assignment_id") {
|
||||
const project = findProjectByValue(value)(projects)
|
||||
this.changeset.task_id = head(project?.tasks)?.value
|
||||
this.changeset.task_id = defaultTask(project?.tasks)?.value
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ import {
|
||||
find,
|
||||
curry,
|
||||
pick,
|
||||
head,
|
||||
defaultTo,
|
||||
} from "lodash/fp"
|
||||
import { format } from "date-fns"
|
||||
|
||||
@@ -42,11 +44,19 @@ export const findTask = id =>
|
||||
get("tasks"),
|
||||
)
|
||||
|
||||
export const defaultTask = tasks =>
|
||||
compose(
|
||||
defaultTo(head(tasks)),
|
||||
find(pathEq("isDefault", true)),
|
||||
nilToArray,
|
||||
)(tasks)
|
||||
|
||||
function taskOptions(tasks) {
|
||||
return tasks.map(({ id, name, billable }) => ({
|
||||
return tasks.map(({ id, name, billable, default: isDefault }) => ({
|
||||
label: billable ? name : `(${name})`,
|
||||
value: id,
|
||||
billable,
|
||||
isDefault,
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user