From 834a5adfc65f88aa7965b329550df20964879844 Mon Sep 17 00:00:00 2001 From: Mitan Omar Date: Thu, 21 Dec 2023 17:15:42 +0100 Subject: [PATCH 1/3] fix(report-row): components from duplication when clicking submit multible time --- app/components/report-row/component.js | 8 ++++++-- app/components/report-row/template.hbs | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/components/report-row/component.js b/app/components/report-row/component.js index a117f90ae..d694cdbf2 100644 --- a/app/components/report-row/component.js +++ b/app/components/report-row/component.js @@ -1,10 +1,12 @@ import { action } from "@ember/object"; import { inject as service } from "@ember/service"; import Component from "@glimmer/component"; +import { tracked } from "@glimmer/tracking"; import ReportValidations from "timed/validations/report"; export default class ReportRowComponent extends Component { @service abilities; + @tracked inUpdate = false; ReportValidations = ReportValidations; @@ -27,8 +29,10 @@ export default class ReportRowComponent extends Component { * @public */ @action - save(changeset) { - this.args.onSave(changeset); + async save(changeset) { + this.inUpdate = true; + await this.args.onSave(changeset); + this.inUpdate = false; } /** * Delete the row diff --git a/app/components/report-row/template.hbs b/app/components/report-row/template.hbs index fd3e0df07..9bd6a660e 100644 --- a/app/components/report-row/template.hbs +++ b/app/components/report-row/template.hbs @@ -109,8 +109,8 @@ type="submit" data-test-save-report class="btn btn-primary" - disabled={{and (not cs.isNew) (or (not cs.isDirty) (not cs.isValid))}} - {{on "click" (prevent-default (fn (optional @onSave) cs))}} + disabled={{or this.inUpdate (and (not cs.isNew) (or (not cs.isDirty) (not cs.isValid)))}} + {{on "click" (prevent-default (fn (optional this.save) cs))}} > {{/if}} From e98f79765587ae63effe6c5fcfb30be39caa0020 Mon Sep 17 00:00:00 2001 From: Mitan Omar Date: Thu, 4 Jan 2024 09:58:36 +0100 Subject: [PATCH 2/3] refactor(report-row): use `dropTask` instead of tracking --- app/components/report-row/component.js | 11 ++++------- app/components/report-row/template.hbs | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/app/components/report-row/component.js b/app/components/report-row/component.js index d694cdbf2..1d8f9dbb5 100644 --- a/app/components/report-row/component.js +++ b/app/components/report-row/component.js @@ -1,12 +1,11 @@ import { action } from "@ember/object"; import { inject as service } from "@ember/service"; import Component from "@glimmer/component"; -import { tracked } from "@glimmer/tracking"; +import { dropTask } from "ember-concurrency"; import ReportValidations from "timed/validations/report"; export default class ReportRowComponent extends Component { @service abilities; - @tracked inUpdate = false; ReportValidations = ReportValidations; @@ -28,11 +27,9 @@ export default class ReportRowComponent extends Component { * @method save * @public */ - @action - async save(changeset) { - this.inUpdate = true; - await this.args.onSave(changeset); - this.inUpdate = false; + @dropTask + *save(changeset) { + yield this.args.onSave(changeset); } /** * Delete the row diff --git a/app/components/report-row/template.hbs b/app/components/report-row/template.hbs index 9bd6a660e..50039414b 100644 --- a/app/components/report-row/template.hbs +++ b/app/components/report-row/template.hbs @@ -109,8 +109,8 @@ type="submit" data-test-save-report class="btn btn-primary" - disabled={{or this.inUpdate (and (not cs.isNew) (or (not cs.isDirty) (not cs.isValid)))}} - {{on "click" (prevent-default (fn (optional this.save) cs))}} + disabled={{or this.save.isRunning (and (not cs.isNew) (or (not cs.isDirty) (not cs.isValid)))}} + {{on "click" (prevent-default (perform this.save cs))}} > {{/if}} From 0bc1c987b006f9b9f947b8fc7ea6dbe1833ed50d Mon Sep 17 00:00:00 2001 From: Mitan Omar Date: Thu, 4 Jan 2024 13:44:01 +0100 Subject: [PATCH 3/3] fix(report-row): check if the argument is defined before calling `save` function --- app/components/report-row/component.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/components/report-row/component.js b/app/components/report-row/component.js index 1d8f9dbb5..2287894e6 100644 --- a/app/components/report-row/component.js +++ b/app/components/report-row/component.js @@ -29,7 +29,9 @@ export default class ReportRowComponent extends Component { */ @dropTask *save(changeset) { - yield this.args.onSave(changeset); + if (this.args.onSave) { + yield this.args.onSave(changeset); + } } /** * Delete the row