-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(form-builder): modal which shows in which form the question is used
--------- Co-authored-by: Falk <falk.neumann@adfinis.com>
- Loading branch information
1 parent
649c5d8
commit c321f08
Showing
10 changed files
with
232 additions
and
1 deletion.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
packages/form-builder/addon/components/cfb-form-editor/question-usage.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{{#if this.otherForms}} | ||
<a | ||
...attributes | ||
href="#" | ||
{{on "click" (fn (mut this.modalVisible) true)}} | ||
data-test-show-question-usage-modal-link | ||
> | ||
{{this.title}} | ||
</a> | ||
{{/if}} | ||
|
||
<UkModal | ||
@visible={{this.modalVisible}} | ||
@stack={{true}} | ||
@onHide={{fn (mut this.modalVisible) false}} | ||
data-test-question-usage-modal | ||
as |modal| | ||
> | ||
<modal.header> | ||
{{t "caluma.form-builder.question.usage.references-heading"}} | ||
</modal.header> | ||
<modal.body> | ||
<ul class="uk-list uk-list-divider"> | ||
{{#each this.forms.value as |form|}} | ||
<li data-test-question-form-item={{form.node.slug}}> | ||
<div class="uk-flex uk-flex-middle"> | ||
<span class="uk-width-expand"> | ||
<LinkTo @route="edit" @model={{form.node.slug}}> | ||
{{form.node.name}} | ||
</LinkTo> | ||
</span> | ||
|
||
{{#if form.node.isArchived}} | ||
<UkBadge> | ||
{{t "caluma.form-builder.form.isArchived"}} | ||
</UkBadge> | ||
{{/if}} | ||
|
||
{{#unless form.node.isPublished}} | ||
<UkBadge class="uk-margin-small-left"> | ||
{{t "caluma.form-builder.question.usage.not-published"}} | ||
</UkBadge> | ||
{{/unless}} | ||
</div> | ||
<div class="uk-text-muted uk-text-small">{{form.node.slug}}</div> | ||
</li> | ||
{{/each}} | ||
</ul> | ||
</modal.body> | ||
</UkModal> |
46 changes: 46 additions & 0 deletions
46
packages/form-builder/addon/components/cfb-form-editor/question-usage.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { inject as service } from "@ember/service"; | ||
import Component from "@glimmer/component"; | ||
import { tracked } from "@glimmer/tracking"; | ||
import { queryManager } from "ember-apollo-client"; | ||
import { trackedFunction } from "ember-resources/util/function"; | ||
|
||
import allFormsForQuestionQuery from "@projectcaluma/ember-form-builder/gql/queries/all-forms-for-question.graphql"; | ||
|
||
export default class CfbFormEditorQuestionUsage extends Component { | ||
@service intl; | ||
@queryManager apollo; | ||
|
||
@tracked modalVisible = false; | ||
|
||
get title() { | ||
return this.intl.t("caluma.form-builder.question.usage.title", { | ||
n: this.otherForms, | ||
// for highlighting the number we use the <b> tag | ||
htmlSafe: true, | ||
}); | ||
} | ||
|
||
get otherForms() { | ||
return this.forms.value?.length - 1 ?? 0; | ||
} | ||
|
||
forms = trackedFunction(this, async () => { | ||
try { | ||
const forms = await this.apollo.query( | ||
{ | ||
query: allFormsForQuestionQuery, | ||
variables: { | ||
slug: this.args.model.slug, | ||
}, | ||
fetchPolicy: "no-cache", | ||
}, | ||
"allForms.edges", | ||
); | ||
|
||
return forms; | ||
} catch (error) { | ||
console.error(error); | ||
return { value: [] }; | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/form-builder/addon/gql/queries/all-forms-for-question.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
query AllFormsForQuestion($slug: String!) { | ||
allForms(filter: [{ questions: [$slug] }]) { | ||
edges { | ||
node { | ||
id | ||
slug | ||
name | ||
isArchived | ||
isPublished | ||
} | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/form-builder/app/components/cfb-form-editor/question-usage.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "@projectcaluma/ember-form-builder/components/cfb-form-editor/question-usage"; |
46 changes: 46 additions & 0 deletions
46
packages/form-builder/tests/acceptance/question-usage-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { visit, click } from "@ember/test-helpers"; | ||
import { setupMirage } from "ember-cli-mirage/test-support"; | ||
import { setupIntl } from "ember-intl/test-support"; | ||
import { module, test } from "qunit"; | ||
|
||
import { setupApplicationTest } from "dummy/tests/helpers"; | ||
|
||
module("Acceptance | question usage", function (hooks) { | ||
setupApplicationTest(hooks); | ||
setupMirage(hooks); | ||
setupIntl(hooks); | ||
|
||
test("can show the question usage", async function (assert) { | ||
assert.expect(4); | ||
|
||
const firstForm = this.server.create("form", { slug: "test-form" }); | ||
const secondForm = this.server.create("form", { | ||
slug: "second-form", | ||
isArchived: true, | ||
isPublished: false, | ||
}); | ||
|
||
this.server.create("question", { | ||
label: "Test Question?", | ||
slug: "test-question", | ||
type: "TEXT", | ||
formIds: [firstForm.id, secondForm.id], | ||
}); | ||
|
||
await visit("/test-form/questions/test-question"); | ||
|
||
await click("[data-test-show-question-usage-modal-link]"); | ||
|
||
assert.dom("[data-test-question-usage-modal]").isVisible(); | ||
|
||
assert.dom("[data-test-question-form-item='test-form']").exists(); | ||
|
||
assert | ||
.dom("[data-test-question-form-item='second-form']") | ||
.containsText("Archived", "archived status is visible"); | ||
|
||
assert | ||
.dom("[data-test-question-form-item='second-form']") | ||
.containsText("not published", "not published status is visible"); | ||
}); | ||
}); |
58 changes: 58 additions & 0 deletions
58
packages/form-builder/tests/integration/components/cfb-form-editor/question-usage-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { render, click, waitFor } from "@ember/test-helpers"; | ||
import { hbs } from "ember-cli-htmlbars"; | ||
import { setupMirage } from "ember-cli-mirage/test-support"; | ||
import { setupIntl } from "ember-intl/test-support"; | ||
import { module, test } from "qunit"; | ||
|
||
import { setupRenderingTest } from "dummy/tests/helpers"; | ||
|
||
module( | ||
"Integration | Component | cfb-form-editor/question-usage", | ||
function (hooks) { | ||
setupRenderingTest(hooks); | ||
setupMirage(hooks); | ||
setupIntl(hooks); | ||
|
||
test("it renders", async function (assert) { | ||
this.set( | ||
"question", | ||
this.server.create("question", { | ||
label: "Test Label", | ||
slug: "test-slug", | ||
type: "TEXT", | ||
}), | ||
); | ||
|
||
this.server.createList("form", 3, { questions: [this.question] }); | ||
|
||
await render( | ||
hbs`<CfbFormEditor::QuestionUsage @model={{this.question}} />`, | ||
); | ||
|
||
await waitFor("[data-test-show-question-usage-modal-link]"); | ||
await click("[data-test-show-question-usage-modal-link]"); | ||
|
||
assert.dom("[data-test-question-usage-modal]").isVisible(); | ||
assert.dom("[data-test-question-form-item]").exists({ count: 3 }); | ||
}); | ||
|
||
test("it is hidden when no other reference to this question exists", async function (assert) { | ||
this.set( | ||
"question", | ||
this.server.create("question", { | ||
label: "Test Label", | ||
slug: "test-slug", | ||
type: "TEXT", | ||
}), | ||
); | ||
|
||
this.server.create("form", { questions: [this.question] }); | ||
|
||
await render( | ||
hbs`<CfbFormEditor::QuestionUsage @model={{this.question}} />`, | ||
); | ||
|
||
assert.dom("[data-test-show-question-usage-modal-link]").isNotVisible(); | ||
}); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters