Skip to content

Commit 8fdc5df

Browse files
authored
fix: field group template component data issues (#412)
1 parent 5874e13 commit 8fdc5df

File tree

1 file changed

+14
-27
lines changed

1 file changed

+14
-27
lines changed

packages/angular-sdk-components/src/lib/_components/template/field-group-template/field-group-template.component.ts

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, Input, forwardRef, OnDestroy, OnChanges, AfterViewInit } from '@angular/core';
1+
import { Component, OnInit, Input, forwardRef, OnDestroy, OnChanges, signal } from '@angular/core';
22
import { CommonModule } from '@angular/common';
33
import { FormGroup } from '@angular/forms';
44
import { MatButtonModule } from '@angular/material/button';
@@ -31,7 +31,7 @@ interface FieldGroupTemplateProps {
3131
styleUrls: ['./field-group-template.component.scss'],
3232
imports: [CommonModule, MatButtonModule, forwardRef(() => ComponentMapperComponent)]
3333
})
34-
export class FieldGroupTemplateComponent implements OnInit, OnDestroy, OnChanges, AfterViewInit {
34+
export class FieldGroupTemplateComponent implements OnInit, OnDestroy, OnChanges {
3535
@Input() configProps$: FieldGroupTemplateProps;
3636
@Input() pConn$: typeof PConnect;
3737
@Input() formGroup$: FormGroup;
@@ -45,7 +45,7 @@ export class FieldGroupTemplateComponent implements OnInit, OnDestroy, OnChanges
4545
heading: any;
4646
children: any;
4747
menuIconOverride$: any;
48-
referenceListLength: number;
48+
referenceListLength = signal<number | null>(null);
4949
fieldHeader: any;
5050

5151
allowAdd = true;
@@ -58,10 +58,6 @@ export class FieldGroupTemplateComponent implements OnInit, OnDestroy, OnChanges
5858
) {}
5959

6060
ngOnInit(): void {
61-
// First thing in initialization is registering and subscribing to the AngularPConnect service
62-
this.angularPConnectData = this.angularPConnect.registerAndSubscribeComponent(this, this.onStateChange);
63-
this.updateSelf();
64-
6561
this.menuIconOverride$ = this.utils.getImageSrc('trash', this.utils.getSDKStaticContentUrl());
6662

6763
const { allowActions, allowTableEdit, referenceList } = this.configProps$;
@@ -86,16 +82,6 @@ export class FieldGroupTemplateComponent implements OnInit, OnDestroy, OnChanges
8682
}
8783
}
8884

89-
onStateChange() {
90-
// Should always check the bridge to see if the component should
91-
// update itself (re-render)
92-
const bUpdateSelf = this.angularPConnect.shouldComponentUpdate(this);
93-
// ONLY call updateSelf when the component should update
94-
if (bUpdateSelf) {
95-
this.updateSelf();
96-
}
97-
}
98-
9985
ngOnChanges(changes) {
10086
if (changes && changes.configProps$) {
10187
const props = changes.configProps$;
@@ -107,16 +93,14 @@ export class FieldGroupTemplateComponent implements OnInit, OnDestroy, OnChanges
10793
}
10894

10995
this.updateSelf();
96+
97+
setTimeout(() => {
98+
this.angularPConnect.shouldComponentUpdate(this);
99+
}, 100);
110100
}
111101
}
112102
}
113103

114-
ngAfterViewInit() {
115-
const resolvedList = getReferenceList(this.pConn$);
116-
// @ts-ignore - Expected 3 arguments, but got 1
117-
this.pConn$.getListActions().initDefaultPageInstructions(resolvedList);
118-
}
119-
120104
updateSelf() {
121105
const inheritedProps: any = this.pConn$.getInheritedProps();
122106

@@ -141,7 +125,10 @@ export class FieldGroupTemplateComponent implements OnInit, OnDestroy, OnChanges
141125
this.pConn$.setInheritedProp('displayMode', 'DISPLAY_ONLY');
142126
}
143127

144-
if (this.referenceListLength != referenceList?.length) {
128+
if (this.referenceListLength() != referenceList?.length) {
129+
// @ts-ignore - Expected 3 arguments, but got 1
130+
this.pConn$.getListActions().initDefaultPageInstructions(resolvedList);
131+
145132
this.children = referenceList?.map((item, index) => {
146133
return {
147134
id: index,
@@ -151,22 +138,22 @@ export class FieldGroupTemplateComponent implements OnInit, OnDestroy, OnChanges
151138
};
152139
});
153140
}
154-
this.referenceListLength = referenceList?.length || 0;
141+
this.referenceListLength.set(referenceList?.length || 0);
155142
}
156143

157144
getStaticHeader = (heading, index) => {
158145
return `${heading} ${index + 1}`;
159146
};
160147

161148
getDynamicHeader = (item, index) => {
162-
if (this.fieldHeader === 'propertyRef' && this.heading && item[this.heading.substring(1)]) {
149+
if (this.heading && item[this.heading.substring(1)]) {
163150
return item[this.heading.substring(1)];
164151
}
165152
return `Row ${index + 1}`;
166153
};
167154

168155
addFieldGroupItem() {
169-
this.pConn$.getListActions().insert({ classID: this.contextClass }, this.referenceListLength);
156+
this.pConn$.getListActions().insert({ classID: this.contextClass }, this.referenceListLength() as number);
170157
}
171158

172159
deleteFieldGroupItem(index) {

0 commit comments

Comments
 (0)