Skip to content

Commit

Permalink
refactor: prettier changes removed and attempt to show only one node
Browse files Browse the repository at this point in the history
  • Loading branch information
CarloBar1 committed Oct 25, 2024
1 parent 2222a52 commit e3df0c7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
23 changes: 15 additions & 8 deletions cosmoz-treenode-button-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import { html } from '@polymer/polymer/lib/utils/html-tag';
import '@neovici/cosmoz-dialog';
import { Tree } from '@neovici/cosmoz-tree';
import { translatable } from '@neovici/cosmoz-i18next';

import './cosmoz-treenode-navigator';
import { getNode, getTreePathParts } from './helpers';

/**
`cosmoz-treenode-navigator`
Navigator through object with treelike datastructure.
Expand Down Expand Up @@ -100,7 +102,7 @@ class CosmozTreenodeButtonView extends translatable(PolymerElement) {
key-property="pathLocator"
key-value="[[ nodePath ]]"
owner-tree="[[ cz.state.tree ]]"
show-max-nodes="1"
show-max-nodes="[[ showMaxNodes]]"
></cosmoz-treenode
>[[ buttonText ]]</span
>
Expand Down Expand Up @@ -269,6 +271,13 @@ class CosmozTreenodeButtonView extends translatable(PolymerElement) {
type: String,
value: 'Search or navigate to chosen destination',
},
/*
* Maximum number of shown nodes.
*/
showMaxNodes: {
type: Number,
value: 1,
},
/*
* Minimum length before an search
* starts.
Expand Down Expand Up @@ -338,11 +347,9 @@ class CosmozTreenodeButtonView extends translatable(PolymerElement) {
if (!Array.isArray(pathParts) || pathParts.length === 0) {
return placeholder;
}
const labels = pathParts
return pathParts
.filter((n) => n)
.map((part) => part[this.tree.searchProperty]);
console.log(labels);
return labels.join('/');
}
/**
* Get text from a node to set on a node chip.
Expand Down Expand Up @@ -389,20 +396,20 @@ class CosmozTreenodeButtonView extends translatable(PolymerElement) {

this.selectedNode = getNode(
this.highlightedNodePath || this.nodePath,
this.tree
this.tree,
);
if (this.highlightedNodePath) {
this.nodePath = this.highlightedNodePath;
}
this.nodesOnNodePath = getTreePathParts(
this.highlightedNodePath || this.nodePath,
this.tree
this.tree,
);

if (this.multiSelection) {
if (
!this.selectedNodes.some(
(node) => node.pathLocator === this.highlightedNodePath
(node) => node.pathLocator === this.highlightedNodePath,
)
) {
this.push('selectedNodes', this.selectedNode);
Expand Down Expand Up @@ -439,7 +446,7 @@ class CosmozTreenodeButtonView extends translatable(PolymerElement) {
timeOut.after(50), // 5 was enough during test
() => {
this.$.dialogTree.fit();
}
},
);
}

Expand Down
24 changes: 12 additions & 12 deletions cosmoz-treenode-navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ const TreenodeNavigator = (host) => {
[searchValue, setSearchValue] = useState(''),
search = useMemo(
() => (searchValue?.length > searchMinLength && searchValue) || undefined,
[searchValue, searchMinLength]
[searchValue, searchMinLength],
),
/**
* The currently displayed node list
*/
dataPlane = useMemo(
() => computeDataPlane(tree, search, openNodePath),
[tree, search, openNodePath]
[tree, search, openNodePath],
),
/**
* Opens a node (renderLevel) based on a given path
Expand All @@ -84,7 +84,7 @@ const TreenodeNavigator = (host) => {
setSearchValue('');
setHighlightedNode();
},
[tree]
[tree],
),
listRef = useRef();

Expand All @@ -105,7 +105,7 @@ const TreenodeNavigator = (host) => {
notifyProperty(
host,
'highlightedNodePath',
highlightedNode?.pathLocator || ''
highlightedNode?.pathLocator || '',
);
}, [highlightedNode]);

Expand Down Expand Up @@ -206,7 +206,7 @@ const TreenodeNavigator = (host) => {
<div class="section">
${tree.getPathString(parentPath, tree.searchProperty)}
</div>
`
`,
))(getParentPath(tree, node))}
<div
class=${computeRowClass('node', node, highlightedNode)}
Expand All @@ -231,10 +231,10 @@ const TreenodeNavigator = (host) => {
</g>
</svg>
</span>
`
`,
)}
</div>
</div>`
</div>`
: nothing;

return html`
Expand All @@ -260,8 +260,8 @@ const TreenodeNavigator = (host) => {
<span class="pointer" tabindex="0" @click=${() => openNode(node)}
>${node[tree.searchProperty]}</span
>
`
)
`,
),
)}
</h3>
<cosmoz-input
Expand All @@ -281,20 +281,20 @@ const TreenodeNavigator = (host) => {
renderItem,
scroller: true,
})}
</div>`
</div>`,
)}
${when(
search && openNodePath,
() => html`
<button class="btn-ghost" @click=${() => setOpenNodePath('')}>
${searchGlobalPlaceholder}
</button>
`
`,
)}
`;
};

customElements.define(
'cosmoz-treenode-navigator',
component(TreenodeNavigator)
component(TreenodeNavigator),
);

0 comments on commit e3df0c7

Please sign in to comment.