-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
150 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 0 additions & 56 deletions
56
...frontend-new/src/components/tabs/fileTree/fileList/fileListUtilities/fileTreeUtilities.ts
This file was deleted.
Oops, something went wrong.
105 changes: 105 additions & 0 deletions
105
...rontend-new/src/components/tabs/fileTree/fileList/fileListUtilities/fileTreeUtilities.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { FileListElementType, FileListElementTypeType } from '../../../../../types/data/fileListType.ts'; | ||
import { DataPluginFile } from '../../../../../plugins/interfaces/dataPluginInterfaces/dataPluginFiles.ts'; | ||
import fileListElementsStyles from '../fileListElements/fileListElements.module.scss'; | ||
|
||
export function generateFileTree(files: DataPluginFile[]): FileListElementType[] { | ||
return convertData(files).content; | ||
} | ||
|
||
function convertData(files: DataPluginFile[]) { | ||
const convertedData = { content: [] }; | ||
let id = 0; | ||
for (const file of files) { | ||
if (file) { | ||
const pathParts = file.path.split('/'); | ||
id = genPathObjectString(convertedData.content, pathParts, file, id); | ||
} | ||
} | ||
return convertedData; | ||
} | ||
|
||
function genPathObjectString(convertedData: FileListElementType[], pathParts: string[], file: DataPluginFile, id: number) { | ||
const currElm = pathParts.shift(); | ||
id++; | ||
if (currElm) { | ||
if (pathParts.length === 0) { | ||
convertedData.push({ | ||
name: currElm, | ||
id: id, | ||
type: FileListElementTypeType.File, | ||
checked: true, | ||
element: file, | ||
foldedOut: false, | ||
isRoot: false, | ||
}); | ||
} else { | ||
let elem = convertedData.find((d) => d.name === currElm); | ||
if (elem === undefined) { | ||
elem = { | ||
name: currElm, | ||
id: id, | ||
type: FileListElementTypeType.Folder, | ||
children: [], | ||
checked: true, | ||
foldedOut: false, | ||
isRoot: false, | ||
}; | ||
if (elem.children) { | ||
id = genPathObjectString(elem.children, pathParts, file, id); | ||
convertedData.push(elem); | ||
} | ||
} else { | ||
if (elem.children) { | ||
id = genPathObjectString(elem.children, pathParts, file, id); | ||
} | ||
} | ||
} | ||
} | ||
return id; | ||
} | ||
|
||
export function filterFileTree(fileTree: FileListElementType, search: string): FileListElementType { | ||
if (fileTree.children) { | ||
return { | ||
...fileTree, | ||
searchTerm: search, | ||
children: fileTree.children | ||
?.map((child) => { | ||
if (child.type === FileListElementTypeType.Folder) { | ||
return filterFileTree(child, search); | ||
} else { | ||
return { ...child, searchTerm: search }; | ||
} | ||
}) | ||
.filter((child) => { | ||
if (child.type === FileListElementTypeType.Folder && child.children) { | ||
return child.children.length > 0; | ||
} | ||
return child.element?.path.toLowerCase().includes(search.toLowerCase()); | ||
}), | ||
}; | ||
} else { | ||
return fileTree; | ||
} | ||
} | ||
|
||
export function formatName(searchTerm: string | undefined, name: string): JSX.Element[] { | ||
let formatedName = [<span key={'formatedNamePart0'}>{name}</span>]; | ||
if (searchTerm) { | ||
const searchParts: string[] = searchTerm ? searchTerm.split('/') : []; | ||
for (const searchPart of searchParts) { | ||
if (name.toLowerCase().includes(searchPart.toLowerCase())) { | ||
const nameParts = name.split(new RegExp(searchPart, 'i')).map((part, i) => <span key={`formatedNamePart${i}`}>{part}</span>); | ||
formatedName = [ | ||
nameParts[0], | ||
<span key={'formatedNamePartMatch'} className={fileListElementsStyles.searchMark}> | ||
{searchPart} | ||
</span>, | ||
nameParts[1], | ||
]; | ||
break; | ||
} | ||
} | ||
} | ||
return formatedName; | ||
} |
20 changes: 20 additions & 0 deletions
20
binocular-frontend-new/src/components/tabs/fileTree/fileSearch/fileSearch.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Dispatch, SetStateAction } from 'react'; | ||
|
||
function FileSearch(props: { orientation?: string; setFileSearch: Dispatch<SetStateAction<string>> }) { | ||
return ( | ||
<> | ||
<label className="input input-bordered flex items-center gap-2"> | ||
<input type="text" className="grow" placeholder="Search" onChange={(event) => props.setFileSearch(event.target.value)} /> | ||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" className="h-4 w-4 opacity-70"> | ||
<path | ||
fillRule="evenodd" | ||
d="M9.965 11.026a5 5 0 1 1 1.06-1.06l2.755 2.754a.75.75 0 1 1-1.06 1.06l-2.755-2.754ZM10.5 7a3.5 3.5 0 1 1-7 0 3.5 3.5 0 0 1 7 0Z" | ||
clipRule="evenodd" | ||
/> | ||
</svg> | ||
</label> | ||
</> | ||
); | ||
} | ||
|
||
export default FileSearch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters