Skip to content

Commit cb4143c

Browse files
committed
Use getPartialTree in search
1 parent 47f1b70 commit cb4143c

File tree

10 files changed

+74
-141
lines changed

10 files changed

+74
-141
lines changed

apps/webapp/src/Components/Sidebar/Sidebar.views.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ import {
2121
StyledTreeItem
2222
} from '@mexit/shared'
2323

24-
import { useViews } from '../../Hooks/useViews'
2524
import { useViewStore } from '../../Stores/useViewStore'
2625
import { SortableTree } from '../Tree'
2726
import { FlattenedItem } from '../Tree/types'
28-
import { buildTree, flattenTree } from '../Tree/utilities'
27+
import { buildPartialTree, buildTree, flattenTree } from '../Tree/utilities'
2928

3029
const SidebarViewTree = ({ defaultItems, onClick, onContextMenu }) => {
3130
const [source, target] = useSingleton()
@@ -41,7 +40,6 @@ const SidebarViewTree = ({ defaultItems, onClick, onContextMenu }) => {
4140
const [search, setSearch] = useState('')
4241
const expandSidebar = useLayoutStore((store) => store.expandSidebar)
4342
const [selected, setSelected] = useState<number>(-1)
44-
const { getViewNamedPath } = useViews()
4543
const onSearchChange: ChangeEventHandler<HTMLInputElement> = (e) => {
4644
setSearch(e.target.value)
4745
}
@@ -57,7 +55,8 @@ const SidebarViewTree = ({ defaultItems, onClick, onContextMenu }) => {
5755
id: view.id,
5856
parentId: parent,
5957
properties: {
60-
label: view.title
58+
label: view.title,
59+
path: view.path
6160
},
6261
depth: 0,
6362
index: 0,
@@ -74,12 +73,13 @@ const SidebarViewTree = ({ defaultItems, onClick, onContextMenu }) => {
7473
if (search !== '') {
7574
const items = flattenTree(tree)
7675
const matchedFlatItems = fuzzySearch(items, search, (item) => item.properties.label)
77-
const filteredTree = buildTree(matchedFlatItems)
76+
const filteredTree = buildPartialTree(matchedFlatItems, items)
77+
7878
setFiltered({ filteredTree, matchedFlatItems })
7979
} else {
8080
setFiltered({ filteredTree: undefined, matchedFlatItems: [] })
8181
}
82-
}, [search, tree])
82+
}, [search])
8383

8484
const reset = () => {
8585
setSearch('')

apps/webapp/src/Components/Sidebar/TaskViewList.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const ViewList = () => {
2727

2828
const handleContextMenu = (id: string, event) => {
2929
const view = useViewStore.getState().views?.find((view) => view.id === id)
30-
console.log('VIEW LIST', { view, id, views: useViewStore.getState().views })
30+
3131
setContextMenu({
3232
type: ContextMenuType.VIEW_LIST,
3333
item: { data: view },

apps/webapp/src/Components/Tree/SortableTree.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const SortableTree = ({
5151

5252
return (
5353
<SortableContext items={sortedIds} strategy={verticalListSortingStrategy}>
54-
{flattenedItems.map(({ id, children, properties, collapsed, depth }) => (
54+
{flattenedItems.map(({ id, children, properties, isStub, collapsed, depth }) => (
5555
<SortableTreeItem
5656
key={id}
5757
id={id}
@@ -64,6 +64,7 @@ export const SortableTree = ({
6464
indentationWidth={indentationWidth}
6565
indicator={indicator}
6666
childCount={children.length}
67+
isStub={isStub}
6768
collapsed={Boolean(collapsed && children.length)}
6869
onCollapse={collapsible && children.length ? () => handleCollapse(id) : undefined}
6970
activeId={activeId}

apps/webapp/src/Components/Tree/components/TreeItem/TreeItem.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface Props extends Omit<HTMLAttributes<HTMLLIElement>, 'id'> {
2323
childCount?: number
2424
clone?: boolean
2525
collapsed?: boolean
26+
isStub?: boolean
2627
depth: number
2728
disableInteraction?: boolean
2829
disableSelection?: boolean
@@ -44,6 +45,7 @@ export const TreeItem = forwardRef<HTMLDivElement, Props>(
4445
(
4546
{
4647
childCount,
48+
isStub,
4749
clone,
4850
depth,
4951
disableSelection,
@@ -72,6 +74,7 @@ export const TreeItem = forwardRef<HTMLDivElement, Props>(
7274
ghost={ghost}
7375
isHighlighted={value.id === highlightedId}
7476
indicator={indicator}
77+
isStub={isStub}
7578
active={value.id === activeId}
7679
disableSelection={!!disableSelection}
7780
onContextMenu={(e) => {

apps/webapp/src/Components/Tree/components/TreeItem/styled.tsx

+12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const TreeListItem = styled.li<{
66
indicator?: boolean
77
disableSelection?: boolean
88
active?: boolean
9+
isStub?: boolean
910
isHighlighted?: boolean
1011
disableInteraction?: boolean
1112
}>`
@@ -23,6 +24,17 @@ export const TreeListItem = styled.li<{
2324
color: ${theme.sidebar.tree.item.wrapper.active.textColor};
2425
`}
2526
27+
${({ isStub }) =>
28+
isStub &&
29+
css`
30+
opacity: 0.8;
31+
color: ${({ theme }) => theme.tokens.text.disabled};
32+
svg {
33+
color: ${({ theme }) => theme.tokens.text.disabled};
34+
}
35+
background-color: transparent;
36+
`}
37+
2638
${({ active, theme }) =>
2739
active
2840
? css`

apps/webapp/src/Components/Tree/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface TreeItem {
66
id: UniqueIdentifier
77
children: TreeItem[]
88
collapsed?: boolean
9+
isStub?: boolean
910
properties?: Record<string, any>
1011
}
1112

apps/webapp/src/Components/Tree/utilities.ts

+45-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { UniqueIdentifier } from '@dnd-kit/core'
22
import { arrayMove } from '@dnd-kit/sortable'
33

4+
import { getAllEntities } from '@mexit/core'
5+
46
import type { FlattenedItem, TreeItem, TreeItems } from './types'
57

68
export const iOS = /iPad|iPhone|iPod/.test(navigator.platform)
@@ -86,20 +88,51 @@ export function flattenTree(items: TreeItems): FlattenedItem[] {
8688
return flatten(items)
8789
}
8890

91+
const updateNode = (
92+
node: FlattenedItem,
93+
nodes: Record<string, TreeItem>,
94+
allItems: FlattenedItem[],
95+
options: Partial<{
96+
root: UniqueIdentifier
97+
isStub: boolean
98+
collapsed: boolean
99+
}> = {
100+
root: 'root',
101+
isStub: false,
102+
collapsed: false
103+
}
104+
) => {
105+
const id = node.id
106+
const parentId = node?.parentId ?? options.root
107+
const parent = nodes[parentId] ?? findItem(allItems, parentId)
108+
109+
if (!nodes[id]) {
110+
const updatedNode: TreeItem = {
111+
id,
112+
children: [],
113+
properties: node.properties,
114+
isStub: options.isStub,
115+
collapsed: options.collapsed
116+
}
117+
118+
nodes[id] = updatedNode
119+
parent?.children?.push(updatedNode)
120+
}
121+
}
122+
89123
export function buildPartialTree(items: FlattenedItem[], allItems: FlattenedItem[]) {
90124
const root: TreeItem = { id: 'root', children: [], properties: {} }
91125
const nodes: Record<string, TreeItem> = { [root.id]: root }
92126

93127
for (const item of items) {
94-
const { id, children } = item
95-
const parentId = item.parentId ?? root.id
96-
const parent = nodes[parentId] ?? findItem(allItems, parentId)
128+
const parents = getAllEntities(item.properties.path)
97129

98-
nodes[id] = { id, children }
99-
if (parent) {
100-
console.log('parent', { parent, item, allItems })
101-
parent.children.push(item)
130+
for (const id of parents) {
131+
const node = nodes[id] ?? (findItem(allItems, id) as any)
132+
updateNode(node, nodes, allItems, { root: root.id, isStub: true })
102133
}
134+
135+
updateNode(item, nodes, allItems)
103136
}
104137

105138
return root.children
@@ -111,12 +144,14 @@ export function buildTree(flattenedItems: FlattenedItem[]): TreeItems {
111144
const items = flattenedItems.map((item) => ({ ...item, children: [] }))
112145

113146
for (const item of items) {
114-
const { id, children, properties } = item
147+
const { id, children } = item
115148
const parentId = item.parentId ?? root.id
116149
const parent = nodes[parentId] ?? findItem(items, parentId)
117150

118-
nodes[id] = { id, children }
119-
if (parent) parent.children.push(item)
151+
if (!nodes[id]) {
152+
nodes[id] = { id, children }
153+
parent.children.push(item)
154+
}
120155
}
121156

122157
return root.children

apps/webapp/src/Hooks/useTreeFromLinks.ts

-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,5 @@ export const getPartialTreeFromLinks = (matchedLinks: ILink[], allLinks: ILink[]
5151
.filter((i) => tree.items[i].data.stub === false)
5252
.map((i) => tree.items[i])
5353

54-
// mog('Made the partialTree From Links', { matchedLinks, allLinks, tree, treeFlatItems })
55-
5654
return { tree, matchedFlatItems }
5755
}

apps/webapp/src/Views/Tasks.tsx

-118
This file was deleted.

libs/shared/src/Style/Sidebar.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,13 @@ export const StyledTreeItem = styled.div<{
216216
}
217217
`}
218218
219-
${({ isStub }) =>
219+
${({ isStub }) =>
220220
isStub &&
221221
css`
222-
color: ${({ theme }) => theme.colors.gray[5]};
222+
opacity: 0.8;
223+
color: ${({ theme }) => theme.tokens.text.disabled};
223224
svg {
224-
color: ${({ theme }) => theme.colors.gray[5]};
225+
color: ${({ theme }) => theme.tokens.text.disabled};
225226
}
226227
background-color: transparent;
227228
`}

0 commit comments

Comments
 (0)