-
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: modal which shows in which form the question is used
- Loading branch information
1 parent
88d445b
commit ebf757f
Showing
9 changed files
with
166 additions
and
1 deletion.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
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,56 @@ | ||
<UkButton | ||
{{on "click" (fn (mut this.modalVisible) true)}} | ||
data-test-show-question-usage-modal-btn | ||
> | ||
{{t "caluma.form-builder.question.usage.button"}} | ||
</UkButton> | ||
|
||
<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.title"}} | ||
</modal.header> | ||
<modal.body> | ||
{{#if this.forms.isLoading}} | ||
<div class="uk-text-center"> | ||
<UkSpinner @ratio={{1}} /> | ||
</div> | ||
{{else}} | ||
<ul class="uk-list uk-list-divider" id="question-list"> | ||
{{#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> | ||
{{else}} | ||
<li class="uk-text-muted"> | ||
{{t "caluma.form-builder.question.usage.no-forms-found"}} | ||
</li> | ||
{{/each}} | ||
</ul> | ||
{{/if}} | ||
</modal.body> | ||
</UkModal> |
29 changes: 29 additions & 0 deletions
29
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,29 @@ | ||
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 { | ||
@tracked modalVisible = false; | ||
@queryManager apollo; | ||
|
||
forms = trackedFunction(this, async () => { | ||
if (!this.modalVisible) { | ||
return null; | ||
} | ||
|
||
const forms = await this.apollo.query( | ||
{ | ||
query: allFormsForQuestionQuery, | ||
variables: { | ||
slug: this.args.model.slug, | ||
}, | ||
}, | ||
"allForms.edges", | ||
); | ||
|
||
return forms; | ||
}); | ||
} |
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-btn]"); | ||
|
||
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"); | ||
}); | ||
}); |
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