From 91edd8360113eb852ac58cacc481b14f86eeafee Mon Sep 17 00:00:00 2001 From: Falk Date: Wed, 5 Apr 2023 10:49:17 +0200 Subject: [PATCH] fix(task-selection): make selection more robust * multiple selection of the same recent task won't reset project & task * initial selection will now resolve proxies to determine state --- app/components/task-selection/component.js | 16 +++++++++++++--- app/index/activities/edit/controller.js | 6 +++--- app/index/activities/edit/template.hbs | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/components/task-selection/component.js b/app/components/task-selection/component.js index f1a4a1b82..edd7a7654 100644 --- a/app/components/task-selection/component.js +++ b/app/components/task-selection/component.js @@ -37,12 +37,20 @@ export default class TaskSelectionComponent extends Component { async _setInitial() { await this.tracking.fetchActiveActivity?.last; - const { customer, project, task } = this.args.initial ?? { + const initial = this.args.initial ?? { customer: null, project: null, task: null, }; + // the objects are possibily wrapped in a proxy which would + // confuse the upcoming null check + const [customer, project, task] = await Promise.all([ + initial.customer, + initial.project, + initial.task, + ]); + if (task && !this.task) { this.onTaskChange(task); } else if (project && !this.project) { @@ -265,7 +273,8 @@ export default class TaskSelectionComponent extends Component { @action async onCustomerChange(value, options = {}) { - if (value && value.get("constructor.modelName") === "task") { + const isTask = value?.get("constructor.modelName") === "task"; + if (isTask) { this._customer = await value.get("project.customer"); this.onTaskChange(value); } else { @@ -278,7 +287,8 @@ export default class TaskSelectionComponent extends Component { if ( this.project && - (!value || value.get("id") !== this.project.get("customer.id")) + (!value || + (!isTask && value.get("id") !== this.project.get("customer.id"))) ) { this.onProjectChange(null, options); } diff --git a/app/index/activities/edit/controller.js b/app/index/activities/edit/controller.js index 4913b2233..9849a5fc3 100644 --- a/app/index/activities/edit/controller.js +++ b/app/index/activities/edit/controller.js @@ -96,9 +96,9 @@ export default class IndexActivitiesEditController extends Controller { } @action - setTask(task) { - if (task.id !== this.changeset.task.id) { - this.changeset.task = task; + setTask(cs, task) { + if (task?.id !== cs.task?.id) { + cs.task = task; } } } diff --git a/app/index/activities/edit/template.hbs b/app/index/activities/edit/template.hbs index c1b3acd76..a103f54d3 100644 --- a/app/index/activities/edit/template.hbs +++ b/app/index/activities/edit/template.hbs @@ -12,7 +12,7 @@
{{t.customer}}