Skip to content

Commit

Permalink
feat: Fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
afonsobspinto committed Aug 12, 2024
2 parents 134ae0a + afb7467 commit 21c4f9c
Show file tree
Hide file tree
Showing 20 changed files with 1,819 additions and 434 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useEffect, useRef, useState } from "react";
import { CheckIcon } from "../../icons";
import type { Neuron } from "../../rest";
import { vars } from "../../theme/variables.ts";
import {EnhancedNeuron} from "../../models/models.ts";

const { gray50, brand600 } = vars;

Expand All @@ -25,8 +26,8 @@ interface CustomEntitiesDropdownProps {
activeNeurons: Set<string>;
onNeuronClick?: (neuron: Option) => void;
onSearchNeurons?: (value: string) => void;
setNeurons?: (neurons: Record<string, Neuron>) => void;
availableNeurons: Record<string, Neuron>;
setNeurons?: (neurons: Record<string, EnhancedNeuron>) => void;
availableNeurons: Record<string, EnhancedNeuron>;
}

const CustomEntitiesDropdown = ({ options, activeNeurons, onNeuronClick, onSearchNeurons, setNeurons, availableNeurons }: CustomEntitiesDropdownProps) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ interface CustomSwitchProps {
disabled?: boolean;
}

const CustomSwitch: React.FC<CustomSwitchProps> = ({ width, height, thumbDimension, checkedPosition, checked, onChange }) => {
const CustomSwitch: React.FC<CustomSwitchProps> = ({ width, height, thumbDimension, checkedPosition, checked, onChange, showTooltip, disabled }) => {

return (
<Tooltip title={checked ? "Hide" : "Show"}>
<Tooltip title={showTooltip ? (checked ? "Hide" : "Show") : ""}>
<Switch
focusVisibleClassName=".Mui-focusVisible"
checked={checked}
onChange={onChange}
disabled={disabled}
sx={(theme) => ({
marginRight: ".5rem",
width: width ?? 23,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,150 +1,153 @@
import AddIcon from "@mui/icons-material/Add";
import { Box, IconButton, Stack, Typography } from "@mui/material";
import {Box, IconButton, Stack, Typography} from "@mui/material";
import Tooltip from "@mui/material/Tooltip";
import { debounce } from "lodash";
import { useCallback, useState } from "react";
import { useGlobalContext } from "../../contexts/GlobalContext.tsx";
import type { Neuron } from "../../rest";
import { NeuronsService } from "../../rest";
import { vars } from "../../theme/variables.ts";
import {debounce} from "lodash";
import {useCallback, useState} from "react";
import {useGlobalContext} from "../../contexts/GlobalContext.tsx";
import type {Neuron} from "../../rest";
import {NeuronsService} from "../../rest";
import {vars} from "../../theme/variables.ts";
import CustomEntitiesDropdown from "./CustomEntitiesDropdown.tsx";
import CustomListItem from "./CustomListItem.tsx";
import {EnhancedNeuron} from "../../models/models.ts";

const { gray900, gray500 } = vars;
const {gray900, gray500} = vars;
const mapNeuronsToListItem = (neuron: string, isActive: boolean) => ({
id: neuron,
label: neuron,
checked: isActive,
id: neuron,
label: neuron,
checked: isActive,
});
const mapNeuronsAvailableNeuronsToOptions = (neuron: Neuron) => ({
id: neuron.name,
label: neuron.name,
content: [],
id: neuron.name,
label: neuron.name,
content: [],
});

const Neurons = ({ children }) => {
const { workspaces, datasets, currentWorkspaceId } = useGlobalContext();
const currentWorkspace = workspaces[currentWorkspaceId];
const activeNeurons = currentWorkspace.activeNeurons;
const allNeurons = currentWorkspace.allWorkspaceNeurons;
const availableNeurons = currentWorkspace.availableNeurons;
const Neurons = ({children}) => {
const {workspaces, datasets, currentWorkspaceId} = useGlobalContext();
const currentWorkspace = workspaces[currentWorkspaceId];
const activeNeurons = currentWorkspace.activeNeurons;
const recentNeurons = Object.values(currentWorkspace.availableNeurons).filter(
(neuron) => neuron.isInteractant
);
const availableNeurons = currentWorkspace.availableNeurons;

const [neurons, setNeurons] = useState(availableNeurons);
const [neurons, setNeurons] = useState(availableNeurons);

const handleSwitchChange = async (neuronId: string, checked: boolean) => {
const neuron = availableNeurons[neuronId];
const handleSwitchChange = async (neuronId: string, checked: boolean) => {
const neuron = availableNeurons[neuronId];

if (!neuron) return;
if (checked) {
await currentWorkspace.activateNeuron(neuron);
} else {
await currentWorkspace.deactivateNeuron(neuronId);
}
};
if (!neuron) return;
if (checked) {
await currentWorkspace.activateNeuron(neuron);
} else {
await currentWorkspace.deactivateNeuron(neuronId);
}
};

const onNeuronClick = (option) => {
const neuron = availableNeurons[option.id];
if (neuron && !activeNeurons.has(option.id)) {
currentWorkspace.activateNeuron(neuron);
} else {
currentWorkspace.deleteNeuron(option.id);
}
};
const handleDeleteNeuron = (neuronId: string) => {
currentWorkspace.deleteNeuron(neuronId);
};
const onNeuronClick = (option) => {
const neuron = availableNeurons[option.id];
if (neuron && !activeNeurons.has(option.id)) {
currentWorkspace.activateNeuron(neuron);
} else {
currentWorkspace.deleteNeuron(option.id);
}
};
const handleDeleteNeuron = (neuronId: string) => {
currentWorkspace.deleteNeuron(neuronId);
};

const fetchNeurons = async (name: string, datasetsIds: { id: string }[]) => {
try {
const Ids = datasetsIds.map((dataset) => dataset.id);
const response = await NeuronsService.searchCells({ name: name, datasetIds: Ids });
const fetchNeurons = async (name: string, datasetsIds: { id: string }[]) => {
try {
const ids = datasetsIds.map((dataset) => dataset.id);
const response = await NeuronsService.searchCells({name: name, datasetIds: ids});

// Convert the object to a Record<string, Neuron>
const neuronsRecord = Object.entries(response).reduce((acc: Record<string, Neuron>, [_, neuron]: [string, Neuron]) => {
acc[neuron.name] = neuron;
return acc;
}, {});
// Convert the object to a Record<string, Neuron>
const neuronsRecord = Object.entries(response).reduce((acc: Record<string, EnhancedNeuron>, [_, neuron]: [string, EnhancedNeuron]) => {
acc[neuron.name] = neuron;
return acc;
}, {});

setNeurons(neuronsRecord);
} catch (error) {
console.error("Failed to fetch datasets", error);
}
};
setNeurons(neuronsRecord);
} catch (error) {
console.error("Failed to fetch datasets", error);
}
};

const debouncedFetchNeurons = useCallback(debounce(fetchNeurons, 300), []);
const debouncedFetchNeurons = useCallback(debounce(fetchNeurons, 300), []);

const onSearchNeurons = (value) => {
const datasetsIds = Object.keys(datasets);
debouncedFetchNeurons(value, datasetsIds);
};
const onSearchNeurons = (value) => {
const datasetsIds = Object.keys(datasets);
debouncedFetchNeurons(value, datasetsIds);
};

const autoCompleteOptions = Object.values(neurons).map((neuron: Neuron) => mapNeuronsAvailableNeuronsToOptions(neuron));
const autoCompleteOptions = Object.values(neurons).map((neuron: Neuron) => mapNeuronsAvailableNeuronsToOptions(neuron));

return (
<Box
sx={{
height: "100%",
display: "flex",
flexDirection: "column",
}}
>
<Stack spacing=".25rem" p=".75rem" mb="1.5rem" pb="0">
<Typography variant="body1" component="p" color={gray900} fontWeight={500}>
Neurons
</Typography>
return (
<Box
sx={{
height: "100%",
display: "flex",
flexDirection: "column",
}}
>
<Stack spacing=".25rem" p=".75rem" mb="1.5rem" pb="0">
<Typography variant="body1" component="p" color={gray900} fontWeight={500}>
Neurons
</Typography>

<Typography variant="body1" component="p" color={gray500}>
Search for the neurons and add it to your workspace. This will affect all viewers.
</Typography>
</Stack>
{children}
<CustomEntitiesDropdown
options={autoCompleteOptions}
activeNeurons={activeNeurons}
onNeuronClick={onNeuronClick}
onSearchNeurons={onSearchNeurons}
setNeurons={setNeurons}
availableNeurons={availableNeurons}
/>
<Box
sx={{
height: "100%",
overflow: "auto",
flex: 1,
}}
>
<Stack spacing=".5rem" p="0 .25rem" mt=".75rem">
<Box display="flex" alignItems="center" justifyContent="space-between" padding=".25rem .5rem">
<Typography color={gray500} variant="subtitle1">
All Neurons
</Typography>
<Tooltip title="Create new group">
<IconButton
<Typography variant="body1" component="p" color={gray500}>
Search for the neurons and add it to your workspace. This will affect all viewers.
</Typography>
</Stack>
{children}
<CustomEntitiesDropdown
options={autoCompleteOptions}
activeNeurons={activeNeurons}
onNeuronClick={onNeuronClick}
onSearchNeurons={onSearchNeurons}
setNeurons={setNeurons}
availableNeurons={availableNeurons}
/>
<Box
sx={{
padding: ".25rem",
borderRadius: ".25rem",
height: "100%",
overflow: "auto",
flex: 1,
}}
>
<AddIcon fontSize="medium" />
</IconButton>
</Tooltip>
</Box>
{Array.from(allNeurons).map((neuronId) => (
<CustomListItem
key={neuronId}
data={mapNeuronsToListItem(neuronId, activeNeurons.has(neuronId))}
showTooltip={false}
showExtraActions={true}
listType="neurons"
onSwitchChange={handleSwitchChange}
onDelete={handleDeleteNeuron}
deleteTooltipTitle="Remove neuron from the workspace"
/>
))}
</Stack>
</Box>
</Box>
);
>
<Stack spacing=".5rem" p="0 .25rem" mt=".75rem">
<Box display="flex" alignItems="center" justifyContent="space-between" padding=".25rem .5rem">
<Typography color={gray500} variant="subtitle1">
All Neurons
</Typography>
<Tooltip title="Create new group">
<IconButton
sx={{
padding: ".25rem",
borderRadius: ".25rem",
}}
>
<AddIcon fontSize="medium"/>
</IconButton>
</Tooltip>
</Box>
{Array.from(recentNeurons).map((neuron) => (
<CustomListItem
key={neuron.name}
data={mapNeuronsToListItem(neuron.name, activeNeurons.has(neuron.name))}
showTooltip={false}
showExtraActions={true}
listType="neurons"
onSwitchChange={handleSwitchChange}
onDelete={handleDeleteNeuron}
deleteTooltipTitle="Remove neuron from the workspace"
/>
))}
</Stack>
</Box>
</Box>
);
};

export default Neurons;
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Outlines } from "@react-three/drei";
import type { ThreeEvent } from "@react-three/fiber";
import type { FC } from "react";
import { Outlines } from "@react-three/drei";
import { useGlobalContext } from "../../../contexts/GlobalContext";
import { useSelector } from "react-redux";
import type { Workspace } from "../../../models/workspace";
import type { RootState } from "../../../layout-manager/layoutManagerFactory";
import { type BufferGeometry, DoubleSide, NormalBlending } from "three";
import { useGlobalContext } from "../../../contexts/GlobalContext";
import type { ThreeEvent } from "@react-three/fiber";
import { getFurthestIntersectedObject } from "../../../helpers/threeDHelpers";
import type { RootState } from "../../../layout-manager/layoutManagerFactory";
import type { Workspace } from "../../../models";
import { OUTLINE_COLOR, OUTLINE_THICKNESS } from "../../../settings/threeDSettings";

interface Props {
Expand All @@ -25,11 +25,11 @@ const STLMesh: FC<Props> = ({ id, color, opacity, renderOrder, isWireframe, stl
const onClick = (event: ThreeEvent<MouseEvent>) => {
const clicked = getFurthestIntersectedObject(event);
if (clicked) {
workspace.highlightNeuron(clicked.userData.id);
workspace.toggleSelectedNeuron(clicked.userData.id);
}
};

const isSelected = id === workspace.highlightedNeuron;
const isSelected = id in workspace.selectedNeurons;
return (
<mesh userData={{ id }} onClick={onClick} frustumCulled={false} renderOrder={renderOrder}>
<primitive attach="geometry" object={stl} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import { useSelector } from "react-redux";
import { useGlobalContext } from "../../../contexts/GlobalContext.tsx";
import { CheckIcon, CloseIcon } from "../../../icons";
import type { RootState } from "../../../layout-manager/layoutManagerFactory.ts";
import type { Dataset } from "../../../models";
import { vars } from "../../../theme/variables.ts";
import CustomAutocomplete from "../../CustomAutocomplete.tsx";
import Gizmo from "./Gizmo.tsx";
import Loader from "./Loader.tsx";
import STLViewer from "./STLViewer.tsx";
import SceneControls from "./SceneControls.tsx";
import {Dataset} from "../../../rest";

const { gray100, gray600 } = vars;
export interface Instance {
Expand Down
Loading

0 comments on commit 21c4f9c

Please sign in to comment.