[IMPAC-648] v1.6.0 - Refactor "data not found" mode#385
[IMPAC-648] v1.6.0 - Refactor "data not found" mode#385cesar-tonnoir merged 25 commits intomaestrano:1.6from
Conversation
|
@xaun this is ready - can you please review? |
e355ebb to
d364f57
Compare
+ improve styling and messaging + remove background images from template + remove myob custom message
+ handle widget.isLoading in the service + #show to call itself again with `demo=true` when no data found + refactor returned promises
d364f57 to
461fb15
Compare
xaun
left a comment
There was a problem hiding this comment.
Looks good, just requesting changes for new components to be written as a .component
| @@ -0,0 +1,20 @@ | |||
| module = angular.module('impac.components.common.delete-widget',[]) | |||
|
|
|||
| module.directive('commonDeleteWidget', ($templateCache, ImpacWidgetsSvc, ImpacUtilities) -> | |||
There was a problem hiding this comment.
For new components, we should be leveraging the angular .component.
bindings: {
# one-way binding
parentWidget: '<'
}
...
# lifecycle hooks
ctrl.$ngOnInit = ->
ctrl.loading = false
.directives should really only be used now to attach functionality onto an element. For example the impac-angular/src/components/widgets-common/autofocus/autofocus.directive.coffee directive.
|
|
||
| scope.deleteWidget = -> | ||
| scope.loading = true | ||
| ImpacWidgetsSvc.delete(scope.parentWidget) |
There was a problem hiding this comment.
It should be the parents (impacWidget) responsibility to make the backend request to delete the widget. This component should just emit an event via an onDelete callback.
There was a problem hiding this comment.
I don't completely agree with this one: as the component is called "delete-widget", one can expect it is going to actually delete the widget by calling the WidgetsSvc... Otherwise, you always put all the logic in a single "widget" component.
I'll apply your suggestion, we can always revert later if needed.
There was a problem hiding this comment.
@cesar-tonnoir I think @alexnoox agrees with me judging by the reaction.. I was going to ask for his input. The delete-widget should just be a presentational component. If you apply what you have done to all components, you will find that your codebase makes requests to APIs from all sorts of places. It seems logically for it to encapsulate the request as it's purpose it to delete. But it actually makes much more sense for the widget.component to be the "smart component", and for it to make the request to the widget service.
Also, think about having many components like this, you will then have the WidgetsSvc dependency across many different places, and it becomes hard to follow.
You can read up on this design pattern by searching "smart components dumb components" or "smart components presentational components" (e.g http://blog.angular-university.io/angular-2-smart-components-vs-presentation-components-whats-the-difference-when-to-use-each-and-why/).
|
|
||
| # Calls Legacy Impac! or bolt API to render a widget | ||
| # If no content is returned, the endpoint will be called again with `demo` = `true` to retrieve stub data | ||
| @show = (widget, refreshCache = false, demo = false) -> |
There was a problem hiding this comment.
Maybe the demo flag should be within an opts arg instead? More flexible with future additions.
| 'bower_components/angular-xeditable/dist/js/xeditable.js', | ||
| 'bower_components/angular-toastr/dist/angular-toastr.tpls.js', | ||
| 'bower_components/bootstrap/dist/js/bootstrap.js', | ||
| 'bower_components/ng-tags-input/ng-tags-input.js', |
There was a problem hiding this comment.
Not sure this needs to be commited?
There was a problem hiding this comment.
I think this should have been part of v1.5.6, it keeps appearing every time I run the specs...
As all the other bower_components are committed, wouldn't it be more consistent to add this one as well?
There was a problem hiding this comment.
Yeah if it is a bower_component then it should be committed. But as I cannot see it in the bower.json I thought it was a mistake. I just tested though and it's writing it to my karma files on gulp test too.. Must be a sub-dep
| 'bower_components/angular-xeditable/dist/js/xeditable.js', | ||
| 'bower_components/angular-toastr/dist/angular-toastr.tpls.js', | ||
| 'bower_components/bootstrap/dist/js/bootstrap.js', | ||
| 'bower_components/ng-tags-input/ng-tags-input.js', |
| (updatedWidget) -> | ||
| _self.show(updatedWidget).finally( -> updatedWidget.isLoading = false ) | ||
| ) | ||
| promises.push _self.update(wgt, { metadata: wgt.metadata }) |
There was a problem hiding this comment.
Is the .then((updatedWidget)-> updatedWidget.isLoading = false not needed anymore?
There was a problem hiding this comment.
No, that's an improvement: the loader is now fully managed by the #show and #update methods in the service.
We don't need to care about it in the controllers or other methods anymore.
|
@xaun thanks for the review. I've applied your suggestions. |
|
@cesar-tonnoir In my review I forgot to highlight the fact that a config change was made & the README.md configurations section(s) were not updated. Do you think you could patch this? Cheers |
WidgetSvc