Skip to content

Commit

Permalink
Merge pull request adfinis#897 from derrabauke/fix-task-selection-xxx
Browse files Browse the repository at this point in the history
fix(task-selection): make selection more robust
  • Loading branch information
MitanOmar authored Apr 5, 2023
2 parents f844c9d + 91edd83 commit 92a419d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
16 changes: 13 additions & 3 deletions app/components/task-selection/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions app/index/activities/edit/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
2 changes: 1 addition & 1 deletion app/index/activities/edit/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<TaskSelection
@initial={{hash task=this.changeset.task}}
@task={{this.changeset.task}}
@on-set-task={{fn this.setTask this.changeset.task}}
@on-set-task={{fn this.setTask this.changeset}}
as |t|
>
<div class="form-group">{{t.customer}}</div>
Expand Down

0 comments on commit 92a419d

Please sign in to comment.