Skip to content

Commit

Permalink
Added empty message into tree
Browse files Browse the repository at this point in the history
  • Loading branch information
nitrogenous committed Jan 22, 2024
1 parent 50012c1 commit 4ccacaf
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 20 deletions.
66 changes: 46 additions & 20 deletions components/lib/tree/Tree.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { PrimeReactContext } from '../api/Api';
import { localeOption, PrimeReactContext } from '../api/Api';
import { useHandleStyle } from '../componentbase/ComponentBase';
import { useMergeProps } from '../hooks/Hooks';
import { useUpdateEffect } from '../hooks/useUpdateEffect';
Expand Down Expand Up @@ -408,33 +408,59 @@ export const Tree = React.memo(
);
};

const createRootChildren = () => {
if (props.filter) {
filterChanged.current = true;
_filter();
}
const createEmptyMessageNode = () => {
const emptyMessageProps = mergeProps(
{
className: classNames(props.contentClassName, cx('emptyMessage'))
},
ptm('emptyMessage')
);

return (
<li {...emptyMessageProps}>
<span className="p-treenode-content">{localeOption('emptyMessage')}</span>
</li>
);
};

const value = getRootNode();
const createRootChildrenContainer = (children) => {
const containerProps = mergeProps(
{
className: classNames(props.contentClassName, cx('container')),
role: 'tree',
'aria-label': props.ariaLabel,
'aria-labelledby': props.ariaLabelledBy,
style: props.contentStyle,
...ariaProps
},
ptm('container')
);

return <ul {...containerProps}>{children}</ul>;
};

const createRootChildren = (value) => {
return value.map((node, index) => createRootChild(node, index, index === value.length - 1));
};

const createModel = () => {
if (props.value) {
const rootNodes = createRootChildren();
const containerProps = mergeProps(
{
className: classNames(props.contentClassName, cx('container')),
role: 'tree',
'aria-label': props.ariaLabel,
'aria-labelledby': props.ariaLabelledBy,
style: props.contentStyle,
...ariaProps
},
ptm('container')
);
if (props.filter) {
filterChanged.current = true;
_filter();
}

return <ul {...containerProps}>{rootNodes}</ul>;
const value = getRootNode();

if (value.length > 0) {
const rootNodes = createRootChildren(value);

return createRootChildrenContainer(rootNodes);
} else {
const emptyMessageNode = createEmptyMessageNode();

return createRootChildrenContainer(emptyMessageNode);
}
}

return null;
Expand Down
2 changes: 2 additions & 0 deletions components/lib/tree/TreeBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const classes = {
loadingIcon: 'p-tree-loading-icon',
loadingOverlay: 'p-tree-loading-overlay p-component-overlay',
searchIcon: 'p-tree-filter-icon',
emptyMessage: 'p-treenode p-tree-empty-message',
filterContainer: 'p-tree-filter-container',
input: 'p-tree-filter p-inputtext p-component',
header: 'p-tree-header',
Expand Down Expand Up @@ -117,6 +118,7 @@ export const TreeBase = ComponentBase.extend({
value: null,
checkboxIcon: null,
disabled: false,
emptyMessage: null,
selectionMode: null,
selectionKeys: null,
onSelectionChange: null,
Expand Down

0 comments on commit 4ccacaf

Please sign in to comment.