@projectcaluma/ember-workflow 13.2.1 → 13.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  <UkButton
2
2
  ...attributes
3
3
  @type={{@type}}
4
- @disabled={{or @disabled @loading this.mutate.isRunning}}
4
+ @disabled={{this.disabled}}
5
5
  @active={{@active}}
6
6
  @loading={{or @loading this.mutate.isRunning}}
7
7
  @color={{or @color "default"}}
@@ -2,10 +2,12 @@ import { inject as service } from "@ember/service";
2
2
  import Component from "@glimmer/component";
3
3
  import { queryManager } from "ember-apollo-client";
4
4
  import { dropTask } from "ember-concurrency";
5
+ import { trackedFunction } from "reactiveweb/function";
5
6
 
6
7
  import cancelWorkItem from "@projectcaluma/ember-workflow/gql/mutations/cancel-work-item.graphql";
7
8
  import completeWorkItem from "@projectcaluma/ember-workflow/gql/mutations/complete-work-item.graphql";
8
9
  import skipWorkItem from "@projectcaluma/ember-workflow/gql/mutations/skip-work-item.graphql";
10
+ import workItemStatusQuery from "@projectcaluma/ember-workflow/gql/queries/work-item-status.graphql";
9
11
 
10
12
  /**
11
13
  * Component to render a UkButton which mutates the given work item.
@@ -36,6 +38,36 @@ export default class WorkItemButtonComponent extends Component {
36
38
  completeWorkItemMutation = completeWorkItem;
37
39
  skipWorkItemMutation = skipWorkItem;
38
40
 
41
+ get disabled() {
42
+ return (
43
+ this.args.disabled ||
44
+ this.args.loading ||
45
+ this.mutate.isRunning ||
46
+ !this.#workItemHasRequiredStatus.value
47
+ );
48
+ }
49
+
50
+ get requiredWorkItemStatus() {
51
+ if (this.args.mutation === "cancel") {
52
+ return ["READY", "SUSPENDED"];
53
+ }
54
+
55
+ return ["READY"];
56
+ }
57
+
58
+ #workItemHasRequiredStatus = trackedFunction(this, async () => {
59
+ const status = await this.apollo.query(
60
+ {
61
+ query: workItemStatusQuery,
62
+ variables: { id: this.args.workItemId },
63
+ fetchPolicy: "network-only",
64
+ },
65
+ "allWorkItems.edges.0.node.status",
66
+ );
67
+
68
+ return this.requiredWorkItemStatus.includes(status);
69
+ });
70
+
39
71
  @dropTask
40
72
  *mutate() {
41
73
  try {
@@ -0,0 +1,10 @@
1
+ query WorkItemStatus($id: ID!) {
2
+ allWorkItems(filter: [{ id: $id }], first: 1) {
3
+ edges {
4
+ node {
5
+ id
6
+ status
7
+ }
8
+ }
9
+ }
10
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectcaluma/ember-workflow",
3
- "version": "13.2.1",
3
+ "version": "13.2.2",
4
4
  "description": "Ember addon for Caluma workflow tools.",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -24,7 +24,7 @@
24
24
  "ember-uikit": "^9.1.3",
25
25
  "graphql": "^15.10.1",
26
26
  "reactiveweb": "^1.3.0",
27
- "@projectcaluma/ember-core": "^13.2.1"
27
+ "@projectcaluma/ember-core": "^13.2.2"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@ember/optional-features": "2.2.0",
@@ -52,7 +52,7 @@
52
52
  "qunit-dom": "3.4.0",
53
53
  "uikit": "3.22.0",
54
54
  "webpack": "5.97.1",
55
- "@projectcaluma/ember-testing": "13.2.1"
55
+ "@projectcaluma/ember-testing": "13.2.2"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "ember-source": ">= 4.0.0"