-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c96a8ae
commit 06ce87f
Showing
9 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
packages/form-builder/addon/components/cfb-form-list/copy-modal.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,49 @@ | ||
{{#if this.visible}} | ||
<UkModal | ||
@visible={{this.visible}} | ||
@onHide={{fn (mut this.visible) false}} | ||
data-test-copy-form-modal | ||
as |modal| | ||
> | ||
<ValidatedForm | ||
@model={{this.changeset}} | ||
@on-submit={{perform this.submit}} | ||
as |f| | ||
> | ||
<modal.header> | ||
<h2 class="uk-modal-title"> | ||
{{t "caluma.form-builder.copy-modal.title" form=@item.name}} | ||
</h2> | ||
</modal.header> | ||
<modal.body> | ||
<f.input | ||
@name="name" | ||
@label={{t "caluma.form-builder.copy-modal.name.label"}} | ||
@hint={{t "caluma.form-builder.copy-modal.name.hint" name=@item.name}} | ||
data-test-copy-modal-input-name | ||
/> | ||
<f.input | ||
@name="slug" | ||
@label={{t "caluma.form-builder.copy-modal.slug.label"}} | ||
@hint={{t "caluma.form-builder.copy-modal.slug.hint" slug=@item.slug}} | ||
data-test-copy-modal-input-slug | ||
/> | ||
</modal.body> | ||
<modal.footer class="uk-text-right"> | ||
<f.submit | ||
@loading={{this.submit.isRunning}} | ||
@disabled={{or | ||
this.submit.isRunning | ||
(not this.changeset.isValid) | ||
(eq @item.slug this.changeset.slug) | ||
}} | ||
data-test-copy-form-submit | ||
> | ||
{{t "caluma.form-builder.copy-modal.submit"}} | ||
</f.submit> | ||
</modal.footer> | ||
</ValidatedForm> | ||
</UkModal> | ||
{{/if}} | ||
|
||
{{yield (hash toggle=this.toggle)}} |
70 changes: 70 additions & 0 deletions
70
packages/form-builder/addon/components/cfb-form-list/copy-modal.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,70 @@ | ||
import { action } from "@ember/object"; | ||
import { inject as service } from "@ember/service"; | ||
import Component from "@glimmer/component"; | ||
import { tracked } from "@glimmer/tracking"; | ||
import { queryManager } from "ember-apollo-client"; | ||
import { Changeset } from "ember-changeset"; | ||
import lookupValidator from "ember-changeset-validations"; | ||
import { dropTask } from "ember-concurrency"; | ||
|
||
import copyFormMutation from "@projectcaluma/ember-form-builder/gql/mutations/copy-form.graphql"; | ||
import validations from "@projectcaluma/ember-form-builder/validations/form"; | ||
|
||
export default class componentsCfbFormItemListCopyModal extends Component { | ||
@queryManager apollo; | ||
@service notification; | ||
@service router; | ||
@service intl; | ||
@tracked visible = false; | ||
|
||
constructor(owner, args) { | ||
super(owner, args); | ||
this.changeset = Changeset( | ||
this.args.item, | ||
lookupValidator(validations), | ||
validations, | ||
); | ||
} | ||
|
||
@action | ||
toggle() { | ||
this.visible = !this.visible; | ||
} | ||
|
||
@dropTask | ||
*submit(changeset) { | ||
try { | ||
const form = yield this.apollo.mutate( | ||
{ | ||
mutation: copyFormMutation, | ||
variables: { | ||
input: { | ||
source: this.args.item.slug, | ||
name: changeset.name, | ||
slug: changeset.slug, | ||
}, | ||
}, | ||
}, | ||
"copyForm.form", | ||
); | ||
|
||
this.notification.success( | ||
this.intl.t( | ||
`caluma.form-builder.notification.form.${ | ||
this.args.slug ? "save" : "create" | ||
}.success`, | ||
), | ||
); | ||
|
||
this.router.transitionTo("edit", form.slug); | ||
} catch (e) { | ||
this.notification.danger( | ||
this.intl.t( | ||
`caluma.form-builder.notification.form.${ | ||
this.args.slug ? "save" : "create" | ||
}.error`, | ||
), | ||
); | ||
} | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
packages/form-builder/addon/gql/mutations/copy-form.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,11 @@ | ||
#import FormInfo from '../fragments/form-info.graphql' | ||
|
||
mutation CopyForm($input: CopyFormInput!) { | ||
copyForm(input: $input) { | ||
form { | ||
id | ||
...FormInfo | ||
} | ||
clientMutationId | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/form-builder/app/components/cfb-form-list/copy-modal.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-list/copy-modal"; |
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,36 @@ | ||
import { visit, click, fillIn, currentURL } 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 | form copy", function (hooks) { | ||
setupApplicationTest(hooks); | ||
setupMirage(hooks); | ||
setupIntl(hooks); | ||
|
||
test("can copy a form", async function (assert) { | ||
assert.expect(5); | ||
|
||
const form = this.server.create("form"); | ||
|
||
await visit("/"); | ||
|
||
assert.dom("[data-test-copy-form-modal]").isNotVisible(); | ||
|
||
await click(`[data-test-copy-form-button=${form.slug}]`); | ||
|
||
assert.dom("[data-test-copy-form-modal]").isVisible(); | ||
|
||
assert.dom("[data-test-copy-modal-input-name]").hasValue(form.name); | ||
assert.dom("[data-test-copy-modal-input-slug]").hasValue(form.slug); | ||
|
||
await fillIn("[data-test-copy-modal-input-name]", `${form.name} copy`); | ||
await fillIn("[data-test-copy-modal-input-slug]", `${form.slug}-copy`); | ||
|
||
await click("[data-test-copy-form-submit]"); | ||
|
||
assert.strictEqual(currentURL(), `/${form.slug}-copy`); | ||
}); | ||
}); |
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