Skip to content

Commit

Permalink
fix(user): probe ability to delete user already in table view (projec…
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabauke authored Sep 26, 2022
1 parent 9cf849b commit 6982c32
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default class EmeisOptionsService extends Service {
deactivate: (model) => myUser.canChange(model),
delete: {
label: "some.translation.key", // you can optionally override the label for the action button with translation key or static string
fn: (model) => myUser.canDelete(model), // in case of label overrides, you have to define th function override via the "fn" key
func: (model) => myUser.canDelete(model), // in case of label overrides, you have to define th function override via the "func" key
},
},
// show only a subset of the "additional" fields on the user model
Expand Down
12 changes: 12 additions & 0 deletions addon/helpers/can-delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Helper from "@ember/component/helper";
import { inject as service } from "@ember/service";

export default class CanDelete extends Helper {
@service emeisOptions;

compute([modelName, model]) {
const option = this.emeisOptions[modelName]?.actions?.delete;
const func = option?.func || option;
return typeof func === "function" ? func(model) : true;
}
}
8 changes: 5 additions & 3 deletions addon/templates/users/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,11 @@
<LinkTo @route="users.edit" @model={{user}} class="uk-link-reset uk-margin-small-right">
<UkIcon @icon="pencil"/>
</LinkTo>
<UkButton @color="link" @onClick={{perform this.delete user}}>
<UkIcon @icon="trash" />
</UkButton>
{{#if (can-delete "user" user)}}
<UkButton @color="link" @onClick={{perform this.delete user}}>
<UkIcon @icon="trash" />
</UkButton>
{{/if}}
</td>
{{/let}}
</body.row>
Expand Down
4 changes: 2 additions & 2 deletions tests/acceptance/users-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ module("Acceptance | users", function (hooks) {
});

test("emeisOptions integration", async function (assert) {
assert.expect(16);
assert.expect(17);

const customEmeisOptionsStub = createEmeisOptions(assert);
this.owner.register("service:emeis-options", customEmeisOptionsStub);
Expand All @@ -396,7 +396,7 @@ module("Acceptance | users", function (hooks) {

await visit(`/users/${user.id}`);
assert.dom("[data-test-toggle-active]").hasText("my deactivate label");
assert.verifySteps(["deactivate", "deactivate-label", "delete"]);
assert.verifySteps(["delete", "deactivate", "deactivate-label", "delete"]);

await click("[data-test-toggle-active]");
// eslint-disable-next-line ember/no-settled-after-test-helper
Expand Down

0 comments on commit 6982c32

Please sign in to comment.