-
Notifications
You must be signed in to change notification settings - Fork 245
feat(data-modeling): show collection name / relationship label in drawer header; show item associated actions in header COMPASS-9653 #7176
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 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,9 +39,13 @@ export const DrawerToolbarLayoutContainer = forwardRef< | |
| ) => { | ||
| const { openDrawer, closeDrawer, getActiveDrawerContent, isDrawerOpen } = | ||
| useDrawerToolbarContext(); | ||
| const { id, title, content } = getActiveDrawerContent() || {}; | ||
| const { id } = getActiveDrawerContent() || {}; | ||
| const lgIds = getLgIds(dataLgId); | ||
| const hasData = toolbarData && toolbarData.length > 0; | ||
| const { title, content } = | ||
gribnoysup marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| toolbarData.find((data) => { | ||
| return data.id === id; | ||
| }) ?? {}; | ||
|
Comment on lines
+42
to
+48
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. This is like a super minimal version of the fix that LG team did in this patch, mapping their changes on top of our vendored package was tricky due to naming (and seems like code was generally shifted around more there), but we can be sure that when this is not vendored anymore, this will continue working
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. Actually, I promised a test for this, let me add that
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. Added in 1538798 |
||
|
|
||
| const handleOnClose = (event: React.MouseEvent<HTMLButtonElement>) => { | ||
| onClose?.(event); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,61 +1,161 @@ | ||
| import React from 'react'; | ||
| import React, { useMemo } from 'react'; | ||
| import { connect } from 'react-redux'; | ||
| import type { DataModelingState } from '../../store/reducer'; | ||
| import { DrawerSection } from '@mongodb-js/compass-components'; | ||
| import { | ||
| css, | ||
| DrawerSection, | ||
| ItemActionControls, | ||
| } from '@mongodb-js/compass-components'; | ||
| import CollectionDrawerContent from './collection-drawer-content'; | ||
| import RelationshipDrawerContent from './relationship-drawer-content'; | ||
| import { | ||
| deleteRelationship, | ||
| selectCurrentModelFromState, | ||
| } from '../../store/diagram'; | ||
| import { getDefaultRelationshipName } from '../../utils'; | ||
|
|
||
| export const DATA_MODELING_DRAWER_ID = 'data-modeling-drawer'; | ||
|
|
||
| const drawerTitleStyles = css({ | ||
| display: 'flex', | ||
| width: '100%', | ||
| }); | ||
|
|
||
| const drawerTitleTextStyles = css({ | ||
| flex: 1, | ||
| whiteSpace: 'nowrap', | ||
| overflow: 'hidden', | ||
| textOverflow: 'ellipsis', | ||
| }); | ||
|
|
||
| const drawerTitleActionGroupStyles = css({}); | ||
|
|
||
| type DiagramEditorSidePanelProps = { | ||
| selectedItems: { type: 'relationship' | 'collection'; id: string } | null; | ||
| selectedItems: { | ||
| id: string; | ||
| type: 'relationship' | 'collection'; | ||
| label: string; | ||
| } | null; | ||
| onDeleteRelationship: (rId: string) => void; | ||
| }; | ||
|
|
||
| function DiagramEditorSidePanel({ | ||
| selectedItems, | ||
| onDeleteRelationship, | ||
| }: DiagramEditorSidePanelProps) { | ||
| if (!selectedItems) { | ||
| return null; | ||
| } | ||
| const { content, label, actions, handleAction } = useMemo(() => { | ||
| if (selectedItems?.type === 'collection') { | ||
| return { | ||
| label: selectedItems.label, | ||
| content: ( | ||
| <CollectionDrawerContent | ||
| key={selectedItems.id} | ||
| namespace={selectedItems.id} | ||
| ></CollectionDrawerContent> | ||
| ), | ||
| actions: [], | ||
| handleAction: () => {}, | ||
| }; | ||
| } | ||
|
|
||
| if (selectedItems?.type === 'relationship') { | ||
| return { | ||
| label: selectedItems.label, | ||
| content: ( | ||
| <RelationshipDrawerContent | ||
| key={selectedItems.id} | ||
| relationshipId={selectedItems.id} | ||
| ></RelationshipDrawerContent> | ||
| ), | ||
| actions: [ | ||
| { action: 'delete', label: 'Delete', icon: 'Trash' as const }, | ||
| ], | ||
| handleAction: (actionName: string) => { | ||
| if (actionName === 'delete') { | ||
| onDeleteRelationship(selectedItems.id); | ||
| } | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| return { content: null }; | ||
gribnoysup marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, [selectedItems, onDeleteRelationship]); | ||
|
|
||
| let content; | ||
|
|
||
| if (selectedItems.type === 'collection') { | ||
| content = ( | ||
| <CollectionDrawerContent | ||
| key={selectedItems.id} | ||
| namespace={selectedItems.id} | ||
| ></CollectionDrawerContent> | ||
| ); | ||
| } else if (selectedItems.type === 'relationship') { | ||
| content = ( | ||
| <RelationshipDrawerContent | ||
| key={selectedItems.id} | ||
| relationshipId={selectedItems.id} | ||
| ></RelationshipDrawerContent> | ||
| ); | ||
| if (!content) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <DrawerSection | ||
| id={DATA_MODELING_DRAWER_ID} | ||
| title="Details" | ||
| label="Details" | ||
| glyph="InfoWithCircle" | ||
| title={ | ||
| <div className={drawerTitleStyles}> | ||
| <span className={drawerTitleTextStyles} title={label}> | ||
| {label} | ||
| </span> | ||
|
|
||
| <ItemActionControls | ||
| actions={actions} | ||
| iconSize="small" | ||
| onAction={handleAction} | ||
| className={drawerTitleActionGroupStyles} | ||
| // Because the close button here is out of our control, we have do | ||
| // adjust the actions rendering in a bit of an unconventional way: | ||
| // if there's more than one action available, collapse it to "...", | ||
| // if it's just one, render the button | ||
| collapseAfter={actions.length > 1 ? 0 : 1} | ||
| ></ItemActionControls> | ||
| </div> | ||
| } | ||
| label={label} | ||
| glyph="Wrench" | ||
| autoOpen | ||
| // TODO: Leafygreen doesn't allow us to tie close event to a particular | ||
| // action. We can add this functionality ourselves, but I'm not sure that | ||
| // adding even more logic on top of the drawer is a good idea. Maybe we're | ||
| // okay with the drawer close button click just staying there until you | ||
| // explicitly click something else? | ||
| // onClose={onClose} | ||
| > | ||
| {content} | ||
| </DrawerSection> | ||
| ); | ||
| } | ||
|
|
||
| export default connect((state: DataModelingState) => { | ||
| return { | ||
| selectedItems: state.diagram?.selectedItems ?? null, | ||
| }; | ||
| })(DiagramEditorSidePanel); | ||
| export default connect( | ||
| (state: DataModelingState) => { | ||
| const selected = state.diagram?.selectedItems; | ||
|
|
||
| if (!selected) { | ||
| return { | ||
| selectedItems: null, | ||
| }; | ||
| } | ||
|
|
||
| if (selected.type === 'collection') { | ||
| return { | ||
| selectedItems: { | ||
| ...selected, | ||
| label: selected.id, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| if (selected.type === 'relationship') { | ||
| const model = selectCurrentModelFromState(state); | ||
| const relationship = model.relationships.find((relationship) => { | ||
| return relationship.id === selected.id; | ||
| }); | ||
|
|
||
| if (!relationship) { | ||
| throw new Error( | ||
| 'Can not find corresponding relationship when rendering DiagramEditorSidePanel' | ||
| ); | ||
| } | ||
|
|
||
| return { | ||
| selectedItems: { | ||
| ...selected, | ||
| label: getDefaultRelationshipName(relationship.relationship), | ||
| }, | ||
| }; | ||
| } | ||
| }, | ||
| { | ||
| onDeleteRelationship: deleteRelationship, | ||
| } | ||
| )(DiagramEditorSidePanel); | ||
Uh oh!
There was an error while loading. Please reload this page.