-
Notifications
You must be signed in to change notification settings - Fork 3.4k
feat(panel): Allow panels to be part of multiple groups. #9830
Conversation
| @@ -895,7 +898,12 @@ MdPanelService.prototype.create = function(config) { | |||
| this._config.scope.$on('$destroy', angular.bind(panelRef, panelRef.detach)); | |||
|
|
|||
| if (this._config.groupName) { | |||
| panelRef.addToGroup(this._config.groupName); | |||
| if (angular.isString(this._config.groupName)) { | |||
| this._config.groupName = [this._config.groupName]; | |||
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.
It seems like the _groupName got converted into an array. I think it's more appropriate to call it something like _groups since an array implies multiple groups.
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.
The groupName here refers to the parameter that the user passes from the panel configuration. Since it can be either a single groupName or an array of groupNames, I was concerned about changing its name.
@ErinCoughlan what do you think about the naming convention here? Let's get the whole team's buy-in.
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.
Oh, sorry, I must've misread it as this._groupName.
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 think groupName works here.
| @@ -987,7 +995,7 @@ MdPanelService.prototype.setGroupMaxOpen = function(groupName, maxOpen) { | |||
| * @private | |||
| */ | |||
| MdPanelService.prototype._openCountExceedsMaxOpen = function(groupName) { | |||
| if (groupName && this._groups[groupName]) { | |||
| if (this._groups[groupName]) { | |||
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.
Using indexOf here should be more appropriate. This will break with a group name of toString.
| if (groupName) { | ||
| this._groups[groupName].openPanels[0].close(); | ||
| } | ||
| this._groups[groupName].openPanels[0].close(); |
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.
Might be appropriate to have a check here that there are any open panels.
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.
This function is actually only fired from the _openCountExceedsMaxOpen method above it. That method checks if the current number of open panels within the group exceeds the maximum limit and if so, the _closeFirstOpenedPanel method is called to close the first opened panel.
| * for configuring the number of open panels and identifying specific | ||
| * behaviors for groups. For instance, all tooltips could be identified | ||
| * using the same groupName. | ||
| * - `groupName` - `{(string|string[])=}`: A single name of a panel group. Can |
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: You're saying "a single name of a group" and "can also be an array" in two consecutive sentences. Might be better to say something along the lines of "A group name or an array of groups".
|
When you ping for review, please mark as "needs: review" and "in-progress". |
7d2ade5 to
66afca2
Compare
|
@ErinCoughlan @crisbeto @DerekLouie Please review changes and provide feedback or LGTM. |
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.
LGTM 👍
66afca2 to
82ba80a
Compare
|
@ErinCoughlan Waiting on your final review for this PR. |
| * for configuring the number of open panels and identifying specific | ||
| * behaviors for groups. For instance, all tooltips could be identified | ||
| * using the same groupName. | ||
| * - `groupName` - `{(string|string[])=}`: A group name or an array of group |
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.
!Array
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 few questions, but overall LGTM.
| @@ -895,7 +898,12 @@ MdPanelService.prototype.create = function(config) { | |||
| this._config.scope.$on('$destroy', angular.bind(panelRef, panelRef.detach)); | |||
|
|
|||
| if (this._config.groupName) { | |||
| panelRef.addToGroup(this._config.groupName); | |||
| if (angular.isString(this._config.groupName)) { | |||
| this._config.groupName = [this._config.groupName]; | |||
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 think groupName works here.
| @@ -1139,18 +1164,38 @@ describe('$mdPanel', function() { | |||
| expect(getGroupPanels('test')).not.toContain(panel); | |||
| }); | |||
|
|
|||
| it('should remove a panel from a group on panel destroy', function() { | |||
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.
Why are you removing the single group tests? The config is different, so I think you still need a test or two here.
| expect(getGroupOpenPanels('test2')).toContain(panelRef); | ||
|
|
||
| closePanel(); | ||
| flushPanel(); |
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 thought there was a flushPanel at the end of the closePanel. Why do you need another one?
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.
It's still here? And there's no response to the question?
| maxOpen: 2 | ||
| }); | ||
| $mdPanel.newPanelGroup('test2', { | ||
| maxOpen: 2 |
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.
Please choose different maxOpen for each group so we can also verify the maxes are being set of the right panels.
|
|
||
| var panel1 = $mdPanel.create(config1); | ||
| var panel2 = $mdPanel.create(config1); | ||
|
|
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.
Why the extra new line here?
9c2107b to
073bcc5
Compare
|
@ErinCoughlan Ping to approve your latest review. |
| expect(getGroupOpenPanels('test2')).toContain(panelRef); | ||
|
|
||
| closePanel(); | ||
| flushPanel(); |
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.
It's still here? And there's no response to the question?
| var panel3 = $mdPanel.create(config2); | ||
| var panel4 = $mdPanel.create(config3); | ||
| var panel5 = $mdPanel.create(config3); | ||
| var panel6 = $mdPanel.create(config3); |
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.
This just got way too complicated. How about one group with maxOpen = 1 and one group with maxOpen =2? I don't understand why you need 6 panels to test this, even with the current values.
It would also be useful to name these related to what their config is. Below when you say panel4, I have no idea which config that is using, so it's hard to understand what you are testing and even harder to know whether it is correct.
The groupName parameter has been changed from allowing only a string to allowing a string or an array of strings. All of the necessary functionality has been changed to accompany the array. Fixes angular#9565
073bcc5 to
7809bf2
Compare
|
@ErinCoughlan Latest ping! |
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.
Thanks. LGTM
|
@ThomasBurleson Final LGTM has been given. |
The groupName parameter has been changed from allowing only a string to allowing a string or an array of strings. All of the necessary functionality has been changed to accompany the array.
Fixes #9565
Ping @ErinCoughlan @crisbeto and @DerekLouie for review.