diff --git a/packages/form-builder/addon/components/cfb-form-editor/question-usage.js b/packages/form-builder/addon/components/cfb-form-editor/question-usage.js index 55491978e..450e9e274 100644 --- a/packages/form-builder/addon/components/cfb-form-editor/question-usage.js +++ b/packages/form-builder/addon/components/cfb-form-editor/question-usage.js @@ -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", { @@ -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); diff --git a/packages/form-builder/addon/components/cfb-form-editor/question.hbs b/packages/form-builder/addon/components/cfb-form-editor/question.hbs index a46b6f96f..4750a286c 100644 --- a/packages/form-builder/addon/components/cfb-form-editor/question.hbs +++ b/packages/form-builder/addon/components/cfb-form-editor/question.hbs @@ -441,7 +441,10 @@ {{/if}}