Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lib): only warn on missing fields in Jexl dependencies #1096

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 27 additions & 24 deletions addon/lib/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Base from "ember-caluma/lib/base";
import { computed, defineProperty } from "@ember/object";
import { equal, not, reads } from "@ember/object/computed";
import { inject as service } from "@ember/service";
import { assert } from "@ember/debug";
import { assert, warn } from "@ember/debug";
import { getOwner } from "@ember/application";
import { camelize } from "@ember/string";
import { task } from "ember-concurrency";
Expand Down Expand Up @@ -378,19 +378,19 @@ export default Base.extend({
"document.{jexl,fields.[]}",
"question.isHidden",
function () {
return getDependenciesFromJexl(
this.document.jexl,
this.question.isHidden
).map((slug) => {
const f = this.document.findField(slug);

assert(
`Field for question \`${slug}\` was not found in this document. Please check the \`isHidden\` jexl expression: \`${this.question.isHidden}\`.`,
f
);

return f;
});
return getDependenciesFromJexl(this.document.jexl, this.question.isHidden)
.map((slug) => {
const f = this.document.findField(slug);

warn(
`Field for question \`${slug}\` was not found in this document. Please check the \`isHidden\` jexl expression: \`${this.question.isHidden}\`.`,
!f,
{ id: "ember-caluma.lib.field.hiddenDependencies" }
);

return f;
})
.filter(Boolean);
}
),

Expand All @@ -410,16 +410,19 @@ export default Base.extend({
return getDependenciesFromJexl(
this.document.jexl,
this.question.isRequired
).map((slug) => {
const f = this.document.findField(slug);

assert(
`Field for question \`${slug}\` was not found in this document. Please check the \`isRequired\` jexl expression: \`${this.question.isRequired}\`.`,
f
);

return f;
});
)
.map((slug) => {
const f = this.document.findField(slug);

warn(
`Field for question \`${slug}\` was not found in this document. Please check the \`isRequired\` jexl expression: \`${this.question.isRequired}\`.`,
!f,
{ id: "ember-caluma.lib.field.optionalDependencies" }
);

return f;
})
.filter(Boolean);
}
),

Expand Down