Skip to content

Commit

Permalink
feat(distribution): add functionality to reopen distribution
Browse files Browse the repository at this point in the history
Include control work-item to reopen distribution and
associated control button and ability.
  • Loading branch information
luytena authored and anehx committed Aug 25, 2022
1 parent 4d98619 commit 9ac023f
Show file tree
Hide file tree
Showing 15 changed files with 154 additions and 8 deletions.
9 changes: 9 additions & 0 deletions packages/distribution/addon/abilities/distribution.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,13 @@ export default class DistributionAbility extends Ability {
).length > 0
);
}

get canReopen() {
return (
!this.config.ui.readonly &&
(this.config.permissions.reopenDistribution?.() ?? true) &&
this.distribution.controls.value?.case.edges[0]?.node.parentWorkItem
.isRedoable
);
}
}
16 changes: 16 additions & 0 deletions packages/distribution/addon/components/cd-navigation/controls.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@route="new"
class="uk-icon-button"
title={{t "caluma.distribution.new.title"}}
data-test-new-inquiry
>
<UkIcon @icon="plus" />
</LinkTo>
Expand Down Expand Up @@ -38,4 +39,19 @@
{{/if}}
</button>
{{/if}}
{{#if (can "reopen distribution")}}
<button
type="button"
class="uk-icon-button"
title={{t "caluma.distribution.reopen"}}
data-test-reopen-distribution
{{on "click" (perform this.reopenDistribution)}}
>
{{#if this.reopenDistribution.isRunning}}
<UkSpinner @ratio={{0.6}} />
{{else}}
<UkIcon @icon="refresh" />
{{/if}}
</button>
{{/if}}
</div>
25 changes: 25 additions & 0 deletions packages/distribution/addon/components/cd-navigation/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { gql } from "graphql-tag";
import { decodeId } from "@projectcaluma/ember-core/helpers/decode-id";
import config from "@projectcaluma/ember-distribution/config";
import completeWorkItemMutation from "@projectcaluma/ember-distribution/gql/mutations/complete-work-item.graphql";
import redoWorkItemMutation from "@projectcaluma/ember-distribution/gql/mutations/redo-work-item.graphql";
import incompleteInquiriesQuery from "@projectcaluma/ember-distribution/gql/queries/incomplete-inquiries.graphql";

export default class CdNavigationControlsComponent extends Component {
Expand Down Expand Up @@ -63,6 +64,30 @@ export default class CdNavigationControlsComponent extends Component {
}
}

@dropTask
*reopenDistribution() {
try {
if (!(yield confirm(this.intl.t("caluma.distribution.reopen-confirm")))) {
return;
}

const distributionWorkItemId = decodeId(
this.distribution.controls.value?.case.edges[0]?.node.parentWorkItem.id
);

yield this.apollo.mutate({
mutation: redoWorkItemMutation,
variables: {
workItem: distributionWorkItemId,
},
});

yield this.distribution.refetchControls();
} catch (e) {
this.notification.danger(this.intl.t("caluma.distribution.reopen-error"));
}
}

@dropTask
*sendInquiries() {
if (!(yield confirm(this.intl.t("caluma.distribution.send-confirm")))) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mutation RedoWorkItem($workItem: ID!) {
redoWorkItem(input: { id: $workItem }) {
workItem {
id
isRedoable
}
}
}
11 changes: 11 additions & 0 deletions packages/distribution/addon/gql/queries/control-work-items.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,15 @@ query ControlWorkItems(
}
}
}
case: allCases(filter: [{ id: $caseId }]) {
edges {
node {
id
parentWorkItem {
id
isRedoable
}
}
}
}
}
10 changes: 9 additions & 1 deletion packages/distribution/addon/services/distribution.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,18 @@ export default class DistributionService extends Service {
navigation = trackedTask(this, this.fetchNavigation, () => [this.caseId]);

async refetch() {
await getObservable(this.controls.value)?.refetch();
await this.refetchControls();
await this.refetchNavigation();
}

async refetchNavigation() {
await getObservable(this.navigation.value)?.refetch();
}

async refetchControls() {
await getObservable(this.controls.value)?.refetch();
}

@dropTask
*fetchControls(caseId) {
return yield this.apollo.watchQuery({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ module("Integration | Component | cd-navigation", function (hooks) {
setupIntl(hooks);

hooks.beforeEach(function () {
distribution(this.server, [
const distributionCase = distribution(this.server, [
{ id: "group1" },
{ id: "group2" },
{ id: "group3" },
{ id: "group4" },
{ id: "group5" },
]);

this.caseId = this.server.db.cases[0].id;
this.caseId = distributionCase.id;

this.owner.lookup("service:caluma-options").currentGroupId = "group1";
this.owner.lookup("service:router").isActive = () => true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ module("Integration | Component | cd-navigation/controls", function (hooks) {
setupIntl(hooks);

hooks.beforeEach(function () {
distribution(this.server, [
const distributionCase = distribution(this.server, [
{ id: "group1" },
{ id: "group2" },
{ id: "group3" },
{ id: "group4" },
{ id: "group5" },
]);

this.caseId = this.server.db.cases[0].id;
this.caseId = distributionCase.id;
this.owner.lookup("service:caluma-options").currentGroupId = "group1";
Object.defineProperty(this.owner.lookup("service:distribution"), "caseId", {
value: this.caseId,
Expand Down Expand Up @@ -94,4 +94,21 @@ module("Integration | Component | cd-navigation/controls", function (hooks) {
)
);
});

test("it can redo the current distribution", async function (assert) {
await assert.expect(3);

await render(hbs`<CdNavigation::Controls @caseId={{this.caseId}} />`);

await click("[data-test-complete-distribution]");
await confirm();

assert.dom("[data-test-reopen-distribution]").exists();

await click("[data-test-reopen-distribution]");
await confirm();

assert.dom("[data-test-complete-distribution]").exists();
assert.dom("[data-test-new-inquiry]").exists();
});
});
3 changes: 3 additions & 0 deletions packages/distribution/translations/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ caluma:
start: "Starten"
send: "Offene Anfragen versenden"
complete: "Zirkulation abschliessen"
reopen: "Zirkulation wiedereröffnen"
send-confirm: "Wollen Sie wirklich alle offenen Anfragen versenden?"
complete-confirm:
"Es gibt noch <b>{count} offene {count, plural, =1 {Anfrage} other {Anfragen}}</b>
in der aktuellen Zirkulation. Wenn Sie die Zirkulation abschliessen, werden
alle verbleibenden offenen Anfragen abgebrochen. Möchten Sie fortfahren?"
complete-confirm-empty: "Möchten Sie die Zirkulation wirklich abschliessen?"
reopen-confirm: "Wollen Sie die Zirkulation wirklich wiedereröffnen?"
send-error: "Fehler beim Versenden der offenen Anfragen"
complete-error: "Fehler beim Abschliessen der Zirkulation"
reopen-error: "Fehler beim Wiedereröffnen der Zirkulation"

more: "mehr"
less: "weniger"
Expand Down
5 changes: 4 additions & 1 deletion packages/distribution/translations/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ caluma:
send: "Send pending inquiries"
complete: "Complete circulation"
send-confirm: "Do you really want to send all pending inquiries?"
reopen: "Reopen circulation"
complete-confirm:
"There {count, plural, =1 {is} other {are}} <b>{count} pending
{count, plural, =1 {inquiry} other {inquiries}}</b> on the current
distribution. Completing the distribution will cause all remaining
pending inquiries to be canceled. Would you like to continue?"
complete-confirm-empty: "Do you really want to complete the distribution?"
reopen-confirm: "Do you really want to reopen the distribution?"
send-error: "Error while sending pending inquiries"
complete-error: "Error while completing distribution"
complete-error: "Error while completing the distribution"
reopen-error: "Error while reopening the distribution"

more: "more"
less: "less"
Expand Down
5 changes: 4 additions & 1 deletion packages/distribution/translations/fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ caluma:
send: "Envoyer les demandes ouvertes"
complete: "Terminer la circulation"
send-confirm: "Voulez-vous vraiment envoyer toutes les demandes ouvertes ?"
reopen: "Rouvrir la procédure de circulation"
complete-confirm:
"Il y a <b>{count} {count, plural, =1 {demande} other {demandes}} en
attente</b> sur la distribution actuelle. Si vous terminez la distribution,
toutes les demandes en attente seront annulées. Voulez-vous continuer ?"
complete-confirm-empty: "Vous voulez vraiment fermer la circulation ?"
reopen-confirm: "Vous voulez vraiment rouvrir la circulation ?"
send-error: "Erreur lors de l'envoi des demandes ouvertes"
complete-error: "Erreur lors de la terminaison de la distribution"
complete-error: "Erreur lors de la terminaison de la circulation"
reopen-error: "Erreur lors de la réouverture de la circulation"

more: "plus"
less: "moins"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ export default Factory.extend({
? faker.date.past()
: null;
},
redoable: () => false,
});
27 changes: 26 additions & 1 deletion packages/testing/addon/mirage-graphql/mocks/work-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,27 @@ export default class WorkItemMock extends BaseMock {
});
}

@register("RedoWorkItemPayload")
handleRedoWorkItem(_, { input }) {
const { id } = deserialize(input);
const workItem = this.collection.find(id);

if (workItem.taskId === "distribution") {
const caseId = workItem.childCaseId;

this.collection
.where({ caseId, taskId: "complete-distribution" })
.update({ status: "READY" });
this.collection
.where({ caseId, taskId: "create-inquiry" })
.update({ status: "READY" });
}

return this.handleSavePayload.fn.call(this, _, {
input: { id, redoable: false, status: "READY" },
});
}

@register("CompleteWorkItemPayload")
handleCompleteWorkItem(_, { input }) {
const { id } = deserialize(input);
Expand Down Expand Up @@ -102,6 +123,10 @@ export default class WorkItemMock extends BaseMock {
addressedGroups: workItem.addressedGroups,
});
} else if (taskId === "complete-distribution") {
this.collection
.where({ childCaseId: caseId, status: "READY", taskId: "distribution" })
.update({ status: "COMPLETED", redoable: true });

this.collection
.where({ caseId, status: "READY", taskId: "inquiry" })
.update({ status: "SKIPPED" });
Expand All @@ -116,7 +141,7 @@ export default class WorkItemMock extends BaseMock {
}

return this.handleSavePayload.fn.call(this, _, {
input: { id: input.id, status: "COMPLETED" },
input: { id, status: "COMPLETED" },
});
}
}
7 changes: 7 additions & 0 deletions packages/testing/addon/mirage-graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4048,6 +4048,13 @@ type WorkItem implements Node {
first: Int
last: Int
): WorkItemConnection!

"""
This property potentially performs poorly if used in a large setof entries, as
the evaluation of the redoable jexl configurationcannot be performed on the
database level. Please use carefully.
"""
isRedoable: Boolean
}

type WorkItemConnection {
Expand Down
10 changes: 10 additions & 0 deletions packages/testing/addon/scenarios/distribution.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export function createBlueprint(server) {
server.create("workflow", { slug: "distribution" });
server.create("workflow", { slug: "inquiry" });

server.create("task", { slug: "distribution" });
server.create("task", { slug: "create-inquiry" });
server.create("task", { slug: "complete-distribution" });
server.create("task", { slug: "inquiry" });
Expand Down Expand Up @@ -225,10 +226,17 @@ export function reviseInquiry(server, { inquiry }) {
}

export function createCase(server, { group }) {
const distributionWorkItem = server.create("work-item", {
taskId: "distribution",
status: "READY",
case: server.create("case"),
});

const distributionCase = server.create("case", {
id: "4222ab21-9c89-47de-98be-d62a8ed0ebeb",
status: "RUNNING",
workflowId: "distribution",
parentWorkItem: distributionWorkItem,
});

server.create("work-item", {
Expand Down Expand Up @@ -389,4 +397,6 @@ export default function (server, groups) {
status: "inquiry-answer-status-positive",
}),
});

return distributionCase;
}

0 comments on commit 9ac023f

Please sign in to comment.