Extract constants to own computed getter methods

This commit is contained in:
Manuel Bouza
2019-04-09 08:38:52 +02:00
parent c6381f1278
commit 5d7b820f81

View File

@@ -59,31 +59,39 @@ class App extends Component {
@observable changeset = {} @observable changeset = {}
@observable formErrors = {} @observable formErrors = {}
@computed get changesetWithDefaults() { @computed get project() {
const { service, projects, lastProjectId, lastTaskId } = this.props const { service, projects, lastProjectId } = this.props
return (
// TODO: extract project, task and billable to own methods
const project =
findProjectByValue(this.changeset.assignment_id)(projects) || findProjectByValue(this.changeset.assignment_id)(projects) ||
findProjectByIdentifier(service?.projectId)(projects) || findProjectByIdentifier(service?.projectId)(projects) ||
findProjectByValue(Number(lastProjectId))(projects) || findProjectByValue(Number(lastProjectId))(projects) ||
head(projects) head(projects)
)
}
const task = @computed get task() {
findTask(this.changeset.task_id || service?.taskId || lastTaskId)(project) || const { service, lastTaskId } = this.props
head(project?.tasks) return (
findTask(this.changeset.task_id || service?.taskId || lastTaskId)(this.project) ||
head(this.project?.tasks)
)
}
const billable = /\(.+\)/.test(this.changeset.hours) === true ? false : !!task?.billable @computed get billable() {
return /\(.+\)/.test(this.changeset.hours) === true ? false : !!this.task?.billable
}
@computed get changesetWithDefaults() {
const { service } = this.props
const defaults = { const defaults = {
remote_service: service?.name, remote_service: service?.name,
remote_id: service?.id, remote_id: service?.id,
remote_url: service?.url, remote_url: service?.url,
date: formatDate(new Date()), date: formatDate(new Date()),
assignment_id: project?.value, assignment_id: this.project?.value,
task_id: task?.value, task_id: this.task?.value,
billable, billable: this.billable,
hours: "", hours: "",
seconds: this.changeset.hours && new TimeInputParser(this.changeset.hours).parseSeconds(), seconds: this.changeset.hours && new TimeInputParser(this.changeset.hours).parseSeconds(),
description: service?.description, description: service?.description,