-
Notifications
You must be signed in to change notification settings - Fork 11
feat: conditional container widget #348
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
Conversation
Codecov Report
@@ Coverage Diff @@
## main #348 +/- ##
==========================================
- Coverage 86.28% 86.24% -0.04%
==========================================
Files 729 733 +4
Lines 14844 14875 +31
Branches 1896 1848 -48
==========================================
+ Hits 12808 12829 +21
- Misses 2005 2013 +8
- Partials 31 33 +2
Continue to review full report at Codecov.
|
type: ARRAY_PROPERTY.type, | ||
required: true | ||
}) | ||
public trueChildren: object[] = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤣
type: ARRAY_PROPERTY.type, | ||
required: true | ||
}) | ||
public falseChildren: object[] = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤣
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shhhhh. Don't tell them! 😂
private readonly api!: ModelApi; | ||
|
||
public getData(): Observable<boolean> { | ||
return this.api.getData<boolean>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Container may not have any data source. So why would this ever emit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A conditional container widget will require a datasource to determine which children to return.
@@ -18,15 +20,17 @@ import { ContainerWidgetModel } from './container-widget.model'; | |||
</div> | |||
` | |||
}) | |||
export class ContainerWidgetRendererComponent extends WidgetRenderer<ContainerWidgetModel> implements AfterViewInit { | |||
export class ContainerWidgetRendererComponent | |||
extends WidgetRenderer<ContainerWidgetModel | ConditionalContainerWidgetModel> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So two issues with this approach that I see -
- The renderer now has to know about different types of models (not a huge deal)
- The conditional works at a container level - this seems more problematic. If I want to condition one widget (which is more likely the case), does that mean it gets padded? What if the condition should change the layout? In my mind, I was thinking the conditional would always work with a single widget - that widget however could be a container itself, and handle its own layout.
I think one nice to have thing with the single widget approach is that if we do eventually add support for conditional models, it would use the exact same model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I had the same thoughts but actually stopped and stashed the new conditional-container-widget.model.ts
and conditional-container-widget-renderer.component.ts
I was going with to get feedback on this minimal approach first.
Is that the suggestion then? We want this to have its own model widget model and renderer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That'd be my suggestion, but of course alway welcome to push back. I would expect it to be no more code than this change (or close enough) and touch fewer existing files. It's trading a new pass through renderer for the changes to the existing renderer/container widget models. I also like the idea of going with simply conditional.model.ts
- We can implement that by associating a renderer right now, but once we build out model support any JSON using this for widgets remains identical (because a widget is jut a model with an associated renderer)
|
||
@ModelProperty({ | ||
key: 'false', | ||
type: PLAIN_OBJECT_PROPERTY.type, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ModelTemplatePropertyType.TYPE
} | ||
|
||
public getModel(): Observable<ModelJson> { | ||
return this.getData().pipe(map(result => (result ? this.true : this.false))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on how we're using this in the renderer, we should hydrate this modelJson, and return a real model - something like this.api.createChild(result ? this.true : this.false)
styleUrls: ['./conditional-widget-renderer.component.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
template: ` | ||
<div class="conditional-widget"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need the div? the instantiated widget should have its own container
` | ||
}) | ||
export class ConditionalWidgetRendererComponent extends WidgetRenderer<ConditionalModel> { | ||
@ViewChild('containerContent', { read: ViewContainerRef, static: true }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't appear used
<ng-container [hdaDashboardModel]="this.getModel() | async"> </ng-container> | ||
</div> | ||
` | ||
template: ` <ng-container [hdaDashboardModel]="this.getChildModel() | async"> </ng-container> ` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by virtue of making this our fetch data implementation, this is already available as this.data$
- we could inline line 16 into fetchData.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll fix this locally. Thanks.
public getModel(): Observable<ModelJson> { | ||
return this.model.getModel().pipe(takeUntil(this.destroyed$)); | ||
public getChildModel(): Observable<object> { | ||
return this.model.getChildModel().pipe(takeUntil(this.destroyed$)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this takeUntil isn't a problem but not necessary ( we used to use these a lot more if you were looking at old code - now we try instead where possible to push the subscriptions into the DOM which will auto unsubscribe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix locally. Thanks.
Description
Container widget that allows a datasource to provide one of two different children[] based on a conditional query or check.
Testing
This is not the entire implementation. Just base code to enable an extended data source.
Checklist: