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

refactor: viewer node tree #3326

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 8 additions & 22 deletions src/component/main/InnerNMRiumContents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,17 @@ import { ExportManagerController } from '../elements/export/ExportManager.js';
import { PrintContent } from '../elements/print/PrintContent.js';
import { Header } from '../header/Header.js';
import DropZone from '../loader/DropZone.js';
import { PanelOpenProviderProvider, Panels } from '../panels/Panels.js';
import { PanelOpenProviderProvider } from '../panels/Panels.js';
import { PanelsBar } from '../panels/PanelsBar.js';
import ToolBar from '../toolbar/ToolBar.js';

import { useNMRiumRefAPI } from './NMRiumRefAPI.js';
import { NMRiumViewer } from './NMRiumViewer.js';
import { SplitPaneWrapper } from './SplitPaneWrapper.js';
import { NMRiumViewerWrapper } from './NMRiumViewerWrapper.js';
import { StateError } from './StateError.js';

import type { NMRiumProps, NMRiumRefAPI } from './index.js';

const viewerContainerStyle = css`
border: 0.55px #e6e6e6 solid;
display: flex;
flex: 1;
flex-direction: column;
height: 100%;
margin-left: -1px;
`;

const containerStyles = css`
background-color: white;
width: 100%;
Expand Down Expand Up @@ -151,19 +142,14 @@ export function InnerNMRiumContents(props: InnerNMRiumContentsProps) {
height: '100%',
}}
>
<KeysListenerTracker mainDivRef={mainDivRef} />

<PanelOpenProviderProvider>
<ToolBar />
<SplitPaneWrapper>
<div css={viewerContainerStyle}>
<KeysListenerTracker mainDivRef={mainDivRef} />

<NMRiumViewer
emptyText={emptyText}
viewerRef={viewerRef}
/>
</div>
<Panels />
</SplitPaneWrapper>
<NMRiumViewerWrapper
viewerRef={viewerRef}
emptyText={emptyText}
/>
<PanelsBar />
</PanelOpenProviderProvider>
<div
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import type { RefObject } from 'react';
import type { SplitPaneSize } from 'react-science/ui';
import { SplitPane } from 'react-science/ui';

import { usePreferences } from '../context/PreferencesContext.js';
import { Panels } from '../panels/Panels.js';
import { useAccordionItems } from '../panels/hooks/useAccordionItems.js';
import { useGetPanelOptions } from '../panels/hooks/useGetPanelOptions.js';

export function SplitPaneWrapper({ children }) {
import type { NMRiumProps } from './NMRium.js';
import { NMRiumViewer } from './NMRiumViewer.js';

interface NMRiumViewerWrapperProps {
viewerRef: RefObject<HTMLDivElement>;
emptyText: NMRiumProps['emptyText'];
}

export function NMRiumViewerWrapper(props: NMRiumViewerWrapperProps) {
const { emptyText, viewerRef } = props;
const { current, dispatch } = usePreferences();
const getPanelPreferences = useGetPanelOptions();

Expand All @@ -31,7 +42,7 @@ export function SplitPaneWrapper({ children }) {
const hasDisplayedPanels = displayedPanels.length > 0;

if (items?.length === 0 || !hasDisplayedPanels) {
return <div style={{ width: '100%', height: '100%' }}>{children}</div>;
return <NMRiumViewer emptyText={emptyText} viewerRef={viewerRef} />;
}

const closed: number | boolean = general?.hidePanelOnLoad
Expand All @@ -46,7 +57,8 @@ export function SplitPaneWrapper({ children }) {
closed={closed}
onResize={resizeHandler}
>
{children}
<NMRiumViewer emptyText={emptyText} viewerRef={viewerRef} />
<Panels />
</SplitPane>
);
}
2 changes: 1 addition & 1 deletion test-e2e/panels/integral.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async function resizeIntegral(nmrium: NmriumPage) {
'_react=IntegralsSeries >> _react=Integration >> nth=0 >> rect >> nth=0',
);
const { width } = (await container.boundingBox()) as BoundingBox;
expect(width).toBe(41);
expect(width).toBe(40);
}

async function deleteIntegral(nmrium: NmriumPage) {
Expand Down
Loading