-
Notifications
You must be signed in to change notification settings - Fork 245
feat(data-modeling): add collection COMPASS-9655 #7195
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
Changes from 19 commits
76701c4
9649383
5dc5e85
736c9eb
198c966
9fca137
b68ba41
0922830
38c5644
ecc0457
9cba1a0
39fe3c4
9cce817
926f035
c50b81f
650b898
df0db50
49659cd
346d0d0
3df807f
c1fb51a
9eb4f44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ import { | |
| type DiagramState, | ||
| selectCurrentModelFromState, | ||
| createNewRelationship, | ||
| addCollection, | ||
| } from '../store/diagram'; | ||
| import { | ||
| Banner, | ||
|
|
@@ -25,6 +26,7 @@ import { | |
| Button, | ||
| useDarkMode, | ||
| useDrawerActions, | ||
| useDrawerState, | ||
| rafraf, | ||
| } from '@mongodb-js/compass-components'; | ||
| import { cancelAnalysis, retryAnalysis } from '../store/analysis-process'; | ||
|
|
@@ -107,6 +109,7 @@ const DiagramContent: React.FunctionComponent<{ | |
| model: StaticModel | null; | ||
| isInRelationshipDrawingMode: boolean; | ||
| editErrors?: string[]; | ||
| newCollection?: string; | ||
| onMoveCollection: (ns: string, newPosition: [number, number]) => void; | ||
| onCollectionSelect: (namespace: string) => void; | ||
| onRelationshipSelect: (rId: string) => void; | ||
|
|
@@ -118,6 +121,7 @@ const DiagramContent: React.FunctionComponent<{ | |
| diagramLabel, | ||
| model, | ||
| isInRelationshipDrawingMode, | ||
| newCollection, | ||
| onMoveCollection, | ||
| onCollectionSelect, | ||
| onRelationshipSelect, | ||
|
|
@@ -129,6 +133,7 @@ const DiagramContent: React.FunctionComponent<{ | |
| const isDarkMode = useDarkMode(); | ||
| const diagram = useRef(useDiagram()); | ||
| const { openDrawer } = useDrawerActions(); | ||
| const { isDrawerOpen } = useDrawerState(); | ||
|
|
||
| const setDiagramContainerRef = useCallback((ref: HTMLDivElement | null) => { | ||
| if (ref) { | ||
|
|
@@ -183,6 +188,35 @@ const DiagramContent: React.FunctionComponent<{ | |
| }); | ||
| }, []); | ||
|
|
||
| // Center on a new collection when it is added | ||
| const previouslyOpenedDrawer = useRef<boolean>(false); | ||
| useEffect(() => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know I will never convince y'all to avoid useEffect usage as much as possible 😆 but I just have to mention that while yes, this is an effect of sorts, I think a better way to think about this as (at least as it is right now) a side-effect directly of calling the createNewCollection action and so can be just a function that is called right after the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, do we know that the new collection will already be there? |
||
| const wasDrawerPreviouslyOpened = previouslyOpenedDrawer.current; | ||
| previouslyOpenedDrawer.current = !!isDrawerOpen; | ||
|
|
||
| if (!newCollection) return; | ||
| const node = nodes.find((n) => n.id === newCollection); | ||
| if (!node) return; | ||
|
|
||
| // For calculating the center, we're taking into account the drawer, | ||
| // so that the new node is centered in the visible part. | ||
| const drawerOffset = wasDrawerPreviouslyOpened ? 0 : 240; | ||
| const zoom = diagram.current.getViewport().zoom; | ||
| const drawerOffsetInDiagramCoords = drawerOffset / zoom; | ||
| const newNodeWidth = 244; | ||
| const newNodeHeight = 64; | ||
| return rafraf(() => { | ||
| void diagram.current.setCenter( | ||
| node.position.x + newNodeWidth / 2 + drawerOffsetInDiagramCoords, | ||
| node.position.y + newNodeHeight / 2, | ||
| { | ||
| duration: 500, | ||
| zoom, | ||
| } | ||
| ); | ||
| }); | ||
| }, [newCollection, nodes, isDrawerOpen]); | ||
|
|
||
| const handleNodesConnect = useCallback( | ||
| (source: string, target: string) => { | ||
| onCreateNewRelationship(source, target); | ||
|
|
@@ -241,6 +275,7 @@ const ConnectedDiagramContent = connect( | |
| model: diagram ? selectCurrentModelFromState(state) : null, | ||
| diagramLabel: diagram?.name || 'Schema Preview', | ||
| selectedItems: state.diagram?.selectedItems ?? null, | ||
| newCollection: diagram?.draftCollection, | ||
| }; | ||
| }, | ||
| { | ||
|
|
@@ -257,7 +292,15 @@ const DiagramEditor: React.FunctionComponent<{ | |
| diagramId?: string; | ||
| onRetryClick: () => void; | ||
| onCancelClick: () => void; | ||
| }> = ({ step, diagramId, onRetryClick, onCancelClick }) => { | ||
| onAddCollectionClick: () => void; | ||
| }> = ({ | ||
| step, | ||
| diagramId, | ||
| onRetryClick, | ||
| onCancelClick, | ||
| onAddCollectionClick, | ||
| }) => { | ||
| const { openDrawer } = useDrawerActions(); | ||
| let content; | ||
|
|
||
| const [isInRelationshipDrawingMode, setIsInRelationshipDrawingMode] = | ||
|
|
@@ -271,6 +314,11 @@ const DiagramEditor: React.FunctionComponent<{ | |
| setIsInRelationshipDrawingMode(false); | ||
| }, []); | ||
|
|
||
| const handleAddCollectionClick = useCallback(() => { | ||
| onAddCollectionClick(); | ||
| openDrawer(DATA_MODELING_DRAWER_ID); | ||
| }, [openDrawer, onAddCollectionClick]); | ||
|
|
||
| if (step === 'NO_DIAGRAM_SELECTED') { | ||
| return null; | ||
| } | ||
|
|
@@ -320,6 +368,7 @@ const DiagramEditor: React.FunctionComponent<{ | |
| <DiagramEditorToolbar | ||
| onRelationshipDrawingToggle={handleRelationshipDrawingToggle} | ||
| isInRelationshipDrawingMode={isInRelationshipDrawingMode} | ||
| onAddCollectionClick={handleAddCollectionClick} | ||
| /> | ||
| } | ||
| > | ||
|
|
@@ -341,5 +390,6 @@ export default connect( | |
| { | ||
| onRetryClick: retryAnalysis, | ||
| onCancelClick: cancelAnalysis, | ||
| onAddCollectionClick: addCollection, | ||
| } | ||
| )(DiagramEditor); | ||
Uh oh!
There was an error while loading. Please reload this page.