Skip to content

Commit

Permalink
feat(work-item-button): add success and error hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Yelinz authored and anehx committed Jun 3, 2021
1 parent 47ef3e1 commit 8d50b15
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 18 deletions.
27 changes: 23 additions & 4 deletions addon/components/work-item-button.js
Expand Up @@ -29,6 +29,7 @@ export default class WorkItemButtonComponent extends Component {

@queryManager apollo;

@service notification;
@service intl;

cancelWorkItemMutation = cancelWorkItem;
Expand All @@ -37,9 +38,27 @@ export default class WorkItemButtonComponent extends Component {

@dropTask
*mutate() {
yield this.apollo.mutate({
mutation: this[`${this.args.mutation}WorkItemMutation`],
variables: { id: this.args.workItemId },
});
try {
yield this.apollo.mutate({
mutation: this[`${this.args.mutation}WorkItemMutation`],
variables: { id: this.args.workItemId },
});

if (this.args.onSuccess) {
this.args.onSuccess();
} else {
this.notification.success(
this.intl.t("caluma.mutate-work-item.success")
);
}
} catch (e) {
if (this.args.onError) {
this.args.onError(e);
} else {
// eslint-disable-next-line no-console
console.error(e);
this.notification.danger(this.intl.t("caluma.mutate-work-item.error"));
}
}
}
}
30 changes: 16 additions & 14 deletions tests/dummy/app/templates/docs/buttons.md
Expand Up @@ -28,17 +28,19 @@ The text of the button is per default the mutation name, it can be overwritten w
</WorkItemButton>
```

The WorkItemButton component has 3 parameters:

- `mutation` The state mutation to be used either `complete`, `skip` or `cancel`.
- `workItemId` Id of the work item which should be mutated.
- `label` (Optional) Overwrites the button text.

Additionally there are many optional parameters for the underlying [UkButton](https://adfinis-sygroup.github.io/ember-uikit/#/docs/components/button) component, refer to the UkButton component documentation to see what exactly they do:

- `type`
- `disabled`
- `loading`
- `color`
- `size`
- `title`
The WorkItemButton component has 5 parameters:

- `mutation` The state mutation to be used either `complete`, `skip` or `cancel`.
- `workItemId` Id of the work item which should be mutated.
- `label` (Optional) Overwrites the button text.
- `onSuccess`(Optional) Function to be called when the mutation succeeds.
- `onError`(Optional) Function to be called when the mutation fails.

Additionally there are many optional parameters for the underlying [UkButton](https://adfinis-sygroup.github.io/ember-uikit/#/docs/components/button) component, refer to the UkButton component documentation to see what exactly they do:

- `type`
- `disabled`
- `loading`
- `color`
- `size`
- `title`
2 changes: 2 additions & 0 deletions translations/de.yaml
Expand Up @@ -215,3 +215,5 @@ caluma:
complete: "Abschliessen"
skip: "Überspringen"
cancel: "Abbrechen"
success: "Der Status der Aufgabens wurde erfolgreich angepasst!"
error: "Hoppla, beim Speichern des Aufgabenstatus ist etwas schief gelaufen..."
2 changes: 2 additions & 0 deletions translations/en.yaml
Expand Up @@ -215,3 +215,5 @@ caluma:
complete: "Complete"
skip: "Skip"
cancel: "Cancel"
success: "Work item state was successfully changed!"
error: "Ooops, something went wrong while changing the work item state..."
2 changes: 2 additions & 0 deletions translations/fr.yaml
Expand Up @@ -78,3 +78,5 @@ caluma:
complete: "Terminer"
skip: "Sauter"
cancel: "Annuler"
success: "Succès!"
error: "Oups, quelque chose a mal ..."

0 comments on commit 8d50b15

Please sign in to comment.