@edifice.io/react 2.2.2-develop-b2school.20250408113943 → 2.2.2-develop-b2school.20250408143232

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,5 +9,6 @@ declare function useWorkspaceFolders(): {
9
9
  name: string;
10
10
  children: FolderTreeNode[];
11
11
  }[];
12
+ setSearchQuery: import('react').Dispatch<import('react').SetStateAction<string>>;
12
13
  };
13
14
  export default useWorkspaceFolders;
@@ -1,6 +1,6 @@
1
1
  import { odeServices } from "@edifice.io/client";
2
2
  import { useQuery } from "@tanstack/react-query";
3
- import { useMemo } from "react";
3
+ import { useState, useMemo } from "react";
4
4
  import { useTranslation } from "react-i18next";
5
5
  function useWorkspaceFolders() {
6
6
  const {
@@ -10,16 +10,22 @@ function useWorkspaceFolders() {
10
10
  } = useQuery({
11
11
  queryKey: ["workspace-folders"],
12
12
  queryFn: () => odeServices.workspace().listFolder("owner", !0)
13
- });
13
+ }), [searchQuery, setSearchQuery] = useState(""), filterTree = (nodes, search) => nodes.map((node) => {
14
+ const filteredChildren = node.children ? filterTree(node.children, search) : [];
15
+ return node.name.toLowerCase().includes(search.toLowerCase()) || filteredChildren.length > 0 ? {
16
+ ...node,
17
+ children: filteredChildren
18
+ } : null;
19
+ }).filter((node) => node !== null);
14
20
  return {
15
21
  folderTree: useMemo(() => {
16
22
  const buildWorkspaceTree = (data) => [{
17
- id: "my-documents",
23
+ id: "",
18
24
  name: t("workspace.myDocuments"),
19
25
  children: data
20
26
  }];
21
27
  if (!folderData) return buildWorkspaceTree([]);
22
- const nodes = /* @__PURE__ */ new Map(), tree = [];
28
+ const nodes = /* @__PURE__ */ new Map(), fullTree = [];
23
29
  return folderData.forEach((item) => {
24
30
  nodes.set(item._id, {
25
31
  id: item._id,
@@ -27,9 +33,10 @@ function useWorkspaceFolders() {
27
33
  children: []
28
34
  });
29
35
  }), folderData.forEach((item) => {
30
- item.eParent && nodes.has(item.eParent) ? nodes.get(item.eParent).children.push(nodes.get(item._id)) : tree.push(nodes.get(item._id));
31
- }), buildWorkspaceTree(tree);
32
- }, [folderData])
36
+ item.eParent && nodes.has(item.eParent) ? nodes.get(item.eParent).children.push(nodes.get(item._id)) : fullTree.push(nodes.get(item._id));
37
+ }), buildWorkspaceTree(searchQuery ? filterTree(fullTree, searchQuery) : fullTree);
38
+ }, [folderData, searchQuery]),
39
+ setSearchQuery
33
40
  };
34
41
  }
35
42
  export {
@@ -1,6 +1,8 @@
1
1
  import { jsxs, jsx } from "react/jsx-runtime";
2
2
  import { useTranslation } from "react-i18next";
3
+ import { useState } from "react";
3
4
  import useWorkspaceFolders from "../../../hooks/useWorkspaceFolders/useWorkspaceFolders.js";
5
+ import SearchBar from "../../../components/SearchBar/SearchBar.js";
4
6
  import Tree from "../../../components/Tree/components/Tree.js";
5
7
  function WorkspaceFolders({
6
8
  onFolderSelected
@@ -8,11 +10,17 @@ function WorkspaceFolders({
8
10
  const {
9
11
  t
10
12
  } = useTranslation(), {
11
- folderTree
12
- } = useWorkspaceFolders();
13
+ folderTree,
14
+ setSearchQuery
15
+ } = useWorkspaceFolders(), [shouldExpandAllNodes, setShouldExpandAllNodes] = useState(!1), [searchValue, setSearchValue] = useState(""), handleSearchChange = (e) => {
16
+ setSearchValue(e.target.value);
17
+ }, handleSearchSubmit = () => {
18
+ setSearchQuery(searchValue), setShouldExpandAllNodes(searchValue !== "");
19
+ };
13
20
  return /* @__PURE__ */ jsxs("div", { className: "d-flex flex-column gap-12", children: [
14
21
  /* @__PURE__ */ jsx("p", { children: t("attachments.add.to.folder.modal.description") }),
15
- /* @__PURE__ */ jsx("div", { className: "border border-gray-400 rounded", children: /* @__PURE__ */ jsx("div", { className: "p-12", children: /* @__PURE__ */ jsx(Tree, { nodes: folderTree, onTreeItemClick: onFolderSelected }) }) })
22
+ /* @__PURE__ */ jsx(SearchBar, { onChange: handleSearchChange, isVariant: !1, placeholder: t("search"), onClick: handleSearchSubmit }),
23
+ /* @__PURE__ */ jsx("div", { className: "border border-gray-400 rounded", children: /* @__PURE__ */ jsx("div", { className: "p-12", children: /* @__PURE__ */ jsx(Tree, { nodes: folderTree, onTreeItemClick: onFolderSelected, shouldExpandAllNodes }) }) })
16
24
  ] });
17
25
  }
18
26
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edifice.io/react",
3
- "version": "2.2.2-develop-b2school.20250408113943",
3
+ "version": "2.2.2-develop-b2school.20250408143232",
4
4
  "description": "Edifice React Library",
5
5
  "keywords": [
6
6
  "react",
@@ -118,9 +118,9 @@
118
118
  "react-slugify": "^3.0.3",
119
119
  "swiper": "^10.1.0",
120
120
  "ua-parser-js": "^1.0.36",
121
- "@edifice.io/bootstrap": "2.2.2-develop-b2school.20250408113943",
122
- "@edifice.io/tiptap-extensions": "2.2.2-develop-b2school.20250408113943",
123
- "@edifice.io/utilities": "2.2.2-develop-b2school.20250408113943"
121
+ "@edifice.io/bootstrap": "2.2.2-develop-b2school.20250408143232",
122
+ "@edifice.io/tiptap-extensions": "2.2.2-develop-b2school.20250408143232",
123
+ "@edifice.io/utilities": "2.2.2-develop-b2school.20250408143232"
124
124
  },
125
125
  "devDependencies": {
126
126
  "@babel/plugin-transform-react-pure-annotations": "^7.23.3",
@@ -151,8 +151,8 @@
151
151
  "vite": "^5.4.11",
152
152
  "vite-plugin-dts": "^4.1.0",
153
153
  "vite-tsconfig-paths": "^5.0.1",
154
- "@edifice.io/client": "2.2.2-develop-b2school.20250408113943",
155
- "@edifice.io/config": "2.2.2-develop-b2school.20250408113943"
154
+ "@edifice.io/client": "2.2.2-develop-b2school.20250408143232",
155
+ "@edifice.io/config": "2.2.2-develop-b2school.20250408143232"
156
156
  },
157
157
  "peerDependencies": {
158
158
  "@react-spring/web": "^9.7.5",