This repository has been archived by the owner on Aug 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Toolbar: add 'kebabLimit' option. #162
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8e1ef18
Toolbar: add 'kebabLimit' option.
martinpovolny a50e70d
Toolbar: make count prop optional for easier use.
martinpovolny eca9656
Tests: skip a failing test for an unused component.
martinpovolny a0d656b
Tests: update snapshot for IconPicker.
martinpovolny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,17 +52,33 @@ const buttonCase = (item, index, onClick) => { | |
/* custom buttons have ID's starting with this: */ | ||
const CUSTOM_ID = 'custom_'; | ||
|
||
const collapseCustomGroups = itemsGroup => ( | ||
itemsGroup.length < 4 | ||
? itemsGroup | ||
: itemsGroup.reduce((acc, i) => { | ||
if (i.id.includes(CUSTOM_ID)) { | ||
acc[0].items.push(i); | ||
const collapseOverlimit = (itemsGroup, kebabLimit) => { | ||
let numItems = 0; | ||
|
||
return itemsGroup.reduce((acc, i) => { | ||
if (i.id.includes(CUSTOM_ID)) { | ||
if (numItems >= kebabLimit) { | ||
acc[acc.length - 1].items.push(i); | ||
} else { | ||
acc.push(i); | ||
numItems += 1; | ||
acc.splice(acc.length - 1, 0, i); | ||
} | ||
return acc; | ||
}, [{ type: ButtonType.KEBAB, items: [] }]) | ||
} else { | ||
acc.splice(acc.length - 1, 0, i); | ||
} | ||
return acc; | ||
}, [{ type: ButtonType.KEBAB, items: [] }]); | ||
}; | ||
|
||
/* | ||
* kebabLimit === -1 means no compacting | ||
* kebabLimit === 0 means always compact into kebab | ||
* other values of kebabLimit give number of items to keep, before the rest is kebabized | ||
*/ | ||
const collapseCustomGroups = (itemsGroup, kebabLimit) => ( | ||
(kebabLimit === -1) || (itemsGroup.length < kebabLimit) | ||
? itemsGroup | ||
: collapseOverlimit(itemsGroup, kebabLimit) | ||
); | ||
|
||
export const ToolbarGroup = ({ group, onClick }) => { | ||
|
@@ -91,17 +107,23 @@ export const Toolbar = props => ( | |
.filter(toolbarGroupHasContent) | ||
.map((group, index) => | ||
/* eslint react/no-array-index-key: "off" */ | ||
<ToolbarGroup key={index} onClick={props.onClick} group={collapseCustomGroups(group)} />) | ||
<ToolbarGroup key={index} onClick={props.onClick} group={collapseCustomGroups(group, props.kebabLimit)} />) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose we don't have anything better than index right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not for the group. But the index is stable. |
||
} | ||
<ToolbarView onClick={props.onViewClick} views={props.views} /> | ||
</div> | ||
</CountContext.Provider> | ||
); | ||
|
||
Toolbar.propTypes = { | ||
count: PropTypes.number.isRequired, | ||
count: PropTypes.number, | ||
kebabLimit: PropTypes.number, | ||
groups: PropTypes.arrayOf(PropTypes.any), // array of arrays of buttons | ||
views: PropTypes.arrayOf(PropTypes.any), // array of view buttons | ||
onClick: PropTypes.func.isRequired, | ||
onViewClick: PropTypes.func.isRequired, | ||
}; | ||
|
||
Toolbar.defaultProps = { | ||
count: 0, | ||
kebabLimit: 3, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can I ask what does the count does and why is it required?
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.
In manageiq the toolbar needs count of selected items in the GTL on the page.
Anyway: making it optional, adding default value.