Skip to content
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

DOP-5203: change Chatbot access from search input to button #1311

Merged
merged 18 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 15 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
13 changes: 6 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 42 additions & 1 deletion src/components/ActionBar/ActionBar.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import React, { useContext } from 'react';
import React, { lazy, useState, useContext } from 'react';
import PropTypes from 'prop-types';
import Button from '@leafygreen-ui/button';
import { cx } from '@leafygreen-ui/emotion';
import Icon from '@leafygreen-ui/icon';
import { Overline } from '@leafygreen-ui/typography';
import { useDarkMode } from '@leafygreen-ui/leafygreen-provider';
import { useSiteMetadata } from '../../hooks/use-site-metadata';
import { isBrowser } from '../../utils/is-browser';
import { getPlaintext } from '../../utils/get-plaintext';
import { getNestedValue } from '../../utils/get-nested-value';
import { isOfflineDocsBuild } from '../../utils/is-offline-docs-build';
import { getCurrLocale } from '../../utils/locale';
import { reportAnalytics } from '../../utils/report-analytics';
import useSnootyMetadata from '../../utils/use-snooty-metadata';
import { SidenavContext } from '../Sidenav';
import {
Expand All @@ -16,6 +21,7 @@ import {
useFeedbackData,
FeedbackContainer,
} from '../Widgets/FeedbackWidget';
import { SuspenseHelper } from '../SuspenseHelper';
import DarkModeDropdown from './DarkModeDropdown';
import SearchInput from './SearchInput';
import {
Expand All @@ -25,13 +31,19 @@ import {
getContainerStyling,
offlineStyling,
overlineStyling,
buttonStyling,
} from './styles';

const Chatbot = lazy(() => import('mongodb-chatbot-ui'));
const LazyChatbot = lazy(() => import('./LazyChatbot'));

export const DEPRECATED_PROJECTS = ['atlas-app-services', 'datalake', 'realm'];

const ActionBar = ({ template, slug, sidenav, ...props }) => {
const url = isBrowser ? window.location.href : null;
const metadata = useSnootyMetadata();
const [chatbotClicked, setChatbotClicked] = useState(false);
const locale = getCurrLocale();
const feedbackData = useFeedbackData({
slug,
url,
Expand All @@ -43,6 +55,16 @@ const ActionBar = ({ template, slug, sidenav, ...props }) => {

const { hideMobile, setHideMobile } = useContext(SidenavContext);

const onClick = () => {
reportAnalytics('Chatbot button clicked');
setChatbotClicked((currVal) => !currVal);
};
const { snootyEnv } = useSiteMetadata();
const { darkMode } = useDarkMode();
const CHATBOT_SERVER_BASE_URL = ['dotcomprd', 'production'].includes(snootyEnv)
? 'https://knowledge.mongodb.com/api/v1'
: 'https://knowledge.staging.corp.mongodb.com/api/v1';

return (
<div
className={cx(props.className, actionBarStyling, containerClassname, isOfflineDocsBuild ? offlineStyling : '')}
Expand All @@ -60,6 +82,25 @@ const ActionBar = ({ template, slug, sidenav, ...props }) => {
{!isOfflineDocsBuild && (
<ActionsBox>
{template !== 'openapi' && <DarkModeDropdown />}
{locale === 'en-us' && (
<Button
className={cx(buttonStyling)}
rayangler marked this conversation as resolved.
Show resolved Hide resolved
leftGlyph={<Icon glyph="Sparkle" />}
aria-label={'Ask MongoDB AI'}
variant={'primaryOutline'}
onClick={onClick}
>
Ask Mongodb AI
</Button>
)}
{locale === 'en-us' && (
<SuspenseHelper>
<Chatbot serverBaseUrl={CHATBOT_SERVER_BASE_URL} darkMode={darkMode}>
<LazyChatbot chatbotClicked={chatbotClicked} setChatbotClicked={setChatbotClicked} />
</Chatbot>
</SuspenseHelper>
)}

{template !== 'errorpage' && !DEPRECATED_PROJECTS.includes(metadata.project) && (
<FeedbackProvider page={feedbackData}>
<FeedbackContainer>
Expand Down
28 changes: 0 additions & 28 deletions src/components/ActionBar/ChatbotControls.js

This file was deleted.

34 changes: 34 additions & 0 deletions src/components/ActionBar/LazyChatbot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React, { useEffect } from 'react';
import { useChatbotContext, ModalView, MongoDbLegalDisclosure, PoweredByAtlasVectorSearch } from 'mongodb-chatbot-ui';
import { css } from '@leafygreen-ui/emotion';

const LazyChatbot = ({ chatbotClicked, setChatbotClicked }) => {
rayangler marked this conversation as resolved.
Show resolved Hide resolved
const { openChat } = useChatbotContext();
useEffect(() => {
if (chatbotClicked) {
openChat();
setChatbotClicked(false);
}
}, [chatbotClicked, openChat, setChatbotClicked]);

return (
<ModalView
inputBottomText={
'This is an experimental generative AI chatbot. All information should be verified prior to use.'
}
disclaimer={
<>
<MongoDbLegalDisclosure />
<PoweredByAtlasVectorSearch
linkStyle="text"
className={css`
margin-top: 8px;
`}
/>
</>
}
/>
);
};

export default LazyChatbot;
Loading