Skip to content
Closed
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
28 changes: 26 additions & 2 deletions packages/compass-assistant/src/compass-assistant-drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import {
Badge,
css,
DrawerSection,
GuideCue,
Icon,
IconButton,
showConfirmation,
spacing,
} from '@mongodb-js/compass-components';
import { type IconButtonPropsWithoutChildren } from '@mongodb-js/compass-components/src/components/toolbar';
import { AssistantChat } from './components/assistant-chat';
import {
ASSISTANT_DRAWER_ID,
Expand Down Expand Up @@ -35,9 +37,10 @@ const assistantTitleTextStyles = css({
* it's within an AssistantProvider.
*/
export const CompassAssistantDrawer: React.FunctionComponent<{
appName: string;
autoOpen?: boolean;
hasNonGenuineConnections?: boolean;
}> = ({ autoOpen, hasNonGenuineConnections = false }) => {
}> = ({ appName, autoOpen, hasNonGenuineConnections = false }) => {
const chat = useContext(AssistantContext);
const { clearChat } = useContext(AssistantActionsContext);

Expand Down Expand Up @@ -90,7 +93,28 @@ export const CompassAssistantDrawer: React.FunctionComponent<{
</div>
}
label="MongoDB Assistant"
glyph="Sparkle"
glyph={({
buttonProps,
}: {
buttonProps: IconButtonPropsWithoutChildren;
}) => (
<GuideCue<HTMLButtonElement>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case it isn't obvious this is our GuideCue from compass-components which wrap's leafygreen's guidecue and exports a different interface, not the raw leafygreen guidecue.

cueId="assistant-drawer"
title="Introducing MongoDB Assistant"
description={`AI-powered assistant to intelligently guide you through your database tasks. Get expert MongoDB help and streamline your workflow directly within ${appName}`}
buttonText="Got it"
onPrimaryButtonClick={() => {}}
tooltipAlign="left"
tooltipJustify="start"
trigger={({ ref: guideCueRef }) => {
return (
<IconButton {...buttonProps} ref={guideCueRef}>
<Icon glyph="Sparkle" />
</IconButton>
);
}}
/>
)}
autoOpen={autoOpen}
>
<AssistantChat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ export const DrawerToolbarLayoutContainer = forwardRef<
isDrawerOpen={isDrawerOpen}
>
<Toolbar data-lgid={lgIds.toolbar} data-testid={lgIds.toolbar}>
{toolbarData?.map((toolbarItem) => (
{toolbarData?.map((toolbarItem, index) => (
<ToolbarIconButton
key={toolbarItem.glyph}
key={index}
glyph={toolbarItem.glyph}
label={toolbarItem.label}
onClick={(event: React.MouseEvent<HTMLButtonElement>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export {
ToolbarIconButton,
type ToolbarIconButtonProps,
} from './toolbar-icon-button';
export { type IconButtonPropsWithoutChildren } from './toolbar-icon-button/toolbar-icon-button.types';
export { DEFAULT_LGID_ROOT, getLgIds, type GetLgIdsReturnType } from './utils';
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export { ToolbarIconButton } from './toolbar-icon-button';
export { type ToolbarIconButtonProps } from './toolbar-icon-button.types';
export {
type ToolbarIconButtonProps,
type IconButtonPropsWithoutChildren,
} from './toolbar-icon-button.types';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { type ComponentPropsWithoutRef, useEffect } from 'react';
import React, { useEffect } from 'react';

import { useDescendant } from '@leafygreen-ui/descendants';
import Icon from '@leafygreen-ui/icon';
Expand All @@ -13,7 +13,19 @@ import {
getIconButtonStyles,
triggerStyles,
} from './toolbar-icon-button.styles';
import { type ToolbarIconButtonProps } from './toolbar-icon-button.types';
import {
type IconButtonPropsWithoutChildren,
type ToolbarIconButtonProps,
} from './toolbar-icon-button.types';

type IconButtonProps = Omit<
React.ComponentProps<typeof IconButton>,
'children'
> & {
'data-testid': string;
'data-lgid': string;
'data-active': boolean;
};

export const ToolbarIconButton = React.forwardRef<
HTMLButtonElement,
Expand Down Expand Up @@ -60,35 +72,43 @@ export const ToolbarIconButton = React.forwardRef<
if (isFocusable && shouldFocus) ref.current?.focus();
}, [isFocusable, ref, shouldFocus]);

const renderButton =
typeof glyph === 'function'
? glyph
: ({ buttonProps }: { buttonProps: IconButtonProps }) => (
<IconButton {...(buttonProps as IconButtonPropsWithoutChildren)}>
<Icon glyph={glyph} />
</IconButton>
);

return (
<Tooltip
data-testid={`${lgIds.iconButtonTooltip}-${index}`}
data-lgid={`${lgIds.iconButtonTooltip}-${index}`}
align={Align.Left}
trigger={
<div className={triggerStyles}>
<IconButton
aria-label={ariaLabel || getNodeTextContent(label)}
active={active}
className={getIconButtonStyles({
theme,
active,
disabled,
className,
})}
tabIndex={isFocusable ? 0 : -1}
onClick={(event: React.MouseEvent<HTMLButtonElement>) =>
handleOnIconButtonClick(event, index, onClick)
}
disabled={disabled}
data-testid={`${lgIds.iconButton}-${index}`}
data-lgid={`${lgIds.iconButton}-${index}`}
data-active={active}
ref={ref}
{...(rest as ComponentPropsWithoutRef<'button'>)}
>
<Icon glyph={glyph} />
</IconButton>
{renderButton({
buttonProps: {
'aria-label': ariaLabel || getNodeTextContent(label),
active: active,
className: getIconButtonStyles({
theme,
active,
disabled,
className,
}),
tabIndex: isFocusable ? 0 : -1,
onClick: (event: React.MouseEvent<HTMLButtonElement>) =>
handleOnIconButtonClick(event, index, onClick),
disabled: disabled,
'data-testid': `${lgIds.iconButton}-${index}`,
'data-lgid': `${lgIds.iconButton}-${index}`,
'data-active': active,
ref: ref,
...rest,
} as IconButtonPropsWithoutChildren,
})}
</div>
}
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { GlyphName } from '@leafygreen-ui/icon';
import type { BaseIconButtonProps as IconButtonProps } from '@leafygreen-ui/icon-button';
import type IconButton from '@leafygreen-ui/icon-button';

type ButtonProps = Omit<
IconButtonProps,
Expand All @@ -13,11 +14,27 @@ type ButtonProps = Omit<
| 'onClick'
>;

export type IconButtonPropsWithoutChildren = Omit<
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't even know. Look away... 😆

React.ComponentProps<typeof IconButton>,
'children'
> & {
'data-testid': string;
'data-lgid': string;
'data-active': boolean;
'aria-labelledby': string;
};

export interface ToolbarIconButtonProps extends ButtonProps {
/**
* The LG Icon that will render in the button
*/
glyph: GlyphName;
glyph:
| GlyphName
| (({
buttonProps,
}: {
buttonProps: IconButtonPropsWithoutChildren;
}) => React.ReactNode);

/**
* The text that will render in the tooltip on hover
Expand Down
7 changes: 6 additions & 1 deletion packages/compass-web/src/compass-assistant-drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import { CompassAssistantDrawer } from '@mongodb-js/compass-assistant';
// TODO(COMPASS-7830): This is a temporary solution to pass the
// hasNonGenuineConnections prop to the CompassAssistantDrawer as otherwise
// we end up with a circular dependency.
export function CompassAssistantDrawerWithConnections() {
export function CompassAssistantDrawerWithConnections({
appName,
}: {
appName: string;
}) {
// Check for non-genuine connections
const activeConnectionIds = useConnectionIds(
(conn) =>
Expand All @@ -15,6 +19,7 @@ export function CompassAssistantDrawerWithConnections() {
);
return (
<CompassAssistantDrawer
appName={appName}
hasNonGenuineConnections={activeConnectionIds.length > 0}
/>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-web/src/entrypoint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function CompassWorkspace({
<CreateNamespacePlugin></CreateNamespacePlugin>
<DropNamespacePlugin></DropNamespacePlugin>
<RenameCollectionPlugin></RenameCollectionPlugin>
<CompassAssistantDrawerWithConnections />
<CompassAssistantDrawerWithConnections appName="Data Explorer" />
</>
);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import { CompassAssistantDrawer } from '@mongodb-js/compass-assistant';
// TODO(COMPASS-7830): This is a temporary solution to pass the
// hasNonGenuineConnections prop to the CompassAssistantDrawer as otherwise
// we end up with a circular dependency.
export function CompassAssistantDrawerWithConnections() {
export function CompassAssistantDrawerWithConnections({
appName,
}: {
appName: string;
}) {
// Check for non-genuine connections
const activeConnectionIds = useConnectionIds(
(conn) =>
Expand All @@ -15,6 +19,7 @@ export function CompassAssistantDrawerWithConnections() {
);
return (
<CompassAssistantDrawer
appName={appName}
hasNonGenuineConnections={activeConnectionIds.length > 0}
/>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/compass/src/app/components/workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export default function Workspace({
<CreateNamespacePlugin></CreateNamespacePlugin>
<DropNamespacePlugin></DropNamespacePlugin>
<RenameCollectionPlugin></RenameCollectionPlugin>
<CompassAssistantDrawerWithConnections />
<CompassAssistantDrawerWithConnections appName="Compass" />
</>
)}
></WorkspacesPlugin>
Expand Down
Loading