Skip to content

Commit

Permalink
feat(cf-form): all passing context information to cf-form, cf-navigation
Browse files Browse the repository at this point in the history
This is useful to allow passing "context" data to custom components.
  • Loading branch information
czosel committed May 8, 2019
1 parent ed6b922 commit 7372e4d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
8 changes: 8 additions & 0 deletions addon/components/cf-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ export default Component.extend(ComponentQueryManager, {
*/
overrides: null,

/**
* Can be used to pass "context" information from the outside through
* to custom overrides.
*
* @argument {*} overrides
*/
context: null,

didReceiveAttrs() {
this._super(...arguments);
if (this.documentId) {
Expand Down
36 changes: 35 additions & 1 deletion addon/components/cf-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,46 @@ import { ComponentQueryManager } from "ember-apollo-client";
import { task } from "ember-concurrency";
import getNavigationQuery from "ember-caluma/gql/queries/get-navigation";

/**
* Component to display a nested form including navigation.
*
* ```hbs
* {{cf-navigation documentId="myDocId" section=section subSection=subSection}}
* ```
*
* @class CfFormComponent
*/
export default Component.extend(ComponentQueryManager, {
layout,
documentStore: service(),

/**
* The ID of the nested document to display the navigation for
* @argument {String} documentId
*/
documentId: null,
activeDocumentId: null,

/**
* Can be used to pass "context" information from the outside through
* to custom overrides.
*
* @argument {*} overrides
*/
context: null,

/**
* Form slug of currently visible section
*
* @argument {String} section
*/
section: null,

/**
* Form slug of currently visible sub-section
*
* @argument {String} subSection
*/
subSection: null,

_currentDocumentId: null,

Expand Down
2 changes: 1 addition & 1 deletion addon/templates/components/cf-field.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="uk-flex">
<div class="uk-width-expand">
{{#if componentOverride}}
{{component componentOverride field=field disabled=disabled onSave=(perform save)}}
{{component componentOverride field=field disabled=disabled context=context onSave=(perform save)}}
{{else}}
{{cf-field/input field=field disabled=disabled onSave=(perform save)}}
{{/if}}
Expand Down
2 changes: 1 addition & 1 deletion addon/templates/components/cf-form.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{#each _document.fields as |field|}}
{{cf-field field=field disabled=disabled}}
{{cf-field field=field disabled=disabled context=context}}
{{/each}}
2 changes: 1 addition & 1 deletion addon/templates/components/cf-navigation.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</div>

<div class="uk-width-1-1 uk-width-2-3@m">
{{cf-form document=displayedDocument}}
{{cf-form document=displayedDocument context=context}}
</div>
{{/if}}
</div>

0 comments on commit 7372e4d

Please sign in to comment.