- ON_SEARCH_CHANGE: (data) =>
- mapTreeValues((v: CollectionPanelDirectory | CollectionPanelFile) => {
+ ON_SEARCH_CHANGE: (searchValue) => {
+ // node.children = children.filter((id: string) => id.replace(parentId, '').toLowerCase().indexOf(searchValue.toLowerCase()) > -1);
+ const ids: string[] = [];
+ const filteredFiles = Object.keys(fetchedFiles)
+ .filter((key: string) => {
+ const node = fetchedFiles[key];
+
+ if (node.value === undefined) {
+ return false;
+ }
+
+ const { id, value: { type, name } } = node;
+
+ if (type === CollectionFileType.DIRECTORY) {
+ ids.push(id);
+ return true;
+ }
+
+ const includeFile = name.toLowerCase().indexOf(searchValue.toLowerCase()) > -1;
+
+ if (includeFile) {
+ ids.push(id);
+ }
+
+ return includeFile;
+ })
+ .reduce((prev, next) => {
+ const node = JSON.parse(JSON.stringify(fetchedFiles[next]));
+ node.children = node.children.filter((key: string) => ids.indexOf(key) > -1);
+ prev[next] = node;
+ return prev;
+ }, {});
+
+ return mapTreeValues((v: CollectionPanelDirectory | CollectionPanelFile) => {