Skip to content
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

Add count prop to OuiTreeView #934 #1138

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
- Adjust background color of OuiToolTip in `next` theme ([#1004](https://github.com/opensearch-project/oui/pull/1004))
- Add new `middle-out` order prop option to `OuiPaletteColorBlind` ([#856](https://github.com/opensearch-project/oui/pull/856))
- Add new icons for OpenSearch Dashboards v2.10.0 ([#1014](https://github.com/opensearch-project/oui/pull/1014))
- Add count prop to OuiTreeView with OuiFacetButton ([[#934](https://github.com/opensearch-project/oui/issues/934)])
- Add `onFullScreenChange` to `OuiDataGrid` ([#1053](https://github.com/opensearch-project/oui/pull/1053))

### 🐛 Bug Fixes
Expand Down
99 changes: 89 additions & 10 deletions src/components/tree_view/__snapshots__/tree_view.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,28 @@ exports[`OuiTreeView is rendered 1`] = `
data-ouiicon-type="folderOpen"
/>
</span>
</button>
<button
class="ouiFacetButton ouiFacetButton--unSelected ouiTreeView_ouiFacetButton"
type="button"
>
<span
class="ouiTreeView__nodeLabel"
class="ouiFacetButton__content"
>
Item One
<span
class="ouiFacetButton__text"
>
<span
class="ouiTreeView__nodeLabel"
>
Item One
</span>
</span>
<span
class="ouiNotificationBadge ouiNotificationBadge--medium ouiNotificationBadge--subdued ouiFacetButton__quantity"
>
3
</span>
</span>
</button>
<div
Expand Down Expand Up @@ -67,10 +85,23 @@ exports[`OuiTreeView is rendered 1`] = `
data-ouiicon-type="document"
/>
</span>
</button>
<button
class="ouiFacetButton ouiFacetButton--unSelected ouiTreeView_ouiFacetButton"
type="button"
>
<span
class="ouiTreeView__nodeLabel"
class="ouiFacetButton__content"
>
Item A
<span
class="ouiFacetButton__text"
>
<span
class="ouiTreeView__nodeLabel"
>
Item A
</span>
</span>
</span>
</button>
<div
Expand All @@ -94,10 +125,28 @@ exports[`OuiTreeView is rendered 1`] = `
data-ouiicon-type="arrowRight"
/>
</span>
</button>
<button
class="ouiFacetButton ouiFacetButton--unSelected ouiTreeView_ouiFacetButton"
type="button"
>
<span
class="ouiTreeView__nodeLabel"
class="ouiFacetButton__content"
>
Item B
<span
class="ouiFacetButton__text"
>
<span
class="ouiTreeView__nodeLabel"
>
Item B
</span>
</span>
<span
class="ouiNotificationBadge ouiNotificationBadge--medium ouiNotificationBadge--subdued ouiFacetButton__quantity"
>
2
</span>
</span>
</button>
<div
Expand All @@ -121,10 +170,28 @@ exports[`OuiTreeView is rendered 1`] = `
data-ouiicon-type="arrowRight"
/>
</span>
</button>
<button
class="ouiFacetButton ouiFacetButton--unSelected ouiTreeView_ouiFacetButton"
type="button"
>
<span
class="ouiTreeView__nodeLabel"
class="ouiFacetButton__content"
>
Item C
<span
class="ouiFacetButton__text"
>
<span
class="ouiTreeView__nodeLabel"
>
Item C
</span>
</span>
<span
class="ouiNotificationBadge ouiNotificationBadge--medium ouiNotificationBadge--subdued ouiFacetButton__quantity"
>
2
</span>
</span>
</button>
<div
Expand All @@ -144,11 +211,23 @@ exports[`OuiTreeView is rendered 1`] = `
class="ouiTreeView__nodeInner"
data-test-subj="ouiTreeViewButton-ouiTreeView_generated-id"
id="item_two"
/>
<button
class="ouiFacetButton ouiFacetButton--unSelected ouiTreeView_ouiFacetButton"
type="button"
>
<span
class="ouiTreeView__nodeLabel"
class="ouiFacetButton__content"
>
Item Two
<span
class="ouiFacetButton__text"
>
<span
class="ouiTreeView__nodeLabel"
>
Item Two
</span>
</span>
</span>
</button>
<div
Expand Down
5 changes: 5 additions & 0 deletions src/components/tree_view/tree_view.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@

}

.ouiTreeView_ouiFacetButton {
text-align-last: center;
padding: none;
}

.ouiTreeView__nodeLabel {
@include ouiTextTruncate;
}
Expand Down
27 changes: 21 additions & 6 deletions src/components/tree_view/tree_view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { OuiScreenReaderOnly } from '../accessibility';
import { OuiText } from '../text';
import { keys, htmlIdGenerator } from '../../services';
import { OuiInnerText } from '../inner_text';
import { OuiFacetButton } from '../facet';

const OuiTreeViewContext = createContext<string>('');

Expand Down Expand Up @@ -118,6 +119,8 @@ export type CommonTreeProps = CommonProps &
* that contain children
*/
showExpansionArrows?: boolean;
/** Number of child components within tree view node
*/
};

export type OuiTreeViewProps = Omit<
Expand Down Expand Up @@ -307,7 +310,7 @@ export class OuiTreeView extends Component<OuiTreeViewProps, OuiTreeViewState> {
{items.map((node, index) => {
const buttonId = node.id;
const wrappingId = this.treeIdGenerator(buttonId);

const count = node.children?.length;
return (
<OuiInnerText
key={node.id + index}
Expand Down Expand Up @@ -389,11 +392,23 @@ export class OuiTreeView extends Component<OuiTreeViewProps, OuiTreeViewState> {
{node.useEmptyIcon && !node.icon ? (
<span className="ouiTreeView__iconPlaceholder" />
) : null}
<span
ref={ref}
className="ouiTreeView__nodeLabel">
{node.label}
</span>
{count === 0 ? (
<span
ref={ref}
className="ouiTreeView__nodeLabel">
{node.label}
</span>
) : (
<OuiFacetButton
quantity={count}
className="ouiTreeView_ouiFacetButton">
<span
ref={ref}
className="ouiTreeView__nodeLabel">
{node.label}
</span>
</OuiFacetButton>
)}
</button>
<div
id={wrappingId}
Expand Down