Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[electrophysiology_browser] Revised EEG filters + Store reference fix #9038

Merged
merged 11 commits into from
Feb 29, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,9 @@ class ElectrophysiologySessionView extends Component {
electrodesURL={electrodesURL}
coordSystemURL={coordSystemURL}
physioFileID={this.state.database[i].file.id}
samplingFrequency={
this.state.database[i].file.summary[0].value
}
>
<Panel
id='channel-viewer'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {EventMetadata} from '../series/store/types';

declare global {
interface Window {
EEGLabSeriesProviderStore: Store;
EEGLabSeriesProviderStore: Store[]; // Store reference per recording
}
}

Expand All @@ -37,6 +37,7 @@ type CProps = {
events: EventMetadata,
physioFileID: number,
limit: number,
samplingFrequency: number,
children: React.ReactNode,
};

Expand All @@ -61,17 +62,22 @@ class EEGLabSeriesProvider extends Component<CProps> {

epicMiddleware.run(rootEpic);

window.EEGLabSeriesProviderStore = this.store;

const {
chunksURL,
electrodesURL,
coordSystemURL,
events,
physioFileID,
limit,
samplingFrequency,
} = props;

if (!window.EEGLabSeriesProviderStore) {
window.EEGLabSeriesProviderStore = [];
}

window.EEGLabSeriesProviderStore[chunksURL] = this.store;

this.store.dispatch(setPhysioFileID(physioFileID));

/**
Expand Down Expand Up @@ -114,6 +120,7 @@ class EEGLabSeriesProvider extends Component<CProps> {
timeInterval,
seriesRange,
limit,
samplingFrequency,
})
);
this.store.dispatch(setChannels(emptyChannels(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type CProps = {
mouseY: number,
setHidden: (_: number[]) => void,
physioFileID: number,
chunksURL: string,
};

/**
Expand All @@ -31,6 +32,7 @@ const EEGMontage = (
{
electrodes,
physioFileID,
chunksURL,
}: CProps) => {
if (electrodes.length === 0) return null;

Expand Down Expand Up @@ -303,11 +305,15 @@ const EEGMontage = (
mouseDown={dragStart}
mouseUp={dragEnd}
mouseLeave={dragEnd}
chunksURL={chunksURL}
>
<Montage3D />
</ResponsiveViewer>
:
<ResponsiveViewer>
<ResponsiveViewer
// @ts-ignore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this being ignored? If ts flags something it's usually for a reason.

Copy link
Contributor Author

@jeffersoncasimir jeffersoncasimir Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why. It was not introduced by this PR (or myself) and there seems to be many instances of // @ts-ignore throughout the module

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh? This line is being introduced by you in this PR.

Copy link
Contributor Author

@jeffersoncasimir jeffersoncasimir Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. However it is also present 11 lines above, as well as in the other <ResponsiveViewer> component in SeriesRenderer.tsx.

It seems to be related to export default withParentSize(ResponsiveViewer) at the end of ResponsiveViewer.tsx.

Here is the error I get when I remove the // @ts-ignore line you pointed out (different branch, but refers to same place):
Screenshot 2024-02-27 at 3 17 54 PM

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like a real error that needs to be investigated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I found an appropriate solution. It has been pushed to this PR.

chunksURL={chunksURL}
>
<Montage2D />
</ResponsiveViewer>
}
Expand Down Expand Up @@ -340,13 +346,15 @@ const EEGMontage = (
EEGMontage.defaultProps = {
montage: [],
hidden: [],
chunksURL: '',
};

export default connect(
(state: RootState) => ({
hidden: state.montage.hidden,
electrodes: state.montage.electrodes,
physioFileID: state.dataset.physioFileID,
chunksURL: state.dataset.chunksURL,
}),
(dispatch: (_: any) => void) => ({
setHidden: R.compose(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type CProps = {
mouseLeave?: (_: any) => void,
children: any,
showOverflow: boolean,
chunksURL: string,
};

/**
Expand All @@ -27,6 +28,7 @@ type CProps = {
* @param root0.mouseLeave
* @param root0.children
* @param root0.showOverflow
* @param root0.chunksURL
*/
const ResponsiveViewer : FunctionComponent<CProps> = ({
ref,
Expand All @@ -37,7 +39,8 @@ const ResponsiveViewer : FunctionComponent<CProps> = ({
mouseUp,
mouseLeave,
children,
showOverflow
showOverflow,
chunksURL,
}) => {
/**
*
Expand All @@ -51,7 +54,7 @@ const ResponsiveViewer : FunctionComponent<CProps> = ({

const layers = React.Children.toArray(children).map(provision);

const domain = window.EEGLabSeriesProviderStore.getState().bounds.domain;
const domain = window.EEGLabSeriesProviderStore[chunksURL]?.getState().bounds.domain;
const amplitude = [0, 1];
const eventScale = [
scaleLinear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ type CProps = {
setHighPassFilter: (_: string) => void,
setViewerWidth: (_: number) => void,
setViewerHeight: (_: number) => void,
setFilteredEpochs: (_: number[]) => void,
setDatasetMetadata: (_: { limit: number }) => void,
dragStart: (_: number) => void,
dragContinue: (_: number) => void,
Expand Down Expand Up @@ -134,6 +135,7 @@ type CProps = {
* @param root0.setHighPassFilter
* @param root0.setViewerWidth
* @param root0.setViewerHeight
* @param root0.setFilteredEpochs
* @param root0.setDatasetMetadata
* @param root0.dragStart
* @param root0.dragContinue
Expand All @@ -145,40 +147,41 @@ type CProps = {
* @param root0.setHoveredChannels
*/
const SeriesRenderer: FunctionComponent<CProps> = ({
viewerHeight,
viewerWidth,
interval,
setInterval,
domain,
amplitudeScale,
rightPanel,
timeSelection,
setCursor,
setRightPanel,
chunksURL,
channels,
channelMetadata,
hidden,
epochs,
filteredEpochs,
activeEpoch,
offsetIndex,
setOffsetIndex,
setAmplitudesScale,
resetAmplitudesScale,
setLowPassFilter,
setHighPassFilter,
setViewerWidth,
setViewerHeight,
setDatasetMetadata,
dragStart,
dragContinue,
dragEnd,
limit,
setCurrentAnnotation,
physioFileID,
hoveredChannels,
setHoveredChannels,
viewerHeight,
viewerWidth,
interval,
setInterval,
domain,
amplitudeScale,
rightPanel,
timeSelection,
setCursor,
setRightPanel,
chunksURL,
channels,
channelMetadata,
hidden,
epochs,
filteredEpochs,
activeEpoch,
offsetIndex,
setOffsetIndex,
setAmplitudesScale,
resetAmplitudesScale,
setLowPassFilter,
setHighPassFilter,
setViewerWidth,
setViewerHeight,
setFilteredEpochs,
setDatasetMetadata,
dragStart,
dragContinue,
dragEnd,
limit,
setCurrentAnnotation,
physioFileID,
hoveredChannels,
setHoveredChannels,
}) => {
if (channels.length === 0) return null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const UPDATE_VIEWED_CHUNKS = 'UPDATE_VIEWED_CHUNKS';
export const updateViewedChunks = createAction(UPDATE_VIEWED_CHUNKS);

type FetchedChunks = {
chunksURL: string,
channelIndex: number,
traceIndex: number,
chunks: Chunk[]
Expand All @@ -30,8 +31,9 @@ export const loadChunks = (chunksData: FetchedChunks[]) => {
return (dispatch: (_: any) => void) => {
const channels : Channel[] = [];

const filters: Filter[] = window.EEGLabSeriesProviderStore
.getState().filters;
const filters: Filter[] = window
.EEGLabSeriesProviderStore[chunksData[0].chunksURL]
.getState().filters;
for (let index = 0; index < chunksData.length; index++) {
const {channelIndex, chunks} : {
channelIndex: number,
Expand Down Expand Up @@ -207,6 +209,7 @@ export const createFetchChunksEpic = (fromState: (any) => State) => (

return from(
Promise.all(chunkPromises).then((chunks) => ({
chunksURL: chunksURL,
channelIndex: channel.index,
traceIndex: traceIndex,
chunks,
Expand Down
Loading
Loading