Skip to content

Commit 7cbec62

Browse files
committed
use drawer
1 parent bb382b0 commit 7cbec62

File tree

4 files changed

+58
-65
lines changed

4 files changed

+58
-65
lines changed

packages/compass-components/src/components/drawer/DrawerLayout/DrawerLayout.types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,7 @@ export type DrawerLayoutPropsWithToolbar = Omit<
4444
} & BaseDrawerLayoutProps;
4545

4646
export type DrawerLayoutProps =
47-
| DrawerLayoutPropsWithToolbar
48-
| DrawerLayoutPropsWithoutToolbar;
47+
| ({
48+
toolbarData: DrawerLayoutPropsWithToolbar['toolbarData'];
49+
} & DrawerLayoutPropsWithToolbar)
50+
| ({ toolbarData?: never } & DrawerLayoutPropsWithoutToolbar);

packages/compass-components/src/components/leafygreen.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export {
141141
DrawerStackProvider,
142142
useDrawerStackContext,
143143
useDrawerToolbarContext,
144+
type DrawerLayoutProps,
144145
} from './drawer';
145146

146147
// 3. Export the leafygreen components.
Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,68 @@
1-
import React from 'react';
1+
import React, { useMemo } from 'react';
22
import { connect } from 'react-redux';
33
import DiagramEditor from './diagram-editor';
44
import SavedDiagramsList from './saved-diagrams-list';
55
import NewDiagramFormModal from './new-diagram-form';
66
import type { DataModelingState } from '../store/reducer';
77
import { DiagramProvider } from '@mongodb-js/diagramming';
88
import DiagramEditorSidePanel from './diagram-editor-side-panel';
9+
import {
10+
DrawerDisplayMode,
11+
DrawerLayout,
12+
type DrawerLayoutProps,
13+
} from '@mongodb-js/compass-components';
14+
import { closeSidePanel } from '../store/side-panel';
915
type DataModelingPluginInitialProps = {
1016
showList: boolean;
17+
isSidePanelOpen: boolean;
18+
onSidePanelClose: () => void;
1119
};
1220

1321
const DataModeling: React.FunctionComponent<DataModelingPluginInitialProps> = ({
1422
showList,
23+
onSidePanelClose,
1524
}) => {
25+
const drawerToolbarData = useMemo<DrawerLayoutProps['toolbarData']>(
26+
() => [
27+
{
28+
id: 'DiagramEditor',
29+
label: 'Data Model',
30+
content: <DiagramEditorSidePanel />,
31+
title: 'Data Model',
32+
glyph: 'Diagram',
33+
onClose: onSidePanelClose,
34+
},
35+
],
36+
[onSidePanelClose]
37+
);
38+
1639
return (
1740
<>
1841
{showList ? (
1942
<SavedDiagramsList></SavedDiagramsList>
2043
) : (
21-
<DiagramProvider fitView>
22-
<DiagramEditor />
23-
<DiagramEditorSidePanel />
24-
</DiagramProvider>
44+
<DrawerLayout
45+
displayMode={DrawerDisplayMode.Overlay}
46+
toolbarData={drawerToolbarData}
47+
>
48+
<DiagramProvider fitView>
49+
<DiagramEditor />
50+
</DiagramProvider>
51+
</DrawerLayout>
2552
)}
2653
<NewDiagramFormModal></NewDiagramFormModal>
2754
</>
2855
);
2956
};
3057

31-
export default connect((state: DataModelingState) => {
32-
return {
33-
showList: state.step === 'NO_DIAGRAM_SELECTED',
34-
};
35-
})(DataModeling);
58+
export default connect(
59+
(state: DataModelingState) => {
60+
return {
61+
showList: state.step === 'NO_DIAGRAM_SELECTED',
62+
isSidePanelOpen: state.sidePanel.isOpen,
63+
};
64+
},
65+
{
66+
onSidePanelClose: closeSidePanel,
67+
}
68+
)(DataModeling);
Lines changed: 10 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
1-
import React, { useEffect } from 'react';
1+
import React from 'react';
22
import { connect } from 'react-redux';
33
import type { DataModelingState } from '../store/reducer';
4-
import { closeSidePanel } from '../store/side-panel';
54
import {
6-
Button,
75
css,
86
cx,
9-
Body,
107
spacing,
118
palette,
129
useDarkMode,
13-
DrawerLayout,
14-
DrawerDisplayMode,
15-
useDrawerToolbarContext,
16-
Drawer,
1710
} from '@mongodb-js/compass-components';
1811

1912
const containerStyles = css({
@@ -25,63 +18,27 @@ const containerStyles = css({
2518
alignItems: 'center',
2619
justifyContent: 'center',
2720
gap: spacing[400],
28-
borderLeft: `1px solid ${palette.gray.light2}`,
2921
});
3022

3123
const darkModeContainerStyles = css({
3224
borderLeftColor: palette.gray.dark2,
3325
});
3426

35-
type DiagramEditorSidePanelProps = {
36-
isOpen: boolean;
37-
onClose: () => void;
38-
};
39-
40-
const DRAWER_TOOLBAR_DATA: DrawerLayoutProps['toolbarData'] = [
41-
{
42-
id: 'Code',
43-
label: 'Code',
44-
content: <DrawerContent />,
45-
title: 'Code Title',
46-
glyph: 'Code',
47-
onClick: () => {
48-
console.log('Code clicked');
49-
},
50-
},
51-
];
52-
53-
function DiagmramEditorSidePanel({
54-
isOpen,
55-
onClose,
56-
}: DiagramEditorSidePanelProps) {
27+
function DiagramEditorSidePanel() {
5728
const isDarkMode = useDarkMode();
58-
// const { openDrawer } = useDrawerToolbarContext();
5929

60-
// useEffect(() => {
61-
// if (isOpen) {
62-
// console.log('OPENING SIDE PANEL');
63-
// openDrawer("DiagramEditorSidePanel");
64-
// }
65-
// }, [isOpen, openDrawer]);
30+
// TODO: this is a placeholder for the side panel content.
6631

6732
return (
6833
<div className={cx(containerStyles, isDarkMode && darkModeContainerStyles)}>
69-
<Drawer title="Diagram Editor" open={isOpen} onClose={onClose}>
70-
<Body>Under development...</Body>
71-
<Button onClick={onClose}>Close</Button>
72-
</Drawer>
34+
This feature is under development.
7335
</div>
7436
);
7537
}
7638

77-
export default connect(
78-
(state: DataModelingState) => {
79-
const { sidePanel } = state;
80-
return {
81-
isOpen: sidePanel.isOpen,
82-
};
83-
},
84-
{
85-
onClose: closeSidePanel,
86-
}
87-
)(DiagmramEditorSidePanel);
39+
export default connect((state: DataModelingState) => {
40+
const { sidePanel } = state;
41+
return {
42+
isOpen: sidePanel.isOpen,
43+
};
44+
})(DiagramEditorSidePanel);

0 commit comments

Comments
 (0)