Skip to content

Commit

Permalink
fix(form-builder): don't refetch the forms for the "used by" modal on…
Browse files Browse the repository at this point in the history
… changeset change (#2611)
  • Loading branch information
StephanH90 authored Jan 25, 2024
1 parent a2657ba commit 077e7a0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default class CfbFormEditorQuestionUsage extends Component {
@queryManager apollo;

@tracked modalVisible = false;
@tracked _forms = null;

get title() {
return this.intl.t("caluma.form-builder.question.usage.title", {
Expand All @@ -25,18 +26,29 @@ export default class CfbFormEditorQuestionUsage extends Component {
}

forms = trackedFunction(this, async () => {
if (!this.args.slug) {
// The shown question hasn't completely loaded yet
return [];
}
if (this._forms) {
// we have already fetched the forms previously
return this._forms;
}

try {
const forms = await this.apollo.query(
{
query: allFormsForQuestionQuery,
variables: {
slug: this.args.model.slug,
slug: this.args.slug,
},
fetchPolicy: "no-cache",
},
"allForms.edges",
);

this._forms = forms; // cache the result

return forms;
} catch (error) {
console.error(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,10 @@
{{/if}}

<div class="uk-flex uk-flex-between uk-flex-middle uk-flex-row-reverse">
<CfbFormEditor::QuestionUsage @model={{f.model}} class="uk-flex-last" />
<CfbFormEditor::QuestionUsage
@slug={{changeset-get f.model "slug"}}
class="uk-flex-last"
/>

<f.submit
@disabled={{f.loading}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module(
this.server.createList("form", 3, { questions: [this.question] });

await render(
hbs`<CfbFormEditor::QuestionUsage @model={{this.question}} />`,
hbs`<CfbFormEditor::QuestionUsage @slug={{this.question.slug}} />`,
);

await waitFor("[data-test-show-question-usage-modal-link]");
Expand All @@ -49,7 +49,7 @@ module(
this.server.create("form", { questions: [this.question] });

await render(
hbs`<CfbFormEditor::QuestionUsage @model={{this.question}} />`,
hbs`<CfbFormEditor::QuestionUsage @slug={{this.question.slug}} />`,
);

assert.dom("[data-test-show-question-usage-modal-link]").isNotVisible();
Expand Down

0 comments on commit 077e7a0

Please sign in to comment.