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

add form builder test and add collapsible sub forms #161

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
29 changes: 25 additions & 4 deletions addon/components/sub-form.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{{#if @useNewListingLayout}}
<div class="sf-listing-sub-form au-o-box">
{{#if (or @subForm.itemLabel @canMoveUp @canMoveDown @canRemove)}}
{{#if
(or
@subForm.itemLabel
@canMoveUp
@canMoveDown
@canRemove
@subForm.isCollapsible
)
}}
<AuToolbar @size={{this.size}} as |Group|>
<Group>
{{#if (or @canMoveUp @canMoveDown)}}
Expand All @@ -13,10 +21,23 @@
/>
{{/if}}
{{#if @subForm.itemLabel}}
<AuHeading @level={{this.titleLevel}} @skin={{this.titleSkin}}>
<AuHeading
@level={{this.titleLevel}}
@skin={{this.titleSkin}}
{{on "click" this.toggleCollapsed}}
>
{{@subForm.itemLabel}}
</AuHeading>
{{/if}}
{{#if @subForm.isCollapsible}}
<AuButton
@skin="naked"
@text={{if this.collapsed "Show" "Hide"}}
@hideText={{true}}
@icon={{if this.collapsed "chevron-right" "chevron-down"}}
{{on "click" this.toggleCollapsed}}
/>
{{/if}}
</Group>
{{#if @canRemove}}
<Group>
Expand All @@ -34,7 +55,7 @@
</AuToolbar>
{{/if}}

<div class="au-o-flow">
<div class="au-o-flow {{if this.collapsed 'au-u-hidden'}}">
Copy link
Contributor Author

@Rahien Rahien Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using au-u-hidden here because it seems that rendering it conditionally using #if or #unless breaks the children of a propertygroup

{{#each this.propertyGroups as |group|}}
<PropertyGroup
@form={{@subForm.uri}}
Expand Down Expand Up @@ -104,4 +125,4 @@
</div>
{{/if}}
</div>
{{/if}}
{{/if}}
12 changes: 12 additions & 0 deletions addon/components/sub-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@ import Component from '@glimmer/component';
import { getTopLevelPropertyGroups } from '../utils/model-factory';
import isLast from '@lblod/ember-submission-form-fields/-private/helpers/is-last';
import OrderButtonGroup from '@lblod/ember-submission-form-fields/components/listing/order-button-group';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';

export default class SubFormComponent extends Component {
propertyGroups = []; // NOTE don't think this needs to be an ember array as it will never change
isLast = isLast;
OrderButtonGroup = OrderButtonGroup;

@tracked
collapsed = false;

constructor() {
super(...arguments);
this.propertyGroups = getTopLevelPropertyGroups({
store: this.args.formStore,
graphs: this.args.graphs,
form: this.args.subForm.uri,
});
this.collapsed = this.args.subForm.isCollapsible;
}

get level() {
Expand All @@ -33,4 +39,10 @@ export default class SubFormComponent extends Component {
get titleSkin() {
return `${this.level + 1}`;
}

@action
toggleCollapsed() {
if (!this.args.subForm.isCollapsible) return;
this.collapsed = !this.collapsed;
}
}
6 changes: 6 additions & 0 deletions addon/models/sub-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ export default class SubFormModel {
undefined,
formGraph
);
this.isCollapsible = store.any(
uri,
FORM('isCollapsible'),
undefined,
formGraph
);
}

@tracked
Expand Down
5 changes: 5 additions & 0 deletions tests/dummy/app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
Basic form fields
</AuNavigationLink>
</li>
<li class="au-c-list-navigation__item">
<AuNavigationLink @route="form" @model="form-builder">
Form builder
</AuNavigationLink>
</li>
<li class="au-c-list-navigation__item">
<AuNavigationLink @route="form" @model="dynamic-behaviour">
Dynamic behaviour
Expand Down
Loading