Skip to content

Commit

Permalink
wip: Initiated work on entity extraction process
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobiClark committed Jan 16, 2025
1 parent c75a99c commit 89c8f7a
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 110 deletions.
22 changes: 18 additions & 4 deletions src/main/main-process/native-ui/dialogs/open-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,17 +593,31 @@ ipcMain.on("open-files-organize-datasets-dialog", async (event) => {
}
});

ipcMain.on("open-folders-organize-datasets-dialog", async (event) => {
ipcMain.on("open-folders-organize-datasets-dialog", async (event, args) => {
if (!args?.importRelativePath) {
throw new Error("The 'importRelativePath' property is required but was not provided.");
}

console.log("args.importRelativePath:", args.importRelativePath);

let mainWindow = BrowserWindow.getFocusedWindow();

const importRelativePath = args.importRelativePath;

let folders = await dialog.showOpenDialog(mainWindow, {
properties: ["openDirectory", "multiSelections"],
title: "Import a folder",
title: `Import a folder to ${importRelativePath}`,
});

if (folders) {
mainWindow.webContents.send("selected-folders-organize-datasets", folders.filePaths);
if (folders.canceled) {
return; // Exit if the dialog is canceled
}

// Send the selected folders and the relative path back to the renderer
mainWindow.webContents.send("selected-folders-organize-datasets", {
filePaths: folders.filePaths,
importRelativePath,
});
});

// Generate manifest file locally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ const ContextMenu = () => {
<div id="context-menu" style={menuStyles}>
<Menu opened position="top" offset={5} styles={{ dropdown: menuStyles }}>
<Menu.Dropdown>
<Group position="apart" spacing="sm">
<Group position="start">
{contextMenuItemType === "folder" ? (
<IconFolder size={ICON_SETTINGS.folderSize} color={ICON_SETTINGS.folderColor} />
) : (
<IconFolderOpen size={ICON_SETTINGS.folderSize} color={ICON_SETTINGS.folderColor} />
)}
<Text fw={500} size="md">
<Text fw={300} size="md">
{contextMenuItemName}
</Text>
</Group>
Expand All @@ -85,7 +85,7 @@ const ContextMenu = () => {
closeContextMenu();
}}
>
Move
Move {contextMenuItemType}
</Menu.Item>
<Menu.Item
onClick={() => {
Expand All @@ -98,10 +98,17 @@ const ContextMenu = () => {
closeContextMenu();
}}
>
Delete
Delete {contextMenuItemType}
</Menu.Item>
{contextMenuItemType === "folder" && (
<Menu.Item onClick={() => console.log("Import data")}>
<Menu.Item
onClick={(e) => {
e.preventDefault();
window.electron.ipcRenderer.send("open-folders-organize-datasets-dialog", {
importRelativePath: contextMenuItemData.relativePath,
});
}}
>
Import data into {contextMenuItemName}
</Menu.Item>
)}
Expand Down
124 changes: 83 additions & 41 deletions src/renderer/src/components/shared/DatasetTreeViewRenderer/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Space,
Center,
Button,
Loader,
} from "@mantine/core";
import { useHover } from "@mantine/hooks";
import { IconFolder, IconFolderOpen, IconFile, IconSearch } from "@tabler/icons-react";
Expand All @@ -22,7 +23,10 @@ import {
setFolderMoveMode,
moveFolderToNewLocation,
} from "../../../stores/slices/datasetTreeViewSlice";
import { moveFoldersToTargetLocation } from "../../../stores/utils/folderAndFileActions";
import {
moveFoldersToTargetLocation,
moveFilesToTargetLocation,
} from "../../../stores/utils/folderAndFileActions";
import { naturalSort } from "../utils/util-functions";

const ICON_SETTINGS = {
Expand Down Expand Up @@ -111,8 +115,6 @@ const FolderItem = ({
!content ||
(Object.keys(content.folders).length === 0 && Object.keys(content.files).length === 0);

console.log("content", content);

const folderIsPassThrough = content.folderIsPassThrough === true;
if (folderIsPassThrough) {
console.log("Folder is pass through", name);
Expand Down Expand Up @@ -150,10 +152,16 @@ const FolderItem = ({
readOnly
disabled={content.relativePath.includes(contextMenuItemData.relativePath)}
onClick={() => {
moveFoldersToTargetLocation(
[contextMenuItemData.relativePath],
content.relativePath
);
contextMenuItemType === "folder"
? moveFoldersToTargetLocation(
[contextMenuItemData.relativePath],
content.relativePath
)
: moveFilesToTargetLocation(
[contextMenuItemData.relativePath],
content.relativePath
);

setFolderMoveMode(false);
}}
/>
Expand Down Expand Up @@ -211,15 +219,41 @@ const DatasetTreeViewRenderer = ({ folderActions, fileActions, allowStructureEdi
const { renderDatasetStructureJSONObj, datasetStructureSearchFilter, folderMoveModeIsActive } =
useGlobalStore();

const searcDebounceTime = 300; // Set the debounce time for the search filter (in milliseconds)

const [inputSearchFilter, setInputSearchFilter] = useState(datasetStructureSearchFilter); // Local state for input
const searchTimeoutRef = useRef(null);

// Debounce the search filter change
const handleSearchChange = (event) => {
const value = event.target.value;
setInputSearchFilter(value); // Update the input immediately

// Clear the previous timeout if there is one
if (searchTimeoutRef.current) {
clearTimeout(searchTimeoutRef.current);
}

// Set a new timeout to update the global state
searchTimeoutRef.current = setTimeout(() => {
setDatasetStructureSearchFilter(value); // Update the global state after the debounce delay
}, searcDebounceTime);
};

useEffect(() => {
return () => {
// Cleanup the timeout on component unmount
if (searchTimeoutRef.current) {
clearTimeout(searchTimeoutRef.current);
}
};
}, []);

const handleMenuClose = () => {
console.log("Closing context menu");
setMenuOpened(false);
};

const handleSearchChange = (event) => {
setDatasetStructureSearchFilter(event.target.value);
};

const handleAllFilesSelectClick = () => {
Object.keys(renderDatasetStructureJSONObj.files).forEach((fileName) =>
fileActions["on-file-click"](fileName, renderDatasetStructureJSONObj.files[fileName])
Expand All @@ -236,22 +270,22 @@ const DatasetTreeViewRenderer = ({ folderActions, fileActions, allowStructureEdi
};

const handleDeleteAllItemsClick = () => {
console.log(
'Deleting all items containing "' + datasetStructureSearchFilter + '" in their name'
);
console.log('Deleting all items containing "' + inputSearchFilter + '" in their name');
};

const renderObjIsEmpty =
!renderDatasetStructureJSONObj ||
(Object.keys(renderDatasetStructureJSONObj?.folders).length === 0 &&
Object.keys(renderDatasetStructureJSONObj?.files).length === 0);

const searchDebounceIsActive = datasetStructureSearchFilter !== inputSearchFilter;

return (
<Paper padding="md" shadow="sm" radius="md" mih={200} p="sm">
<TextInput
label="Search files and folders:"
placeholder="Search files and folders..."
value={datasetStructureSearchFilter}
value={inputSearchFilter}
onChange={handleSearchChange}
leftSection={<IconSearch stroke={1.5} />}
mb="sm"
Expand Down Expand Up @@ -306,32 +340,40 @@ const DatasetTreeViewRenderer = ({ folderActions, fileActions, allowStructureEdi
</Center>
) : (
<>
{naturalSort(Object.keys(renderDatasetStructureJSONObj?.folders || {})).map(
(folderName) => (
<FolderItem
key={folderName}
name={folderName}
content={renderDatasetStructureJSONObj.folders[folderName]}
onFolderClick={folderActions?.["on-folder-click"]}
onFileClick={fileActions?.["on-file-click"]}
datasetStructureSearchFilter={datasetStructureSearchFilter}
isFolderSelected={folderActions?.["is-folder-selected"]}
isFileSelected={fileActions?.["is-file-selected"]}
allowStructureEditing={allowStructureEditing}
/>
)
)}
{naturalSort(Object.keys(renderDatasetStructureJSONObj?.files || {})).map(
(fileName) => (
<FileItem
key={fileName}
name={fileName}
content={renderDatasetStructureJSONObj.files[fileName]}
onFileClick={fileActions?.["on-file-click"]}
isFileSelected={fileActions?.["is-file-selected"]}
allowStructureEditing={allowStructureEditing}
/>
)
{searchDebounceIsActive ? (
<Center w="100%">
<Loader size="md" m="xs" />
</Center>
) : (
<>
{naturalSort(Object.keys(renderDatasetStructureJSONObj?.folders || {})).map(
(folderName) => (
<FolderItem
key={folderName}
name={folderName}
content={renderDatasetStructureJSONObj.folders[folderName]}
onFolderClick={folderActions?.["on-folder-click"]}
onFileClick={fileActions?.["on-file-click"]}
datasetStructureSearchFilter={datasetStructureSearchFilter}
isFolderSelected={folderActions?.["is-folder-selected"]}
isFileSelected={fileActions?.["is-file-selected"]}
allowStructureEditing={allowStructureEditing}
/>
)
)}
{naturalSort(Object.keys(renderDatasetStructureJSONObj?.files || {})).map(
(fileName) => (
<FileItem
key={fileName}
name={fileName}
content={renderDatasetStructureJSONObj.files[fileName]}
onFileClick={fileActions?.["on-file-click"]}
isFileSelected={fileActions?.["is-file-selected"]}
allowStructureEditing={allowStructureEditing}
/>
)
)}
</>
)}
</>
)}
Expand Down
32 changes: 22 additions & 10 deletions src/renderer/src/scripts/others/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import {
blockedMessage,
hostFirewallMessage,
} from "../check-firewall/checkFirewall";
import { setDatasetEntityObj } from "../../stores/slices/datasetEntitySelectorSlice";

// add jquery to the window object
window.$ = jQuery;
Expand Down Expand Up @@ -4163,41 +4164,52 @@ organizeDSaddFolders.addEventListener("click", function () {
// Event listener for when folder(s) are imported into the file explorer
window.electron.ipcRenderer.on(
"selected-folders-organize-datasets",
async (event, importedFolders) => {
async (event, { filePaths: importedFolders, importRelativePath }) => {
try {
const currentFileExplorerPath = window.organizeDSglobalPath.value.trim();
console.log("Importing folders at path", currentFileExplorerPath);
if (!importRelativePath) {
throw new Error("The 'importRelativePath' property is missing in the response.");
}

// Use the current file explorer path or the provided relative path
const currentFileExplorerPath = `dataset_root/${importRelativePath}`;

console.log("currentFileExplorerPath we are merging into at", currentFileExplorerPath);

const builtDatasetStructureFromImportedFolders =
await window.buildDatasetStructureJsonFromImportedData(
importedFolders,
currentFileExplorerPath
);

console.log(
"builtDatasetStructureFromImportedFolders after importing data",
builtDatasetStructureFromImportedFolders
);

// Add the imported folders to the dataset structure
await mergeLocalAndRemoteDatasetStructure(
builtDatasetStructureFromImportedFolders,
currentFileExplorerPath
);

// Step 4: Update successful, show success message
// Show success message
window.notyf.open({
type: "success",
message: `Data successfully imported`,
duration: 3000,
});
/*await mergeNewDatasetStructureToExistingDatasetStructureAtPath(
builtDatasetStructureFromImportedFolders,
currentFileExplorerPath
);*/
} catch (error) {
console.error("Error importing folders", error);

// Optionally show an error notification
window.notyf.open({
type: "error",
message: `Error importing data: ${error.message}`,
duration: 3000,
});
}
}
);

/* ################################################################################## */
/* ################################################################################## */
/* ################################################################################## */
Expand Down Expand Up @@ -4801,7 +4813,7 @@ const mergeLocalAndRemoteDatasetStructure = async (
);
console.log("currentPathArray", currentPathArray.slice(1));

setTreeViewDatasetStructure(window.datasetStructureJSONObj, currentPathArray.slice(1));
setTreeViewDatasetStructure(window.datasetStructureJSONObj, ["primary"]);
};

const mergeNewDatasetStructureToExistingDatasetStructureAtPath = async (
Expand Down
Loading

0 comments on commit 89c8f7a

Please sign in to comment.