Skip to content

Commit

Permalink
wip: Added entity data auto selection
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobiClark committed Jan 23, 2025
1 parent 2da10b2 commit bc0474d
Show file tree
Hide file tree
Showing 13 changed files with 361 additions and 893 deletions.
Original file line number Diff line number Diff line change
@@ -1,48 +1,49 @@
import GuidedModeSection from "../../containers/GuidedModeSection";
import useGlobalStore from "../../../stores/globalStore";
import { Text, Image } from "@mantine/core";

// Content lookup object that maps keys to arrays of content sections.
// Each section specifies its type (e.g., text, image) and associated data.
const contentLookup = {
"sub-": [
{
type: "text",
data: "Each subject must be uniquely identified with a subject ID. SODA provides three options for specifying subject IDs based on the number of subjects and your preference:",
},
{
type: "text",
data: "<b>1. Manual Entry (Recommended for fewer than 10 subjects):</b> Manually enter subject IDs directly into the interface below. This is ideal for small datasets or if you prefer not to use automated methods.",
},
{
type: "text",
data: "<b>2. Spreadsheet Entry (Recommended for more than 10 subjects):</b> Upload a spreadsheet file containing subject IDs. This method is suited for larger datasets or when you already have the subject IDs organized in a file.",
},
{
type: "text",
data: "<b>3. Extract from Folder Names (Recommended if you imported folders with names that subject IDs can be extracted from):</b> Automatically generate subject IDs by extracting them from folder names. Use this method if your data is already organized into folders named after the subjects.",
},
],
"sam-": [
{
type: "text",
data: "If any measurements were taken from samples collected from subjects (e.g. tissue samples), you can specify the samples in the interface below.",
},
{ type: "image", data: "https://via.placeholder.com/300" },
{ type: "text", data: "And yet another section for key2." },
],
"sites-": [
{ type: "text", data: "This is the first section for key2." },
{ type: "image", data: "https://via.placeholder.com/300" },
{ type: "text", data: "And yet another section for key2." },
],
};

const InstructionalTextSection = ({ textSectionKey }) => {
// Retrieve content sections for the given key. If the key is not found,
// provide a fallback with a "Content not found" message.
const contentSections = contentLookup[textSectionKey] || [
{ type: "text", data: "Content not found." },
];
const contentLookup = {
"sub-": [
{
type: "text",
data: "Each subject must be uniquely identified with a subject ID. SODA provides three options for specifying subject IDs based on the number of subjects and your preference:",
},
{
type: "text",
data: "<b>1. Manual Entry (Recommended for fewer than 10 subjects):</b> Manually enter subject IDs directly into the interface below. This is ideal for small datasets or if you prefer not to use automated methods.",
},
{
type: "text",
data: "<b>2. Spreadsheet Entry (Recommended for more than 10 subjects):</b> Upload a spreadsheet file containing subject IDs. This method is suited for larger datasets or when you already have the subject IDs organized in a file.",
},
{
type: "text",
data: "<b>3. Extract from Folder Names (Recommended if you imported folders with names that subject IDs can be extracted from):</b> Automatically generate subject IDs by extracting them from folder names. Use this method if your data is already organized into folders named after the subjects.",
},
],
"sam-": [
{
type: "text",
data: "If any measurements were taken from samples collected from subjects (e.g. tissue samples), you can specify the samples in the interface below.",
},
{ type: "image", data: "https://via.placeholder.com/300" },
{ type: "text", data: "And yet another section for key2." },
],
"sites-": [
{ type: "text", data: "This is the first section for key2." },
{ type: "image", data: "https://via.placeholder.com/300" },
{ type: "text", data: "And yet another section for key2." },
],
};
const contentSections = contentLookup[textSectionKey];

if (!contentSections) {
return null;
}

return (
<GuidedModeSection>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ import {
import useGlobalStore from "../../../stores/globalStore";
import DatasetTreeViewRenderer from "../../shared/DatasetTreeViewRenderer";
import InstructionalTextSection from "../../common/InstructionalTextSection";
import { setDatasetStructureSearchFilter } from "../../../stores/slices/datasetTreeViewSlice";
import { externallySetSearchFilterValue } from "../../../stores/slices/datasetTreeViewSlice";
import {
setActiveEntity,
modifyDatasetEntityForRelativeFilePath,
getEntityForRelativePath,
} from "../../../stores/slices/datasetEntitySelectorSlice";
import { naturalSort } from "../../shared/utils/util-functions";

const ENTITY_PREFIXES = ["sub-", "sam-", "perf-"];

Expand Down Expand Up @@ -76,7 +77,7 @@ const handleFolderClick = (
const renderEntityList = (entityType, activeEntity, datasetEntityObj) => {
if (!datasetEntityObj?.[entityType]) return null;

return Object.keys(datasetEntityObj[entityType]).map((entity) => {
return naturalSort(Object.keys(datasetEntityObj[entityType])).map((entity) => {
const entityItemsCount = datasetEntityObj[entityType][entity].length || 0;
console.log("entity", entity);
console.log("activeEntity", activeEntity);
Expand Down Expand Up @@ -118,7 +119,7 @@ const renderEntityList = (entityType, activeEntity, datasetEntityObj) => {
handleEntityClick(entity);
}
const entityName = entity.substring(entity.indexOf("-") + 1);
setDatasetStructureSearchFilter(entityName);
externallySetSearchFilterValue(entityName);
}}
/>
</Tooltip>
Expand Down Expand Up @@ -194,7 +195,7 @@ const EntityDataSelectorPage = ({
fileActions={{
"on-file-click": (fileName, fileContents) =>
handleFileClick(entityType, activeEntity, datasetEntityObj, fileContents),
"is-file-selected": (fileContents) => {
"is-file-selected": (fileName, fileContents) => {
const entity = getEntityForRelativePath(
datasetEntityObj,
entityType,
Expand Down
27 changes: 14 additions & 13 deletions src/renderer/src/components/pages/EntitySelector/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ const EntitySelectorPage = ({
}
};

const handleRemoveEntity = (entityName) => {
removeEntityFromEntityList(entityType, entityName);
};

const handleImportEntitiesFromLocalFoldersClick = () => {
window.electron.ipcRenderer.send("open-entity-id-import-selector");
};
Expand All @@ -69,21 +65,25 @@ const EntitySelectorPage = ({
<ScrollArea h={700} type="auto">
<Box>
{entityList.length > 0 ? (
<Stack w={width}>
{entityList.map((entityName) => (
<Stack w={width} gap={0}>
{naturalSort(entityList).map((entityName) => (
<Group
key={entityName}
justify="space-between"
px="sm"
py="xs"
py={4}
style={{ borderBottom: "1px solid #eaeaea" }}
>
<Text>{entityName}</Text>
<Group gap="xs">
<ActionIcon color="blue">
<IconEdit size={16} />
</ActionIcon>
<ActionIcon color="red" onClick={() => handleRemoveEntity(entityName)}>
<ActionIcon
color="red"
onClick={() => {
removeEntityFromEntityList(entityType, entityName);
}}
>
<IconTrash size={16} />
</ActionIcon>
</Group>
Expand Down Expand Up @@ -132,7 +132,7 @@ const EntitySelectorPage = ({
}}
error={
!isNewEntityNameValid &&
`${entityTypeStringSingular} does not adhere to identifier conventions.`
`${entityTypeStringPlural} IDs can only contain letters, numbers, and hypens.`
}
/>
<Button onClick={handleAddEntity} leftIcon={<IconPlus />}>
Expand Down Expand Up @@ -166,6 +166,7 @@ const EntitySelectorPage = ({
folderActions={{
"on-folder-click": async (folderName, folderContents, folderIsSelected) => {
const childFolderNames = Object.keys(folderContents.folders);
console.log("childFolderNames", childFolderNames);
const potentialEntities = naturalSort(childFolderNames).map(
(childFolderName) => {
const formattedName =
Expand All @@ -178,9 +179,9 @@ const EntitySelectorPage = ({

const continueWithEntityIdImport = await swalFileListDoubleAction(
potentialEntities,
`Confirm ${entityTypeStringPlural} Import`,
`The following ${entityTypeStringPlural} have been detected in the selected folder. If you proceed, they will be added to your list of ${entityTypeStringPlural}:`,
`Import Selected ${entityTypeStringPlural}`,
`${potentialEntities.length} ${entityTypeStringSingular} IDs detected`,
`The following ${entityTypeStringPlural} have been detected in the selected folder. If you select 'Import ${entityTypeStringPlural}', these ${entityTypeStringPlural} will be added to the list of ${entityTypeStringPlural} for this dataset. Do you want to proceed?`,
`Import ${entityTypeStringSingular} IDs`,
`Cancel Import`,
""
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import SingleColumnTable from "../tables/singleColumn";
import PennsieveAgentCheckDisplay from "../backgroundServices/PennsieveAgentCheckDisplay";
import EntitySelectorPage from "../pages/EntitySelector";
import EntityDataSelectorPage from "../pages/EntityDataSelector";
import DatasetEntityManager from "../shared/manifest/DatasetEntityManager";
import DataImporter from "../shared/DataImporter";
import { Divider } from "@mantine/core";

Expand Down
Loading

0 comments on commit bc0474d

Please sign in to comment.