@projectcaluma/ember-form 11.0.0-beta.13 → 11.0.0-beta.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,26 @@
1
+ # [@projectcaluma/ember-form-v11.0.0-beta.16](https://github.com/projectcaluma/ember-caluma/compare/@projectcaluma/ember-form-v11.0.0-beta.15...@projectcaluma/ember-form-v11.0.0-beta.16) (2022-03-23)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **embroider:** add missing dependency on @ember/string ([3a6e6bb](https://github.com/projectcaluma/ember-caluma/commit/3a6e6bb39a8c1a40a2ae00b3d4ea00606a755e25))
7
+ * **embroider:** fix dynamic component usage ([1cf0f6e](https://github.com/projectcaluma/ember-caluma/commit/1cf0f6e2914651bbb0ec70d1f7485fd9db90c9b5))
8
+ * **embroider:** remove obsolete export for getWidget helper function ([94fb461](https://github.com/projectcaluma/ember-caluma/commit/94fb461aaa7cac6af9f5612b8f34ad047a2b67bb))
9
+
10
+ # [@projectcaluma/ember-form-v11.0.0-beta.15](https://github.com/projectcaluma/ember-caluma/compare/@projectcaluma/ember-form-v11.0.0-beta.14...@projectcaluma/ember-form-v11.0.0-beta.15) (2022-03-16)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **form:** make sure dynamic options are loaded before validating ([2713b37](https://github.com/projectcaluma/ember-caluma/commit/2713b3718b64f9111ca3e7bec2a6c60fafcb183a))
16
+
17
+ # [@projectcaluma/ember-form-v11.0.0-beta.14](https://github.com/projectcaluma/ember-caluma/compare/@projectcaluma/ember-form-v11.0.0-beta.13...@projectcaluma/ember-form-v11.0.0-beta.14) (2022-03-11)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * **form:** make sure table controls are always visible ([8cd97d2](https://github.com/projectcaluma/ember-caluma/commit/8cd97d204539f2e84b9baf9841591460bddf145a))
23
+
1
24
  # [@projectcaluma/ember-form-v11.0.0-beta.13](https://github.com/projectcaluma/ember-caluma/compare/@projectcaluma/ember-form-v11.0.0-beta.12...@projectcaluma/ember-form-v11.0.0-beta.13) (2022-03-11)
2
25
 
3
26
 
@@ -1,17 +1,23 @@
1
- <DocumentValidity
2
- @document={{@field.document}}
3
- @validateOnEnter={{this.validateOnEnter}}
4
- as |isValid validate|
5
- >
6
- <WorkItemButton
7
- @workItemId={{this.workItem}}
8
- @mutation={{this.action}}
9
- @label={{@field.question.raw.label}}
10
- @disabled={{or (and (not-eq isValid null) (not isValid)) @disabled}}
11
- @color={{this.color}}
12
- @beforeMutate={{fn this.beforeMutate validate}}
13
- @onSuccess={{this.onSuccess}}
14
- @onError={{this.onError}}
15
- class={{if @disabled "uk-hidden"}}
16
- />
17
- </DocumentValidity>
1
+ {{#if
2
+ (macroCondition
3
+ (macroDependencySatisfies "@projectcaluma/ember-workflow" "*")
4
+ )
5
+ }}
6
+ <DocumentValidity
7
+ @document={{@field.document}}
8
+ @validateOnEnter={{this.validateOnEnter}}
9
+ as |isValid validate|
10
+ >
11
+ <WorkItemButton
12
+ @workItemId={{this.workItem}}
13
+ @mutation={{this.action}}
14
+ @label={{@field.question.raw.label}}
15
+ @disabled={{or (and (not-eq isValid null) (not isValid)) @disabled}}
16
+ @color={{this.color}}
17
+ @beforeMutate={{fn this.beforeMutate validate}}
18
+ @onSuccess={{this.onSuccess}}
19
+ @onError={{this.onError}}
20
+ class={{if @disabled "uk-hidden"}}
21
+ />
22
+ </DocumentValidity>
23
+ {{/if}}
@@ -1,71 +1,78 @@
1
1
  import { assert } from "@ember/debug";
2
2
  import { action } from "@ember/object";
3
+ import { dependencySatisfies, macroCondition } from "@embroider/macros";
3
4
  import Component from "@glimmer/component";
4
- import UIkit from "uikit";
5
+ import { confirm } from "ember-uikit";
5
6
 
6
- async function confirm(text) {
7
- try {
8
- await UIkit.modal.confirm(text);
7
+ let CfFieldInputActionButtonComponent;
9
8
 
10
- return true;
11
- } catch (error) {
12
- return false;
13
- }
14
- }
9
+ if (macroCondition(dependencySatisfies("@projectcaluma/ember-workflow", ""))) {
10
+ CfFieldInputActionButtonComponent = class extends Component {
11
+ constructor(...args) {
12
+ super(...args);
13
+
14
+ assert(
15
+ "The document must have a `workItemUuid` for `<CfField::Input::ActionButton />` to work.",
16
+ this.args.field.document.workItemUuid
17
+ );
18
+ }
15
19
 
16
- export default class CfFieldInputActionButtonComponent extends Component {
17
- constructor(...args) {
18
- super(...args);
20
+ get workItem() {
21
+ return (
22
+ this.args.context?.actionButtonWorkItemId ||
23
+ this.args.field.document.workItemUuid
24
+ );
25
+ }
19
26
 
20
- assert(
21
- "The document must have a `workItemUuid` for `<CfField::Input::ActionButton />` to work.",
22
- this.args.field.document.workItemUuid
23
- );
24
- }
27
+ get action() {
28
+ return this.args.field.question.raw.action.toLowerCase();
29
+ }
25
30
 
26
- get workItem() {
27
- return (
28
- this.args.context?.actionButtonWorkItemId ||
29
- this.args.field.document.workItemUuid
30
- );
31
- }
31
+ get color() {
32
+ return this.args.field.question.raw.color.toLowerCase();
33
+ }
32
34
 
33
- get action() {
34
- return this.args.field.question.raw.action.toLowerCase();
35
- }
35
+ get validateOnEnter() {
36
+ return (
37
+ this.args.field.question.raw.action === "COMPLETE" &&
38
+ this.args.field.question.raw.validateOnEnter
39
+ );
40
+ }
36
41
 
37
- get color() {
38
- return this.args.field.question.raw.color.toLowerCase();
39
- }
42
+ @action
43
+ async beforeMutate(validateFn) {
44
+ if (
45
+ this.args.field.question.raw.action === "COMPLETE" &&
46
+ !(await validateFn())
47
+ ) {
48
+ return false;
49
+ }
40
50
 
41
- get validateOnEnter() {
42
- return (
43
- this.args.field.question.raw.action === "COMPLETE" &&
44
- this.args.field.question.raw.validateOnEnter
45
- );
46
- }
51
+ const confirmText = this.args.field.question.raw.infoText;
47
52
 
48
- @action
49
- async beforeMutate(validateFn) {
50
- if (
51
- this.args.field.question.raw.action === "COMPLETE" &&
52
- !(await validateFn())
53
- ) {
54
- return false;
53
+ return !confirmText || confirm(confirmText);
55
54
  }
56
55
 
57
- const confirmText = this.args.field.question.raw.infoText;
58
-
59
- return !confirmText || confirm(confirmText);
60
- }
56
+ @action
57
+ onSuccess() {
58
+ return this.args.context?.actionButtonOnSuccess?.();
59
+ }
61
60
 
62
- @action
63
- onSuccess() {
64
- return this.args.context?.actionButtonOnSuccess?.();
65
- }
61
+ @action
62
+ onError(error) {
63
+ return this.args.context?.actionButtonOnError?.(error);
64
+ }
65
+ };
66
+ } else {
67
+ CfFieldInputActionButtonComponent = class extends Component {
68
+ constructor(...args) {
69
+ super(...args);
66
70
 
67
- @action
68
- onError(error) {
69
- return this.args.context?.actionButtonOnError?.(error);
70
- }
71
+ assert(
72
+ "@projectcaluma/ember-workflow must be installed to enable the usage of the action button questions"
73
+ );
74
+ }
75
+ };
71
76
  }
77
+
78
+ export default CfFieldInputActionButtonComponent;
@@ -1,8 +1,7 @@
1
1
  {{#each @field.options as |option i|}}
2
- {{#if (gt i 0)}}<br />{{/if}}
2
+ {{#if (and (gt i 0) (not @field.raw.question.meta.vertical))}}<br />{{/if}}
3
3
  <label
4
- class="cf-checkbox_label
5
- {{if @field.isInvalid 'uk-form-danger'}}
4
+ class="{{if @field.isInvalid 'uk-form-danger'}}
6
5
  {{if @field.raw.question.meta.vertical 'uk-margin-large-right'}}"
7
6
  >
8
7
  <input
@@ -1,29 +1,27 @@
1
- {{#let (component this.componentName) as |DynamicSelect|}}
2
- <DynamicSelect
3
- @options={{@field.options}}
4
- @selected={{@field.selected}}
5
- @disabled={{@disabled}}
6
- @allowClear={{true}}
7
- @preventScroll={{true}}
8
- @searchEnabled={{this.searchEnabled}}
9
- @searchField="label"
10
- @triggerId={{@field.pk}}
11
- @renderInPlace={{true}}
12
- @placeholder={{this.placeholder}}
13
- @loadingMessage={{t "caluma.form.power-select.options-loading"}}
14
- @searchMessage={{t "caluma.form.power-select.options-empty"}}
15
- @searchPlaceholder={{t "caluma.form.power-select.search-placeholder"}}
16
- @noMatchesMessage={{t "caluma.form.power-select.search-empty"}}
17
- @onChange={{this.change}}
18
- as |option|
19
- >
20
- {{#if (and option.disabled (not @disabled))}}
21
- <del
22
- class="uk-text-muted"
23
- title={{t "caluma.form.optionNotAvailable"}}
24
- >{{option.label}}</del>
25
- {{else}}
26
- {{option.label}}
27
- {{/if}}
28
- </DynamicSelect>
29
- {{/let}}
1
+ <this.selectComponent
2
+ @options={{@field.options}}
3
+ @selected={{@field.selected}}
4
+ @disabled={{@disabled}}
5
+ @allowClear={{true}}
6
+ @preventScroll={{true}}
7
+ @searchEnabled={{this.searchEnabled}}
8
+ @searchField="label"
9
+ @triggerId={{@field.pk}}
10
+ @renderInPlace={{true}}
11
+ @placeholder={{this.placeholder}}
12
+ @loadingMessage={{t "caluma.form.power-select.options-loading"}}
13
+ @searchMessage={{t "caluma.form.power-select.options-empty"}}
14
+ @searchPlaceholder={{t "caluma.form.power-select.search-placeholder"}}
15
+ @noMatchesMessage={{t "caluma.form.power-select.search-empty"}}
16
+ @onChange={{this.change}}
17
+ as |option|
18
+ >
19
+ {{#if (and option.disabled (not @disabled))}}
20
+ <del
21
+ class="uk-text-muted"
22
+ title={{t "caluma.form.optionNotAvailable"}}
23
+ >{{option.label}}</del>
24
+ {{else}}
25
+ {{option.label}}
26
+ {{/if}}
27
+ </this.selectComponent>
@@ -1,7 +1,10 @@
1
1
  import { getOwner } from "@ember/application";
2
2
  import { action } from "@ember/object";
3
3
  import { inject as service } from "@ember/service";
4
+ import { ensureSafeComponent } from "@embroider/util";
4
5
  import Component from "@glimmer/component";
6
+ import PowerSelectComponent from "ember-power-select/components/power-select";
7
+ import PowerSelectMultipleComponent from "ember-power-select/components/power-select-multiple";
5
8
 
6
9
  /**
7
10
  * Dropdown component for the single and multiple choice question type
@@ -16,8 +19,11 @@ export default class CfFieldInputPowerselectComponent extends Component {
16
19
  return this.args.field?.question.isMultipleChoice;
17
20
  }
18
21
 
19
- get componentName() {
20
- return this.multiple ? "power-select-multiple" : "power-select";
22
+ get selectComponent() {
23
+ return ensureSafeComponent(
24
+ this.multiple ? PowerSelectMultipleComponent : PowerSelectComponent,
25
+ this
26
+ );
21
27
  }
22
28
 
23
29
  get searchEnabled() {
@@ -1,5 +1,5 @@
1
1
  {{#each @field.options as |option i|}}
2
- {{#if (gt i 0)}}<br />{{/if}}
2
+ {{#if (and (gt i 0) (not @field.raw.question.meta.vertical))}}<br />{{/if}}
3
3
  <label
4
4
  class="{{if @field.isInvalid 'uk-form-danger'}}
5
5
  {{if @field.raw.question.meta.vertical 'uk-margin-large-right'}}"
@@ -29,7 +29,7 @@
29
29
  @color="link"
30
30
  @onClick={{fn this.edit document}}
31
31
  title={{t "caluma.form.edit"}}
32
- class="uk-flex-inline uk-margin-small-left"
32
+ class="uk-flex-inline uk-margin-small-left table-controls"
33
33
  data-test-edit-row
34
34
  >
35
35
  <UkIcon @icon="pencil" />
@@ -40,7 +40,7 @@
40
40
  @color="link"
41
41
  @onClick={{fn (perform this.delete) document}}
42
42
  title={{t "caluma.form.delete"}}
43
- class="uk-flex-inline uk-margin-small-left"
43
+ class="uk-flex-inline uk-margin-small-left table-controls"
44
44
  data-test-delete-row
45
45
  >
46
46
  <UkIcon @icon="trash" />
@@ -5,22 +5,12 @@ import Component from "@glimmer/component";
5
5
  import { tracked } from "@glimmer/tracking";
6
6
  import { queryManager } from "ember-apollo-client";
7
7
  import { dropTask } from "ember-concurrency";
8
- import UIkit from "uikit";
8
+ import { confirm } from "ember-uikit";
9
9
 
10
10
  import removeDocumentMutation from "@projectcaluma/ember-form/gql/mutations/remove-document.graphql";
11
11
  import saveDocumentMutation from "@projectcaluma/ember-form/gql/mutations/save-document.graphql";
12
12
  import { parseDocument } from "@projectcaluma/ember-form/lib/parsers";
13
13
 
14
- async function confirm(text) {
15
- try {
16
- await UIkit.modal.confirm(text);
17
-
18
- return true;
19
- } catch (error) {
20
- return false;
21
- }
22
- }
23
-
24
14
  export default class CfFieldInputTableComponent extends Component {
25
15
  @service notification;
26
16
  @service intl;
@@ -1,21 +1,8 @@
1
- {{#if this.type}}
2
- {{#let (component (concat "cf-field/input/" this.type)) as |InputComponent|}}
3
- <div
4
- class="uk-form-controls
5
- {{if
6
- (and
7
- (has-question-type @field.question 'multiple-choice' 'choice')
8
- @field.question.raw.meta.vertical
9
- )
10
- 'uk-flex'
11
- }}"
12
- >
13
- <InputComponent
14
- @field={{@field}}
15
- @disabled={{@disabled}}
16
- @onSave={{@onSave}}
17
- @context={{@context}}
18
- />
19
- </div>
20
- {{/let}}
21
- {{/if}}
1
+ <div class="uk-form-controls">
2
+ <this.inputComponent
3
+ @field={{@field}}
4
+ @disabled={{@disabled}}
5
+ @onSave={{@onSave}}
6
+ @context={{@context}}
7
+ />
8
+ </div>
@@ -1,12 +1,33 @@
1
- import { dasherize } from "@ember/string";
1
+ import { ensureSafeComponent } from "@embroider/util";
2
2
  import Component from "@glimmer/component";
3
3
 
4
- const mapping = {
5
- MultipleChoiceQuestion: "checkbox",
6
- ChoiceQuestion: "radio",
7
- DynamicMultipleChoiceQuestion: "checkbox",
8
- DynamicChoiceQuestion: "radio",
9
- CalculatedFloatQuestion: "float",
4
+ import ActionButtonComponent from "@projectcaluma/ember-form/components/cf-field/input/action-button";
5
+ import CheckboxComponent from "@projectcaluma/ember-form/components/cf-field/input/checkbox";
6
+ import DateComponent from "@projectcaluma/ember-form/components/cf-field/input/date";
7
+ import FileComponent from "@projectcaluma/ember-form/components/cf-field/input/file";
8
+ import FloatComponent from "@projectcaluma/ember-form/components/cf-field/input/float";
9
+ import IntegerComponent from "@projectcaluma/ember-form/components/cf-field/input/integer";
10
+ import RadioComponent from "@projectcaluma/ember-form/components/cf-field/input/radio";
11
+ import StaticComponent from "@projectcaluma/ember-form/components/cf-field/input/static";
12
+ import TableComponent from "@projectcaluma/ember-form/components/cf-field/input/table";
13
+ import TextComponent from "@projectcaluma/ember-form/components/cf-field/input/text";
14
+ import TextareaComponent from "@projectcaluma/ember-form/components/cf-field/input/textarea";
15
+
16
+ const COMPONENT_MAPPING = {
17
+ ActionButtonQuestion: ActionButtonComponent,
18
+ CalculatedFloatQuestion: FloatComponent,
19
+ ChoiceQuestion: RadioComponent,
20
+ DateQuestion: DateComponent,
21
+ DynamicChoiceQuestion: RadioComponent,
22
+ DynamicMultipleChoiceQuestion: CheckboxComponent,
23
+ FileQuestion: FileComponent,
24
+ FloatQuestion: FloatComponent,
25
+ IntegerQuestion: IntegerComponent,
26
+ MultipleChoiceQuestion: CheckboxComponent,
27
+ StaticQuestion: StaticComponent,
28
+ TableQuestion: TableComponent,
29
+ TextareaQuestion: TextareaComponent,
30
+ TextQuestion: TextComponent,
10
31
  };
11
32
 
12
33
  /**
@@ -16,17 +37,14 @@ const mapping = {
16
37
  */
17
38
  export default class CfFieldInputComponent extends Component {
18
39
  /**
19
- * The input component type
40
+ * The input component
20
41
  *
21
- * @property {String} type
42
+ * @property {Component} inputComponent
22
43
  * @accessor
23
44
  */
24
- get type() {
45
+ get inputComponent() {
25
46
  const typename = this.args.field?.question.raw.__typename;
26
47
 
27
- return (
28
- typename &&
29
- (mapping[typename] || dasherize(typename.replace(/Question$/, "")))
30
- );
48
+ return ensureSafeComponent(COMPONENT_MAPPING[typename], this);
31
49
  }
32
50
  }
@@ -777,6 +777,8 @@ export default class Field extends Base {
777
777
  * @private
778
778
  */
779
779
  async _validateDynamicChoiceQuestion() {
780
+ await this.question.dynamicOptions;
781
+
780
782
  return validate("inclusion", this.answer.value, {
781
783
  in: (this.options || []).map(({ slug }) => slug),
782
784
  });
@@ -797,6 +799,8 @@ export default class Field extends Base {
797
799
  return true;
798
800
  }
799
801
 
802
+ await this.question.dynamicOptions;
803
+
800
804
  return value.map((value) => {
801
805
  return validate("inclusion", value, {
802
806
  in: (this.options || []).map(({ slug }) => slug),
@@ -1,4 +1 @@
1
- export {
2
- default,
3
- getWidget,
4
- } from "@projectcaluma/ember-form/helpers/get-widget";
1
+ export { default } from "@projectcaluma/ember-form/helpers/get-widget";
@@ -5,19 +5,7 @@
5
5
 
6
6
  @import "../uikit-overwrites";
7
7
 
8
- .cf-checkbox_label {
9
- display: block;
10
- position: relative;
11
- padding-left: 26px;
12
-
13
- .uk-checkbox {
14
- position: absolute;
15
- top: 0.25em;
16
- left: 0;
17
- margin: 0;
18
- }
19
-
20
- & + br {
21
- display: none;
22
- }
8
+ .table-controls > .uk-icon {
9
+ min-height: 20px;
10
+ min-width: 20px;
23
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectcaluma/ember-form",
3
- "version": "11.0.0-beta.13",
3
+ "version": "11.0.0-beta.16",
4
4
  "description": "Ember addon for rendering Caluma forms.",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -14,11 +14,13 @@
14
14
  "test:ember-compatibility": "ember try:each"
15
15
  },
16
16
  "dependencies": {
17
+ "@ember/string": "^3.0.0",
17
18
  "@embroider/macros": "^1.5.0",
19
+ "@embroider/util": "^1.5.0",
18
20
  "@glimmer/component": "^1.0.4",
19
21
  "@glimmer/tracking": "^1.0.4",
20
- "@projectcaluma/ember-core": "^11.0.0-beta.5",
21
- "ember-apollo-client": "^3.2.0",
22
+ "@projectcaluma/ember-core": "^11.0.0-beta.6",
23
+ "ember-apollo-client": "^4.0.2",
22
24
  "ember-auto-import": "^2.4.0",
23
25
  "ember-autoresize-modifier": "^0.5.0",
24
26
  "ember-cli-babel": "^7.26.11",
@@ -33,7 +35,7 @@
33
35
  "ember-pikaday": "^4.0.0",
34
36
  "ember-power-select": "^5.0.4",
35
37
  "ember-resources": "^4.4.0",
36
- "ember-uikit": "^5.0.0",
38
+ "ember-uikit": "^5.1.1",
37
39
  "ember-validators": "^4.1.2",
38
40
  "graphql": "^15.8.0",
39
41
  "jexl": "^2.3.0",
@@ -45,9 +47,9 @@
45
47
  "@ember/optional-features": "2.0.0",
46
48
  "@ember/test-helpers": "2.6.0",
47
49
  "@embroider/test-setup": "1.5.0",
48
- "@faker-js/faker": "6.0.0-beta.0",
49
- "@projectcaluma/ember-testing": "11.0.0-beta.4",
50
- "@projectcaluma/ember-workflow": "11.0.0-beta.4",
50
+ "@faker-js/faker": "6.0.0",
51
+ "@projectcaluma/ember-testing": "11.0.0-beta.5",
52
+ "@projectcaluma/ember-workflow": "11.0.0-beta.5",
51
53
  "broccoli-asset-rev": "3.0.0",
52
54
  "ember-cli": "3.28.5",
53
55
  "ember-cli-code-coverage": "1.0.3",
@@ -73,6 +75,14 @@
73
75
  "uuid": "8.3.2",
74
76
  "webpack": "5.70.0"
75
77
  },
78
+ "peerDependencies": {
79
+ "@projectcaluma/ember-workflow": "^11.0.0-beta.5"
80
+ },
81
+ "peerDependenciesMeta": {
82
+ "@projectcaluma/ember-workflow": {
83
+ "optional": true
84
+ }
85
+ },
76
86
  "engines": {
77
87
  "node": "12.* || 14.* || >= 16"
78
88
  },