Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(user): probe ability to delete user already in table view #562

Merged
merged 1 commit into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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