Skip to content

Commit aaf98ef

Browse files
committed
Add current changes #2
1 parent 34795dc commit aaf98ef

File tree

7 files changed

+67
-146
lines changed

7 files changed

+67
-146
lines changed

src/components/explore-section/EphysViewerContainer/ImageViewComponent.tsx

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import * as React from 'react';
22
import { Select } from 'antd';
33
import { LineChartOutlined } from '@ant-design/icons';
4+
import NWBTrace from './nwb-trace';
5+
import { useMemo } from 'react';
46

57
const { Option } = Select;
68

@@ -26,23 +28,21 @@ interface ImageSetComponentProps {
2628
about?: string | undefined;
2729
}[];
2830
};
29-
onRepetitionClicked: (stimulusType: string, rep: string) => () => void;
31+
onRepetitionClick: (stimulusType: string, rep: string) => () => void;
3032
imagePreview: React.FC<{ imageUrl: string }>;
3133
}
3234

33-
interface ImageViewComponentProps {
34-
stimulusTypeMap: Map<string, number>;
35-
stimulusType: string;
36-
imageCollectionData: ImageCollection;
37-
imagePreview: React.FC<{ imageUrl: string }>;
35+
interface TraceOverviewComponentProps {
36+
trace: NWBTrace;
37+
protocol: string;
3838
onStimulusChange: (value: string) => void;
39-
onRepetitionClicked: (stimulusType: string, rep: string) => () => void;
39+
onRepetitionClick: (stimulusType: string, rep: string) => () => void;
4040
}
4141

4242
function ImageSetComponent({
4343
stimulusType,
4444
repetitions,
45-
onRepetitionClicked,
45+
onRepetitionClick,
4646
imagePreview,
4747
}: ImageSetComponentProps) {
4848
const repCount = Object.keys(repetitions).length;
@@ -79,7 +79,7 @@ function ImageSetComponent({
7979
<span className="indent-10 text-lg font-light text-dark">Repetition {repKey}</span>
8080
<button
8181
className="flex items-center rounded bg-neutral-1 p-3 hover:bg-neutral-2"
82-
onClick={onRepetitionClicked(stimulusType, repKey)}
82+
onClick={onRepetitionClick(stimulusType, repKey)}
8383
type="button"
8484
aria-label="Toggle selection"
8585
>
@@ -106,58 +106,56 @@ function ImageSetComponent({
106106
);
107107
}
108108

109-
function ImageViewComponent({
110-
stimulusTypeMap,
111-
stimulusType,
112-
imageCollectionData,
113-
imagePreview,
109+
function TraceOverviewComponent({
110+
trace,
111+
protocol,
114112
onStimulusChange,
115-
onRepetitionClicked,
116-
}: ImageViewComponentProps) {
117-
const sortedImageCollectionData = React.useMemo(() => {
118-
const entries = Array.from(imageCollectionData.entries() || []);
119-
120-
return entries.sort(([stimulusTypeA], [stimulusTypeB]) => {
121-
const textA = stimulusTypeA.toUpperCase();
122-
const textB = stimulusTypeB.toUpperCase();
123-
const AvB = textA > textB ? 1 : 0;
124-
return textA < textB ? -1 : AvB;
125-
});
126-
}, [imageCollectionData]);
113+
onRepetitionClick,
114+
}: TraceOverviewComponentProps) {
115+
const protocols = useMemo(() => trace.getProtocols(), [trace]);
116+
117+
const repetitionMap = useMemo(
118+
() =>
119+
protocols.reduce(
120+
(map, protocol) => map.set(protocol, trace.getRepetitions(protocol)),
121+
new Map<string, string[]>()
122+
),
123+
[trace]
124+
);
127125

128126
return (
129127
<div className="flex flex-col gap-10">
130-
{stimulusTypeMap.size > 1 && (
128+
{protocols.length > 1 && (
131129
<div className="flex flex-col gap-2">
132-
Select Stimulus ({stimulusTypeMap.size} available)
130+
Select Stimulus ({protocols.length} available)
133131
<Select
134132
className="stimulus-select"
135133
placeholder="Select a stimulus"
136-
value={stimulusType}
134+
value={protocol}
137135
onChange={onStimulusChange}
138136
>
139137
<Option value="All">All</Option>
140-
{Array.from(stimulusTypeMap.entries()).map(([key, amount]) => (
141-
<Option value={key} key={key}>
142-
{key} {amount > 1 && `(${amount})`}
138+
{Array.from(repetitionMap.entries()).map(([protocol, repetitions]) => (
139+
<Option value={protocol} key={protocol}>
140+
{protocol} {repetitions.length > 1 && `(${repetitions.length})`}
143141
</Option>
144142
))}
145143
</Select>
146144
</div>
147145
)}
148146
<div className="flex flex-col gap-5">
149-
{sortedImageCollectionData.map(([itemStimulusType, { repetitions }]) => (
150-
<ImageSetComponent
151-
key={itemStimulusType}
152-
stimulusType={itemStimulusType}
153-
repetitions={repetitions}
154-
onRepetitionClicked={onRepetitionClicked}
155-
imagePreview={imagePreview}
156-
/>
147+
{protocols.map((protocol) => (
148+
<h2>{protocol}</h2>
149+
// <ImageSetComponent
150+
// key={protocol}
151+
// stimulusType={protocol}
152+
// repetitions={repetitionMap.get(protocol) ?? []}
153+
// onRepetitionClick={onRepetitionClick}
154+
// />
157155
))}
158156
</div>
159157
</div>
160158
);
161159
}
162160

163-
export default ImageViewComponent;
161+
export default TraceOverviewComponent;
Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,30 @@
11
import { NexusImage } from './NexusImage';
2-
import ImageViewComponent from './ImageViewComponent';
2+
import TraceOverviewComponent from './ImageViewComponent';
33
import NWBTrace from './nwb-trace';
44

55
interface ImageViewContainerProps {
66
trace: NWBTrace;
77
stimulusType: string;
88
onStimulusChange: (value: string) => void;
9-
onRepetitionClicked: (stimulusType: string, rep: string) => () => void;
9+
onRepetitionClick: (stimulusType: string, rep: string) => () => void;
1010
}
1111

12-
function ImageViewContainer({
12+
function TraceOverview({
1313
trace,
1414
stimulusType,
15-
onRepetitionClicked,
15+
onRepetitionClick,
1616
onStimulusChange,
1717
}: ImageViewContainerProps) {
1818
return (
1919
<>
20-
<ImageViewComponent
21-
{...{
22-
trace,
23-
stimulusType,
24-
onStimulusChange,
25-
onRepetitionClicked,
26-
// eslint-disable-next-line react/no-unstable-nested-components
27-
imagePreview: ({ imageUrl }) => (
28-
// We need to put this as a prop because it contains effects (container, not component)
29-
<NexusImage
30-
{...{
31-
imageUrl,
32-
org: orgLabel,
33-
project: projectLabel,
34-
}}
35-
/>
36-
),
37-
}}
20+
<TraceOverviewComponent
21+
trace={trace}
22+
protocol={stimulusType}
23+
onStimulusChange={onStimulusChange}
24+
onRepetitionClick={onRepetitionClick}
3825
/>
3926
</>
4027
);
4128
}
4229

43-
export default ImageViewContainer;
30+
export default TraceOverview;

src/components/explore-section/EphysViewerContainer/NexusImage.tsx

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/components/explore-section/EphysViewerContainer/TraceSelectorGroup.tsx renamed to src/components/explore-section/EphysViewerContainer/SweepSelector.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ import { classNames } from '@/util/utils';
33

44
type TraceSelectorGroupProps = {
55
selectedSweeps: string[];
6-
sweepsOptions: { label: string; value: string }[];
6+
sweepOptions: { label: string; value: string }[];
77
handlePreviewSweep: (value?: string) => void;
88
setSelectedSweeps: (sweeps: string[]) => void;
99
colorMap: Map<string, string>;
1010
previewItem?: string;
1111
};
1212

13-
function TraceSelectorGroup({
13+
function SweepSelector({
1414
previewItem,
1515
selectedSweeps,
16-
sweepsOptions,
16+
sweepOptions,
1717
handlePreviewSweep,
1818
setSelectedSweeps,
1919
colorMap,
2020
}: TraceSelectorGroupProps) {
21-
const sweeps = sweepsOptions.map(({ label, value }) => {
21+
const sweeps = sweepOptions.map(({ label, value }) => {
2222
const isSelected = selectedSweeps.includes(value);
2323
const isEmptySelection = !selectedSweeps.length;
2424
const isHighlight = isSelected || (isEmptySelection && !previewItem);
@@ -69,11 +69,11 @@ function TraceSelectorGroup({
6969
return (
7070
<div className="flex flex-col gap-3">
7171
<span className="font-bold text-dark">
72-
Sweep <small className="text-sm font-light">({sweepsOptions.length} available)</small>
72+
Sweep <small className="text-sm font-light">({sweepOptions.length} available)</small>
7373
</span>
7474
<div className="flex flex-wrap items-center">{sweeps}</div>
7575
</div>
7676
);
7777
}
7878

79-
export default TraceSelectorGroup;
79+
export default SweepSelector;

src/components/explore-section/EphysViewerContainer/TraceDetailsView.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import DistinctColors from 'distinct-colors';
55
import StimulusPlot from './StimulusPlot';
66
import ResponsePlot from './ResponsePlot';
77
import OptionSelect from '@/components/explore-section/EphysViewerContainer/OptionSelect';
8-
import TraceSelectorGroup from '@/components/explore-section/EphysViewerContainer/TraceSelectorGroup';
8+
import SweepSelector from '@/components/explore-section/EphysViewerContainer/SweepSelector';
99
import NWBTrace from './nwb-trace';
1010

1111
interface EphysPlotProps {
@@ -68,7 +68,7 @@ function TraceDetailsView({ trace, defaultProtocol, defaultRepetition }: EphysPl
6868
</Select.Option>
6969
));
7070

71-
const sweepsOptions = sweeps ? sweeps.map((sweep) => ({ label: sweep, value: sweep })) : [];
71+
const sweepOptions = sweeps ? sweeps.map((sweep) => ({ label: sweep, value: sweep })) : [];
7272

7373
const handleProtocolChange = (protocol: string) => {
7474
setSelectedDataSet(protocol);
@@ -80,7 +80,7 @@ function TraceDetailsView({ trace, defaultProtocol, defaultRepetition }: EphysPl
8080
const handlePreviewSweep = (value?: string) => {
8181
if (!value) {
8282
setPreviewItem(undefined);
83-
} else if (sweepsOptions.length > 1 && !selectedSweeps.includes(value)) {
83+
} else if (sweepOptions.length > 1 && !selectedSweeps.includes(value)) {
8484
setPreviewItem(value);
8585
}
8686
};
@@ -115,13 +115,13 @@ function TraceDetailsView({ trace, defaultProtocol, defaultRepetition }: EphysPl
115115
handleChange={handleRepetitionChange}
116116
hideWhenSingle
117117
/>
118-
<TraceSelectorGroup
118+
<SweepSelector
119119
handlePreviewSweep={handlePreviewSweep}
120120
colorMap={colorMap}
121121
selectedSweeps={selectedSweeps}
122122
previewItem={previewItem}
123123
setSelectedSweeps={setSelectedSweeps}
124-
sweepsOptions={sweepsOptions}
124+
sweepOptions={sweepOptions}
125125
/>
126126
{sweeps.length > 1 && (
127127
<button

src/components/explore-section/EphysViewerContainer/index.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import { FileImageOutlined, LineChartOutlined } from '@ant-design/icons';
44
import { useAtomValue } from 'jotai';
55

66
import { ExperimentalTrace } from '@/types/explore-section/delta-experiment';
7-
import ImageViewContainer from '@/components/explore-section/EphysViewerContainer/ImageViewContainer';
7+
import TraceOverview from '@/components/explore-section/EphysViewerContainer/ImageViewContainer';
88
import TraceDetailsView from './TraceDetailsView';
9-
import './styles/ephys-plugin-styles.scss';
109
import sessionAtom from '@/state/session';
1110
import useTrace from './hooks/use-nwb-trace';
1211

12+
import './styles/ephys-plugin-styles.scss';
13+
1314
enum VIEW {
1415
OVERVIEW = 'overview',
1516
DETAILED = 'detailed',
@@ -57,14 +58,14 @@ function EphysViewerContainer({ resource }: { resource: ExperimentalTrace }) {
5758
</Radio.Button>
5859
</Radio.Group>
5960

60-
{/* {view === VIEW.OVERVIEW && (
61-
<ImageViewContainer
61+
{view === VIEW.OVERVIEW && (
62+
<TraceOverview
6263
trace={trace}
6364
stimulusType={protocol}
64-
onRepetitionClicked={showRepetitionDetails}
65+
onRepetitionClick={showRepetitionDetails}
6566
onStimulusChange={setProtocol}
6667
/>
67-
)} */}
68+
)}
6869

6970
{view === VIEW.DETAILED && (
7071
<TraceDetailsView

src/components/explore-section/EphysViewerContainer/styles/nexus-image.scss

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)