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

fix(opentrons-ai-client) fix textarea overlapping issue #15307

Merged
merged 6 commits into from
May 31, 2024
Merged
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
10 changes: 6 additions & 4 deletions opentrons-ai-client/src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as auth0 from '@auth0/auth0-react'
import { renderWithProviders } from './__testing-utils__'
import { i18n } from './i18n'
import { SidePanel } from './molecules/SidePanel'
import { ChatContainer } from './organisms/ChatContainer'
import { MainContentContainer } from './organisms/MainContentContainer'
import { Loading } from './molecules/Loading'

import { App } from './App'
Expand All @@ -16,7 +16,7 @@ vi.mock('@auth0/auth0-react')
const mockLogout = vi.fn()

vi.mock('./molecules/SidePanel')
vi.mock('./organisms/ChatContainer')
vi.mock('./organisms/MainContentContainer')
vi.mock('./molecules/Loading')

const render = (): ReturnType<typeof renderWithProviders> => {
Expand All @@ -28,7 +28,9 @@ const render = (): ReturnType<typeof renderWithProviders> => {
describe('App', () => {
beforeEach(() => {
vi.mocked(SidePanel).mockReturnValue(<div>mock SidePanel</div>)
vi.mocked(ChatContainer).mockReturnValue(<div>mock ChatContainer</div>)
vi.mocked(MainContentContainer).mockReturnValue(
<div>mock MainContentContainer</div>
)
vi.mocked(Loading).mockReturnValue(<div>mock Loading</div>)
})

Expand All @@ -48,7 +50,7 @@ describe('App', () => {
})
render()
screen.getByText('mock SidePanel')
screen.getByText('mock ChatContainer')
screen.getByText('mock MainContentContainer')
screen.getByText('Logout')
})

Expand Down
4 changes: 2 additions & 2 deletions opentrons-ai-client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { tokenAtom } from './resources/atoms'
import { useGetAccessToken } from './resources/hooks'
import { SidePanel } from './molecules/SidePanel'
import { Loading } from './molecules/Loading'
import { ChatContainer } from './organisms/ChatContainer'
import { MainContentContainer } from './organisms/MainContentContainer'

export interface InputType {
userPrompt: string
Expand Down Expand Up @@ -75,7 +75,7 @@ export function App(): JSX.Element | null {
</Flex>
<FormProvider {...methods}>
<SidePanel />
<ChatContainer />
<MainContentContainer />
</FormProvider>
</Flex>
)
Expand Down
1 change: 1 addition & 0 deletions opentrons-ai-client/src/atoms/GlobalStyle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const GlobalStyle = createGlobalStyle`
width: 100%;
height: 100%;
color: ${COLORS.black90};
overflow: hidden;
}

a {
Expand Down
5 changes: 2 additions & 3 deletions opentrons-ai-client/src/molecules/ChatFooter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ export function ChatFooter(): JSX.Element {

return (
<Flex
bottom="0"
width="100%"
gridGap={SPACING.spacing24}
flexDirection={DIRECTION_COLUMN}
minHeight="calc(100vh-15rem)"
paddingBottom={SPACING.spacing24}
>
<InputPrompt />
<StyledText css={DISCLAIMER_TEXT_STYLE}>{t('disclaimer')}</StyledText>
Expand All @@ -33,4 +31,5 @@ const DISCLAIMER_TEXT_STYLE = css`
font-size: ${TYPOGRAPHY.fontSize20};
line-height: ${TYPOGRAPHY.lineHeight24};
text-align: ${TYPOGRAPHY.textAlignCenter};
padding-bottom: ${SPACING.spacing24};
`
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react'
import { I18nextProvider } from 'react-i18next'
import { i18n } from '../../i18n'
import { ChatContainer as ChatContainerComponent } from './index'
import { MainContentContainer as MainContentContainerComponent } from './index'

import type { Meta, StoryObj } from '@storybook/react'

const meta: Meta<typeof ChatContainerComponent> = {
const meta: Meta<typeof MainContentContainerComponent> = {
title: 'AI/organisms/ChatContainer',
component: ChatContainerComponent,
component: MainContentContainerComponent,
decorators: [
Story => (
<I18nextProvider i18n={i18n}>
Expand All @@ -17,5 +17,5 @@ const meta: Meta<typeof ChatContainerComponent> = {
],
}
export default meta
type Story = StoryObj<typeof ChatContainerComponent>
type Story = StoryObj<typeof MainContentContainerComponent>
export const ChatContainer: Story = {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import { renderWithProviders } from '../../../__testing-utils__'
import { i18n } from '../../../i18n'
import { PromptGuide } from '../../../molecules/PromptGuide'
import { ChatFooter } from '../../../molecules/ChatFooter'
import { ChatContainer } from '../index'
import { MainContentContainer } from '../index'

vi.mock('../../../molecules/PromptGuide')
vi.mock('../../../molecules/ChatFooter')
// Note (kk:05/20/2024) to avoid TypeError: scrollRef.current.scrollIntoView is not a function
window.HTMLElement.prototype.scrollIntoView = vi.fn()

const render = (): ReturnType<typeof renderWithProviders> => {
return renderWithProviders(<ChatContainer />, {
return renderWithProviders(<MainContentContainer />, {
i18nInstance: i18n,
})
}

describe('ChatContainer', () => {
describe('MainContentContainer', () => {
beforeEach(() => {
vi.mocked(PromptGuide).mockReturnValue(<div>mock PromptGuide</div>)
vi.mocked(ChatFooter).mockReturnValue(<div>mock ChatFooter</div>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
DIRECTION_COLUMN,
Flex,
OVERFLOW_AUTO,
POSITION_FIXED,
SPACING,
StyledText,
} from '@opentrons/components'
Expand All @@ -17,7 +16,7 @@ import { ChatDisplay } from '../../molecules/ChatDisplay'
import { ChatFooter } from '../../molecules/ChatFooter'
import { chatDataAtom } from '../../resources/atoms'

export function ChatContainer(): JSX.Element {
export function MainContentContainer(): JSX.Element {
const { t } = useTranslation('protocol_generator')
const [chatData] = useAtom(chatDataAtom)
const scrollRef = React.useRef<HTMLSpanElement | null>(null)
Expand All @@ -40,14 +39,20 @@ export function ChatContainer(): JSX.Element {
width="auto"
flexDirection={DIRECTION_COLUMN}
gridGap={SPACING.spacing40}
minHeight={`calc(100vh-24.375rem)`}
overflowY={OVERFLOW_AUTO}
height="100vh"
>
<Flex width="100%" height="100%">
<ChatDataContainer>
<StyledText>{t('opentronsai')}</StyledText>
<Flex
width="100%"
flexGrow="1"
overflowY={OVERFLOW_AUTO}
flexDirection={DIRECTION_COLUMN}
>
<Flex flexDirection={DIRECTION_COLUMN} gridGap={SPACING.spacing12}>
{/* Prompt Guide remain as a reference for users. */}
<StyledText>{t('opentronsai')}</StyledText>
<PromptGuide />
</Flex>
<ChatDataContainer>
{chatData.length > 0
? chatData.map((chat, index) => (
<ChatDisplay
Expand All @@ -58,9 +63,9 @@ export function ChatContainer(): JSX.Element {
))
: null}
</ChatDataContainer>
<span ref={scrollRef} />
</Flex>
<span ref={scrollRef} />
<Flex position={POSITION_FIXED} bottom="0" zIndex="2" width="69%">
<Flex bottom="0" zIndex="2" width="100%" flexDirection={DIRECTION_COLUMN}>
<ChatFooter />
</Flex>
</Flex>
Expand All @@ -71,5 +76,4 @@ const ChatDataContainer = styled(Flex)`
flex-direction: ${DIRECTION_COLUMN};
grid-gap: ${SPACING.spacing40};
width: 100%;
height: calc(100vh + 9rem);
`
Loading