Skip to content

Commit

Permalink
feat: embedded workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
hamed-musallam committed Apr 27, 2022
1 parent ecc7b86 commit cc3ad59
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 25 deletions.
18 changes: 6 additions & 12 deletions src/component/NMRium.tsx
@@ -1,7 +1,7 @@
/** @jsxImportSource @emotion/react */

import { css } from '@emotion/react';
import { RootLayout, SplitPane } from 'analysis-ui-components';
import { RootLayout } from 'analysis-ui-components';
import { CorrelationData } from 'nmr-correlation';
import {
useEffect,
Expand All @@ -26,6 +26,7 @@ import Viewer1D from './1d/Viewer1D';
import Viewer2D from './2d/Viewer2D';
import ErrorOverlay from './ErrorOverlay';
import KeysListenerTracker from './EventsTrackers/KeysListenerTracker';
import { SplitPaneWrapper } from './SplitPaneWrapper';
import { AssignmentProvider } from './assignment';
import { ChartDataProvider } from './context/ChartContext';
import { DispatchProvider } from './context/DispatchContext';
Expand Down Expand Up @@ -113,7 +114,8 @@ export type NMRiumWorkspace =
| 'exercise'
| 'process1D'
| 'default'
| 'prediction';
| 'prediction'
| 'embedded';

export interface NMRiumProps {
data?: NMRiumData;
Expand Down Expand Up @@ -333,15 +335,7 @@ function InnerNMRium({
}}
>
<ToolBar />
<SplitPane
initialSeparation="590px"
orientation="horizontal"
sideSeparation="end"
initialClosed={
preferences?.general?.hidePanelOnLoad ||
false
}
>
<SplitPaneWrapper>
<div css={viewerContainerStyle}>
<KeysListenerTracker />
<div
Expand All @@ -360,7 +354,7 @@ function InnerNMRium({
</div>
</div>
<Panels />
</SplitPane>
</SplitPaneWrapper>

<div
ref={elementsWrapperRef}
Expand Down
18 changes: 18 additions & 0 deletions src/component/SplitPaneWrapper.tsx
@@ -0,0 +1,18 @@
import { SplitPane } from 'analysis-ui-components';

import { usePreferences } from './context/PreferencesContext';

export function SplitPaneWrapper({ children }) {
const { current } = usePreferences();
return (
<SplitPane
key={current?.display?.general?.hidePanelOnLoad ? 'true' : 'false'}

This comment has been minimized.

Copy link
@hamed-musallam

hamed-musallam Apr 27, 2022

Author Member

@targos
should we do it in this way to force the SplitPane to re-render or we should listen for the initialClosed property inside the SplitPane component and once its value change update the local state

initialSeparation="590px"
orientation="horizontal"
sideSeparation="end"
initialClosed={current?.display?.general?.hidePanelOnLoad || false}
>
{children}
</SplitPane>
);
}
17 changes: 5 additions & 12 deletions src/component/reducer/preferencesReducer.ts
Expand Up @@ -65,21 +65,14 @@ export const WORKSPACES: Array<{
key: 'prediction',
label: Workspaces.prediction.label,
},
{
key: 'embedded',
label: Workspaces.embedded.label,
},
];

function getPreferencesByWorkspace(workspace: NMRiumWorkspace) {
switch (workspace) {
case 'exercise':
return Workspaces.exercise;
case 'process1D':
return Workspaces.process1D;
case 'prediction':
return Workspaces.prediction;
case 'default':
return Workspaces.default;
default:
return {} as Workspace;
}
return Workspaces?.[workspace] || {};
}

export interface PreferencesState {
Expand Down
33 changes: 33 additions & 0 deletions src/component/workspaces/embedded.ts
@@ -0,0 +1,33 @@
import { Workspace } from './Workspace';
import { basic } from './basic';

export const embedded: Workspace = {
version: 1,
label: 'Embedded workspace',
display: {
general: {
disableMultipletAnalysis: false,
hideSetSumFromMolecule: false,
hideGeneralSettings: false,
experimentalFeatures: { display: true },
hidePanelOnLoad: true,
},

panels: {
spectraPanel: { display: true, open: true },
informationPanel: { display: true, open: false },
peaksPanel: { display: true, open: false },
integralsPanel: { display: true, open: false },
rangesPanel: { display: true, open: false },
structuresPanel: { display: true, open: false },
filtersPanel: { display: true, open: false },
zonesPanel: { display: true, open: false },
summaryPanel: { display: false, open: false },
multipleSpectraAnalysisPanel: { display: false, open: false },
databasePanel: { display: false, open: false },
predictionPanel: { display: false, open: false },
},
},
controllers: basic.controllers,
formatting: basic.formatting,
};
3 changes: 2 additions & 1 deletion src/component/workspaces/index.ts
@@ -1,6 +1,7 @@
import { basic } from './basic';
import { embedded } from './embedded';
import { exercise } from './exercise';
import { prediction } from './prediction';
import { process1D } from './process1D';

export default { exercise, default: basic, process1D, prediction };
export default { exercise, default: basic, process1D, prediction, embedded };

0 comments on commit cc3ad59

Please sign in to comment.