-
Notifications
You must be signed in to change notification settings - Fork 250
Hide share button in TreeViewBase if user does not have permissions t… #5550
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
Hide share button in TreeViewBase if user does not have permissions t… #5550
Conversation
AlexVelezLl
left a comment
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.
Everything looks good with the production code! Just one little comment to make tests a little bit easier to read, and to prevent ourselves from having to make a lot of updates on these tests when we update this component to KDS.
| stubs: { | ||
| ToolBar: { | ||
| template: '<div><slot /><slot name="extension" /></div>', | ||
| }, | ||
| MainNavigationDrawer: true, | ||
| PublishSidePanel: true, | ||
| SubmitToCommunityLibrarySidePanel: true, | ||
| ProgressModal: true, | ||
| ChannelTokenModal: true, | ||
| SyncResourcesModal: true, | ||
| Clipboard: true, | ||
| OfflineText: true, | ||
| ContentNodeIcon: true, | ||
| DraggablePlaceholder: true, | ||
| MessageDialog: true, | ||
| SavingIndicator: true, | ||
| QuickEditModal: true, | ||
| BaseMenu: { | ||
| name: 'BaseMenu', | ||
| template: | ||
| '<div><slot name="activator" :on="{}" /><div class="menu-content"><slot /></div></div>', | ||
| }, | ||
| KButton: { | ||
| template: '<button class="share-button"><slot /></button>', | ||
| }, | ||
| VList: { | ||
| template: '<div class="v-list"><slot /></div>', | ||
| }, | ||
| VListTile: { | ||
| template: '<div class="v-list-tile"><slot /></div>', | ||
| }, | ||
| VListTileTitle: { | ||
| template: '<div class="v-list-tile-title"><slot /></div>', | ||
| }, | ||
| }, | ||
| }); | ||
| }; | ||
|
|
||
| const getShareButton = wrapper => { | ||
| const allBaseMenus = wrapper.findAllComponents({ name: 'BaseMenu' }); | ||
| for (let i = 0; i < allBaseMenus.length; i++) { | ||
| const baseMenu = allBaseMenus.at(i); | ||
| const shareButton = baseMenu.find('.share-button'); | ||
| if (shareButton.exists()) { | ||
| return shareButton; | ||
| } | ||
| } | ||
| return { exists: () => false }; | ||
| }; | ||
| const getShareMenuItems = wrapper => { | ||
| const allBaseMenus = wrapper.findAllComponents({ name: 'BaseMenu' }); | ||
| for (let i = 0; i < allBaseMenus.length; i++) { | ||
| const baseMenu = allBaseMenus.at(i); | ||
| const shareButton = baseMenu.find('.share-button'); | ||
| if (shareButton.exists()) { | ||
| return baseMenu.findAll('.v-list-tile'); | ||
| } | ||
| } | ||
| return { length: 0, wrappers: [] }; | ||
| }; |
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.
Although stubbing these components may make the tests run faster, I don't think we need to stub every child/descendant component. For example, I don't think we may need to stub presentational components like the VList, VListTile, VListTileTitle, etc. And components like KButton neither. I think we can perhaps just stub some components for which setting up the environment for them to work properly is not worth it, e.g. the QuickEditModal component.
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 Alex, I've fixed the code.
AlexVelezLl
left a comment
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!
…o see any option
Summary
Fixes issue by hiding the Share button in TreeViewBase when the user cannot use any share options.
Added canShareChannel (returns true if canManage or isPublished) to control button visibility.
Added CanSubmitToCommunityLibrary to control the "Submit to community library" menu item.
The Share button now renders only when at least one option is available (invite collaborators, share token, or submit to community library), and each menu item is conditionally shown based on permissions.
Added tests covering computed properties, button visibility, and menu item visibility across permission and channel state combinations.
References
Fixed #5453
Reviewer guidance
Run unit tests or Test manually.