Skip to content

Commit

Permalink
wip: fixed all entity selection bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobiClark committed Oct 25, 2024
1 parent b6963ed commit f034a3f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ const getFileTypeIcon = (fileName) => {
// FileItem component
const FileItem = ({ name, content, onFileClick, getFileBackgroundColor }) => {
const filesRelativePath = content.relativePath;
const filesEntity = getEntityForRelativePath("subjects", filesRelativePath);

const fileBackgroundColor = getFileBackgroundColor(filesRelativePath);
return (
<div
Expand Down Expand Up @@ -117,6 +115,8 @@ const FolderItem = ({
content={content.folders[folderName]}
onFolderClick={onFolderClick}
onFileClick={onFileClick}
getFolderBackgroundColor={getFolderBackgroundColor}
getFileBackgroundColor={getFileBackgroundColor}
/>
))}
{Object.keys(content.files || {}).map((fileName) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import DatasetTreeViewRenderer from "../DatasetTreeViewRenderer";
import {
setActiveEntity,
toggleRelativeFilePathForManifestEntity,
getEntityForRelativePath,
} from "../../../stores/slices/manifestEntitySelectorSlice";
import { get } from "jquery";

const ManifestEntitySelector = () => {
const datasetStructureJSONObj = useGlobalStore((state) => state.datasetStructureJSONObj);
Expand All @@ -32,6 +34,22 @@ const ManifestEntitySelector = () => {
toggleRelativeFilePathForManifestEntity(entityType, activeEntity, fileContents.relativePath);
};

const getFolderBackgroundColor = (folderRelativePath) => {
const folderIsSelected = getEntityForRelativePath(folderRelativePath);
return folderIsSelected ? "blue" : "white";
};

const getFileBackgroundColor = (fileRelativePath) => {
if (fileRelativePath === "primary/sub-1/code_description.xlsx") {
console.log("Active entity:", activeEntity);
}
const fileIsSelected = getEntityForRelativePath(fileRelativePath);
if (fileIsSelected) {
console.log("File is selected:", fileRelativePath);
}
return fileIsSelected ? "blue" : "white";
};

return (
<FullWidthContainer>
<Grid gutter="md">
Expand Down Expand Up @@ -65,6 +83,8 @@ const ManifestEntitySelector = () => {
datasetStructure={datasetStructureJSONObj}
onFolderClick={handleFolderClick}
onFileClick={handleFileClick}
getFolderBackgroundColor={getFolderBackgroundColor}
getFileBackgroundColor={getFileBackgroundColor}
/>
</Paper>
</Grid.Col>
Expand Down
19 changes: 12 additions & 7 deletions src/renderer/src/stores/slices/manifestEntitySelectorSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ export const toggleRelativeFilePathForManifestEntity = (
entityName,
entityRelativePath
) => {
if (!entityType || !entityName || !entityRelativePath) {
console.log(
"Aborting toggleRelativeFilePathForManifestEntity: entityType, entityName, or entityRelativePath is missing"
);
console.log(entityType, entityName, entityRelativePath);

return;
}
useGlobalStore.setState(
produce((state) => {
// Check if entityType exists, if not, create it
Expand Down Expand Up @@ -115,12 +123,9 @@ export const toggleRelativeFilePathForManifestEntity = (
);
};

export const getEntityForRelativePath = (entityType, relativePath) => {
export const getEntityForRelativePath = (relativePath) => {
const manifestEntityObj = useGlobalStore((state) => state.manifestEntityObj);
if (!manifestEntityObj[entityType]) {
return null;
}
return Object.keys(manifestEntityObj[entityType]).find((entity) =>
manifestEntityObj[entityType][entity]?.includes(relativePath)
);
const entityType = useGlobalStore((state) => state.entityType);
const activeEntity = useGlobalStore((state) => state.activeEntity);
return manifestEntityObj?.[entityType]?.[activeEntity]?.includes(relativePath);
};

0 comments on commit f034a3f

Please sign in to comment.