Skip to content

Commit cfacd15

Browse files
committed
Adding lazy loading to collapsed panels.
1 parent ee1ad94 commit cfacd15

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

src/components/panel/Panel.js

+45-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export default class PanelComponent extends NestedComponent {
1414
input: false,
1515
tableView: false,
1616
dataGridLabel: false,
17-
persistent: false
17+
persistent: false,
18+
lazyLoad: false
1819
}, ...extend);
1920
}
2021

@@ -31,6 +32,7 @@ export default class PanelComponent extends NestedComponent {
3132

3233
constructor(component, options, data) {
3334
super(component, options, data);
35+
this.lazyLoaded = false;
3436
}
3537

3638
get defaultSchema() {
@@ -60,6 +62,48 @@ export default class PanelComponent extends NestedComponent {
6062
}
6163
}
6264

65+
checkValidity(data, dirty) {
66+
// Make sure to toggle the collapsed state before checking validity.
67+
if (
68+
dirty &&
69+
this.component.lazyLoad &&
70+
this.component.collapsible &&
71+
this.collapsed &&
72+
!this.lazyLoaded
73+
) {
74+
this.lazyLoaded = true;
75+
this.addComponents();
76+
}
77+
78+
return super.checkValidity(data, dirty);
79+
}
80+
81+
addComponents(element, data, options, state) {
82+
// If they are lazy loading, then only add the components if they toggle the collapsed state.
83+
if (
84+
this.component.lazyLoad &&
85+
this.component.collapsible &&
86+
this.collapsed &&
87+
!this.lazyLoaded
88+
) {
89+
return;
90+
}
91+
return super.addComponents(element, data, options, state);
92+
}
93+
94+
toggleCollapse() {
95+
super.toggleCollapse();
96+
if (
97+
this.component.lazyLoad &&
98+
this.component.collapsible &&
99+
!this.collapsed &&
100+
!this.lazyLoaded
101+
) {
102+
this.lazyLoaded = true;
103+
this.addComponents();
104+
}
105+
}
106+
63107
build(state) {
64108
this.component.theme = this.component.theme || 'default';
65109
let panelClass = 'mb-2 card border ';

src/components/panel/editForm/Panel.edit.display.js

+11
Original file line numberDiff line numberDiff line change
@@ -119,5 +119,16 @@ export default [
119119
conditional: {
120120
json: { '===': [{ var: 'data.collapsible' }, true] }
121121
}
122+
},
123+
{
124+
weight: 652,
125+
type: 'checkbox',
126+
label: 'Lazy Load Contents',
127+
tooltip: 'Lazy loads the contents only when the panel is opened.',
128+
key: 'lazyLoad',
129+
input: true,
130+
conditional: {
131+
json: { '===': [{ var: 'data.collapsed' }, true] }
132+
}
122133
}
123134
];

0 commit comments

Comments
 (0)