Skip to content

Commit

Permalink
feat(opentrons-ai-client): Header component with title and log out bu…
Browse files Browse the repository at this point in the history
…tton (#16542)

<!--
Thanks for taking the time to open a Pull Request (PR)! Please make sure
you've read the "Opening Pull Requests" section of our Contributing
Guide:


https://github.com/Opentrons/opentrons/blob/edge/CONTRIBUTING.md#opening-pull-requests

GitHub provides robust markdown to format your PR. Links, diagrams,
pictures, and videos along with text formatting make it possible to
create a rich and informative PR. For more information on GitHub
markdown, see:


https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax

To ensure your code is reviewed quickly and thoroughly, please fill out
the sections below to the best of your ability!
-->

# Overview

<!--
Describe your PR at a high level. State acceptance criteria and how this
PR fits into other work. Link issues, PRs, and other relevant resources.
-->

Added a new header component to the app that has a functional logout
button.

## Test Plan and Hands on Testing

<!--
Describe your testing of the PR. Emphasize testing not reflected in the
code. Attach protocols, logs, screenshots and any other assets that
support your testing.
-->

Tested the logout functionality manually.

## Changelog

<!--
List changes introduced by this PR considering future developers and the
end user. Give careful thought and clear documentation to breaking
changes.
-->

<img width="1018" alt="image"
src="https://github.com/user-attachments/assets/709bc7cd-45d6-4282-9ff7-fafdbe256d32">

## Review requests

<!--
- What do you need from reviewers to feel confident this PR is ready to
merge?
- Ask questions.
-->

## Risk assessment

<!--
- Indicate the level of attention this PR needs.
- Provide context to guide reviewers.
- Discuss trade-offs, coupling, and side effects.
- Look for the possibility, even if you think it's small, that your
change may affect some other part of the system.
- For instance, changing return tip behavior may also change the
behavior of labware calibration.
- How do your unit tests and on hands on testing mitigate this PR's
risks and the risk of future regressions?
- Especially in high risk PRs, explain how you know your testing is
enough.
-->
  • Loading branch information
connected-znaim authored Oct 22, 2024
1 parent b381a04 commit b2f2546
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"ai": "AI",
"api": "API: An API level is 2.15",
"application": "Application: Your protocol's name, describing what it does.",
"commands": "Commands: List the protocol's steps, specifying quantities in microliters (uL) and giving exact source and destination locations.",
Expand All @@ -15,6 +16,7 @@
"make_sure_your_prompt": "Write a prompt in a natural language for OpentronsAI to generate a protocol using the Opentrons Python Protocol API v2. The better the prompt, the better the quality of the protocol produced by OpentronsAI.",
"modules_and_adapters": "Modules and adapters: Specify the modules and labware adapters required by your protocol.",
"notes": "A few important things to note:",
"opentrons": "Opentrons",
"opentronsai": "OpentronsAI",
"ot2_pipettes": "OT-2 pipettes: Include volume, number of channels, and generation.",
"pcr_flex": "PCR (Flex)",
Expand Down
20 changes: 20 additions & 0 deletions opentrons-ai-client/src/molecules/Header/Header.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Meta, StoryObj } from '@storybook/react'
import { Header as HeaderComponent } from '.'
import { COLORS, Flex, SPACING } from '@opentrons/components'

const meta: Meta<typeof HeaderComponent> = {
title: 'AI/Molecules/Header',
component: HeaderComponent,
decorators: [
Story => (
<Flex backgroundColor={COLORS.grey10} padding={SPACING.spacing40}>
<Story />
</Flex>
),
],
}
export default meta

type Story = StoryObj<typeof HeaderComponent>

export const ChatHeaderExample: Story = {}
23 changes: 23 additions & 0 deletions opentrons-ai-client/src/molecules/Header/__tests__/Header.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { renderWithProviders } from '../../../__testing-utils__'
import { i18n } from '../../../i18n'
import { Header } from '../index'
import { describe, it } from 'vitest'
import { screen } from '@testing-library/react'

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

describe('Header', () => {
it('should render Header component', () => {
render()
screen.getByText('Opentrons')
})

it('should render log out button', () => {
render()
screen.getByText('Logout')
})
})
63 changes: 63 additions & 0 deletions opentrons-ai-client/src/molecules/Header/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { useTranslation } from 'react-i18next'
import styled from 'styled-components'

import {
Flex,
StyledText,
Link as LinkButton,
POSITION_ABSOLUTE,
TYPOGRAPHY,
COLORS,
POSITION_RELATIVE,
ALIGN_CENTER,
JUSTIFY_SPACE_BETWEEN,
} from '@opentrons/components'
import { useAuth0 } from '@auth0/auth0-react'

const HeaderBar = styled(Flex)`
position: ${POSITION_RELATIVE};
background-color: ${COLORS.white};
width: 100%;
align-items: ${ALIGN_CENTER};
height: 60px;
`

const HeaderBarContent = styled(Flex)`
position: ${POSITION_ABSOLUTE};
padding: 18px 32px;
justify-content: ${JUSTIFY_SPACE_BETWEEN};
width: 100%;
`

const HeaderGradientTitle = styled(StyledText)`
background: linear-gradient(90deg, #562566 0%, #893ba4 47.5%, #c189d4 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
font-size: 16px;
`

const HeaderTitle = styled(StyledText)`
font-size: 16px;
`

const LogoutButton = styled(LinkButton)`
color: ${COLORS.grey50};
font-size: ${TYPOGRAPHY.fontSizeH3};
`

export function Header(): JSX.Element {
const { t } = useTranslation('protocol_generator')
const { logout } = useAuth0()

return (
<HeaderBar>
<HeaderBarContent>
<Flex>
<HeaderTitle>{t('opentrons')}</HeaderTitle>
<HeaderGradientTitle>{t('ai')}</HeaderGradientTitle>
</Flex>
<LogoutButton onClick={() => logout()}>{t('logout')}</LogoutButton>
</HeaderBarContent>
</HeaderBar>
)
}

0 comments on commit b2f2546

Please sign in to comment.