Skip to content

[IMPAC-648] v1.6.0 - Refactor "data not found" mode#385

Merged
cesar-tonnoir merged 25 commits intomaestrano:1.6from
cesar-tonnoir:feature/demo-data
Aug 18, 2017
Merged

[IMPAC-648] v1.6.0 - Refactor "data not found" mode#385
cesar-tonnoir merged 25 commits intomaestrano:1.6from
cesar-tonnoir:feature/demo-data

Conversation

@cesar-tonnoir
Copy link
Copy Markdown
Contributor

@cesar-tonnoir cesar-tonnoir commented Aug 14, 2017

  • Better styling and wording
  • Example mode with stub data
  • Update delete widget 'pop-up' to match the new design
  • Slight refactor of WidgetSvc

@cesar-tonnoir
Copy link
Copy Markdown
Contributor Author

@xaun this is ready - can you please review?
goes with: https://github.com/maestrano/impac/pull/486

@cesar-tonnoir cesar-tonnoir changed the base branch from release/1.5.6 to 1.6 August 15, 2017 15:29
@cesar-tonnoir cesar-tonnoir changed the base branch from 1.6 to release/1.5.6 August 15, 2017 15:31
@cesar-tonnoir cesar-tonnoir changed the base branch from release/1.5.6 to 1.6 August 16, 2017 04:28
@cesar-tonnoir cesar-tonnoir changed the title Refactor "data not found" mode [IMPAC-648] v1.6.0 - Refactor "data not found" mode Aug 16, 2017
Copy link
Copy Markdown
Contributor

@xaun xaun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) ->
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 done


scope.deleteWidget = ->
scope.loading = true
ImpacWidgetsSvc.delete(scope.parentWidget)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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/).

Comment thread src/services/widgets/widgets.svc.coffee Outdated

# 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) ->
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the demo flag should be within an opts arg instead? More flexible with future additions.

Comment thread karma-min.conf.js
'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',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this needs to be commited?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread karma.conf.js
'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',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

(updatedWidget) ->
_self.show(updatedWidget).finally( -> updatedWidget.isLoading = false )
)
promises.push _self.update(wgt, { metadata: wgt.metadata })
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the .then((updatedWidget)-> updatedWidget.isLoading = false not needed anymore?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@cesar-tonnoir
Copy link
Copy Markdown
Contributor Author

@xaun thanks for the review. I've applied your suggestions.
I'm going to merge the PR as this needs to be deployed tonight. Please let me know if you have any other comment.

@cesar-tonnoir cesar-tonnoir merged commit fd4c6f1 into maestrano:1.6 Aug 18, 2017
@xaun
Copy link
Copy Markdown
Contributor

xaun commented Aug 23, 2017

@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

@cesar-tonnoir cesar-tonnoir deleted the feature/demo-data branch November 6, 2017 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants