-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Details template fields are not getting re-render on save for… (#…
…257) * fix: Details template fields are not getting re-rendering on save for later * removed unnecessary code in case view
- Loading branch information
1 parent
fd126d5
commit 77a51a7
Showing
21 changed files
with
135 additions
and
320 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
packages/angular-sdk-components/src/lib/_components/template/base/details-template-base.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Directive, OnInit, OnDestroy, Injector, Input } from '@angular/core'; | ||
import { AngularPConnectData, AngularPConnectService } from '../../../_bridge/angular-pconnect'; | ||
|
||
@Directive() | ||
export class DetailsTemplateBase implements OnInit, OnDestroy { | ||
@Input() pConn$: typeof PConnect; | ||
|
||
// For interaction with AngularPConnect | ||
protected angularPConnectData: AngularPConnectData = {}; | ||
protected angularPConnect; | ||
|
||
childrenMetadataOld; | ||
|
||
constructor(injector: Injector) { | ||
this.angularPConnect = injector.get(AngularPConnectService); | ||
} | ||
|
||
ngOnInit(): void { | ||
// First thing in initialization is registering and subscribing to the AngularPConnect service | ||
this.angularPConnectData = this.angularPConnect.registerAndSubscribeComponent(this, this.onStateChange); | ||
|
||
this.checkAndUpdate(); | ||
} | ||
|
||
ngOnDestroy() { | ||
if (this.angularPConnectData.unsubscribeFn) { | ||
this.angularPConnectData.unsubscribeFn(); | ||
} | ||
} | ||
|
||
onStateChange() { | ||
this.checkAndUpdate(); | ||
} | ||
|
||
checkAndUpdate() { | ||
// Should always check the bridge to see if the component should update itself (re-render) | ||
const bUpdateSelf = this.angularPConnect.shouldComponentUpdate(this); | ||
|
||
// Only call updateSelf when the component should update | ||
if (bUpdateSelf || this.hasRawMetadataChanged()) { | ||
this.updateSelf(); | ||
} | ||
} | ||
|
||
// this method will get overriden by the child component | ||
updateSelf() {} | ||
|
||
hasRawMetadataChanged(): boolean { | ||
const newChildrenMetadata = this.fetchChildrenMetadata(); | ||
|
||
if (!PCore.isDeepEqual(newChildrenMetadata, this.childrenMetadataOld)) { | ||
this.childrenMetadataOld = newChildrenMetadata; | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
fetchChildrenMetadata() { | ||
const children = this.pConn$.getChildren() || []; | ||
|
||
return children.map(child => { | ||
const pConnect = child.getPConnect(); | ||
return pConnect.resolveConfigProps(pConnect.getRawMetadata()); | ||
}); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...late-base/form-template-base.component.ts → ...nents/template/base/form-template-base.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.