Skip to content

Commit

Permalink
fix(edit-form): replace hardcoded route name handling with dynamic si…
Browse files Browse the repository at this point in the history
…nce an engine can be mouted with a different name
  • Loading branch information
velrest committed Oct 14, 2020
1 parent fe9ccbf commit e770214
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
6 changes: 3 additions & 3 deletions addon/components/edit-form.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
<div class="uk-flex uk-flex-right uk-margin">
{{! without quotes on the @route the LinkTo component tries to set the property listViewRouteName which has no setter}}
<LinkTo
@route="{{this.listViewRouteName}}"
@route="{{this.relativeListViewRouteName}}"
class="uk-button uk-button-default uk-margin-right"
data-test-back
>
{{t "emeis.form.back"}}
</LinkTo>

{{#unless @noDelete}}
{{#if (and (not @noDelete) (not @model.isNew))}}
<UkButton
@loading={{this.delete.isRunning}}
@disabled={{this.delete.isRunning}}
Expand All @@ -26,7 +26,7 @@
>
{{t "emeis.form.delete"}}
</UkButton>
{{/unless}}
{{/if}}

<UkButton
@loading={{this.save.isRunning}}
Expand Down
22 changes: 17 additions & 5 deletions addon/components/edit-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,23 @@ export default class EditFormComponent extends Component {
return this.router.currentRoute.parent.name;
}

get relativeParentRouteName() {
// Remove the top level route
return this.router.currentRoute.parent.name.split(".").slice(1).join(".");
}

get listViewRouteName() {
return this.args.listViewRouteName || `${this.parentRouteName}.index`;
}

get editViewRouteName() {
return `${this.parentRouteName}.edit`;
}

get relativeListViewRouteName() {
return (
this.args.listViewRouteName ||
`${this.parentRouteName}.index`.replace("ember-emeis.", "")
this.args.listViewRouteName.split(".").slice(1).join(".") ||
`${this.relativeParentRouteName}.index`
);
}

Expand All @@ -33,7 +46,7 @@ export default class EditFormComponent extends Component {
this.notification.success(this.intl.t("emeis.form.save-success"));

if (isNew) {
this.router.replaceWith(`${this.parentRouteName}.edit`, model);
this.router.replaceWith(this.editViewRouteName, model);
}
} catch (exception) {
this.notification.danger(this.intl.t("emeis.form.save-error"));
Expand All @@ -45,7 +58,6 @@ export default class EditFormComponent extends Component {
*delete() {
yield this.args.model.destroyRecord();
this.notification.success(this.intl.t("emeis.form.delete-success"));
// I dont really understand why this replaceWith needs the "ember-emeis." prefix and the onw in save does not :/.
this.router.replaceWith(`ember-emeis.${this.listViewRouteName}`);
this.router.replaceWith(this.listViewRouteName);
}
}

0 comments on commit e770214

Please sign in to comment.