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

refactor: Design of messages #635

Merged
merged 10 commits into from
Jan 6, 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
2 changes: 1 addition & 1 deletion backend/chainlit/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def ask_user_fn(data, timeout):
data_layer.create_user_session(
id=session_id,
started_at=datetime.utcnow().isoformat(),
anon_user_id=anon_user_identifier,
anon_user_id=anon_user_identifier if not user else None,
user_id=user.identifier if user else None,
)
)
Expand Down
14 changes: 7 additions & 7 deletions cypress/e2e/action/spec.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ describe('Action', () => {

it('should correctly execute and display actions', () => {
// Click on "first action"
cy.get('#first-action').should('be.visible');
cy.get('#first-action').should('exist');
cy.get('#first-action').click();
cy.get('.step').should('have.length', 3);
cy.get('.step')
.eq(2)
.should('contain', 'Thanks for pressing: first-action');

// Click on "test action"
cy.get("[id='test-action']").should('be.visible');
cy.get("[id='test-action']").should('exist');
cy.get("[id='test-action']").click();
cy.get('.step').should('have.length', 4);
cy.get('.step').eq(3).should('contain', 'Executed test action!');
Expand All @@ -24,7 +24,7 @@ describe('Action', () => {
cy.wait(100);

// Click on "removable action"
cy.get("[id='removable-action']").should('be.visible');
cy.get("[id='removable-action']").should('exist');
cy.get("[id='removable-action']").click();
cy.get('.step').should('have.length', 5);
cy.get('.step').eq(4).should('contain', 'Executed removable action!');
Expand All @@ -33,13 +33,13 @@ describe('Action', () => {
cy.wait(100);

// Click on "multiple action one" in the action drawer, should remove the correct action button
cy.get("[id='actions-drawer-button']").should('be.visible');
cy.get("[id='actions-drawer-button']").should('exist');
cy.get("[id='actions-drawer-button']").click();
cy.get('.step').should('have.length', 5);

cy.wait(100);

cy.get("[id='multiple-action-one']").should('be.visible');
cy.get("[id='multiple-action-one']").should('exist');
cy.get("[id='multiple-action-one']").click();
cy.get('.step')
.eq(5)
Expand All @@ -51,7 +51,7 @@ describe('Action', () => {
// Click on "multiple action two", should remove the correct action button
cy.get('.step').should('have.length', 6);
cy.get("[id='actions-drawer-button']").click();
cy.get("[id='multiple-action-two']").should('be.visible');
cy.get("[id='multiple-action-two']").should('exist');
cy.get("[id='multiple-action-two']").click();
cy.get('.step')
.eq(6)
Expand All @@ -61,7 +61,7 @@ describe('Action', () => {
cy.wait(100);

// Click on "all actions removed", should remove all buttons
cy.get("[id='all-actions-removed']").should('be.visible');
cy.get("[id='all-actions-removed']").should('exist');
cy.get("[id='all-actions-removed']").click();
cy.get('.step').eq(7).should('contain', 'All actions have been removed!');
cy.get("[id='all-actions-removed']").should('not.exist');
Expand Down
10 changes: 5 additions & 5 deletions cypress/e2e/avatar/spec.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ describe('Avatar', () => {
it('should be able to display avatars', () => {
cy.get('.step').should('have.length', 5);

cy.get('.step').eq(0).find('.message-avatar').should('have.length', 0);
cy.get('.step').eq(1).find('.message-avatar').should('have.length', 1);
cy.get('.step').eq(2).find('.message-avatar').should('have.length', 0);
cy.get('.step').eq(3).find('.message-avatar').should('have.length', 1);
cy.get('.step').eq(4).find('.message-avatar').should('have.length', 1);
cy.get('.step').eq(0).find('img').should('have.length', 0);
cy.get('.step').eq(1).find('img').should('have.length', 1);
cy.get('.step').eq(2).find('img').should('have.length', 0);
cy.get('.step').eq(3).find('img').should('have.length', 1);
cy.get('.step').eq(4).find('img').should('have.length', 1);

cy.get('.element-link').should('have.length', 0);
});
Expand Down
22 changes: 22 additions & 0 deletions frontend/src/assets/chevronLeft.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import SvgIcon, { SvgIconProps } from '@mui/material/SvgIcon';

const ChevronLeftIcon = (props: SvgIconProps) => {
return (
<SvgIcon>
<svg
{...props}
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
>
<path d="m11 17-5-5 5-5" />
<path d="m18 17-5-5 5-5" />
</svg>
</SvgIcon>
);
};

export default ChevronLeftIcon;
22 changes: 22 additions & 0 deletions frontend/src/assets/chevronRight.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import SvgIcon, { SvgIconProps } from '@mui/material/SvgIcon';

const ChevronRightIcon = (props: SvgIconProps) => {
return (
<SvgIcon>
<svg
{...props}
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
>
<path d="m6 17 5-5-5-5" />
<path d="m13 17 5-5-5-5" />
</svg>
</SvgIcon>
);
};

export default ChevronRightIcon;
22 changes: 22 additions & 0 deletions frontend/src/assets/chevronUp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import SvgIcon, { SvgIconProps } from '@mui/material/SvgIcon';

const ChevronUpIcon = (props: SvgIconProps) => {
return (
<SvgIcon>
<svg
{...props}
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
>
<path d="m17 11-5-5-5 5" />
<path d="m17 18-5-5-5 5" />
</svg>
</SvgIcon>
);
};

export default ChevronUpIcon;
22 changes: 22 additions & 0 deletions frontend/src/assets/user.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import SvgIcon, { SvgIconProps } from '@mui/material/SvgIcon';

const UserIcon = (props: SvgIconProps) => {
return (
<SvgIcon>
<svg
{...props}
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
>
<path d="M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2" />
<circle cx="12" cy="7" r="4" />
</svg>
</SvgIcon>
);
};

export default UserIcon;
8 changes: 6 additions & 2 deletions frontend/src/components/atoms/buttons/userButton/avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { useAuth } from 'api/auth';

import { Avatar, Box } from '@mui/material';

import UserIcon from 'assets/user';

export default function UserAvatar() {
const { user } = useAuth();

Expand All @@ -16,7 +18,7 @@ export default function UserAvatar() {
}}
src={user.metadata?.image || undefined}
>
{user.identifier?.[0]}
{user.identifier?.[0]?.toUpperCase()}
</Avatar>
);
} else {
Expand All @@ -29,7 +31,9 @@ export default function UserAvatar() {
bgcolor: 'primary.main',
color: 'primary.contrastText'
}}
/>
>
<UserIcon sx={{ width: 20 }} />
</Avatar>
</Box>
);
}
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/components/organisms/chat/history/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useRef, useState } from 'react';
import { useRecoilState } from 'recoil';

import AutoDelete from '@mui/icons-material/AutoDelete';
import KeyboardDoubleArrowUpIcon from '@mui/icons-material/KeyboardDoubleArrowUp';
import {
IconButton,
Menu,
Expand All @@ -17,6 +16,8 @@ import {
import { UserInput } from '@chainlit/react-client';
import { grey } from '@chainlit/react-components/theme';

import ChevronUpIcon from 'assets/chevronUp';

import { inputHistoryState } from 'state/userInputHistory';

interface Props {
Expand Down Expand Up @@ -247,7 +248,7 @@ export default function InputHistoryButton({ disabled, onClick }: Props) {
onClick={() => toggleChatHistoryMenu(!inputHistory.open)}
ref={ref}
>
<KeyboardDoubleArrowUpIcon />
<ChevronUpIcon />
</IconButton>
</span>
</Tooltip>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/organisms/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const Header = memo(
borderBottomColor: (theme) => theme.palette.divider
}}
>
<Stack alignItems="center" direction={'row'} gap={!matches ? 3 : 1}>
<Stack alignItems="center" direction={'row'} gap={!matches ? 3 : 0}>
{!matches ? <Logo style={{ maxHeight: '25px' }} /> : null}
<Nav
matches={matches}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';

import Box from '@mui/material/Box';
import Tooltip from '@mui/material/Tooltip';

interface TriggerButtonProps {
onClick: () => void;
Expand All @@ -16,26 +15,28 @@ const commonBoxStyles = {

const TriggerButton = ({ onClick, open }: TriggerButtonProps): JSX.Element => {
return (
<Box
sx={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
cursor: 'pointer',
padding: 2,
'&:hover div:nth-child(1)': {
transform: open ? 'rotate(15deg)' : 'rotate(-15deg)'
},
'&:hover div:nth-child(2)': {
transform: open ? 'rotate(-15deg)' : 'rotate(15deg)'
}
}}
onClick={onClick}
>
<Box sx={{ ...commonBoxStyles, marginTop: '0.25rem' }} />
<Box sx={{ ...commonBoxStyles, marginTop: '-0.25rem' }} />
</Box>
<Tooltip title={open ? 'Close sidebar' : 'Open sidebar'} placement="right">
<Box
sx={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
cursor: 'pointer',
padding: 2,
'&:hover div:nth-child(1)': {
transform: open ? 'rotate(15deg)' : 'rotate(-15deg)'
},
'&:hover div:nth-child(2)': {
transform: open ? 'rotate(-15deg)' : 'rotate(15deg)'
}
}}
onClick={onClick}
>
<Box sx={{ ...commonBoxStyles, marginTop: '0.25rem' }} />
<Box sx={{ ...commonBoxStyles, marginTop: '-0.25rem' }} />
</Box>
</Tooltip>
);
};

Expand Down
30 changes: 23 additions & 7 deletions frontend/src/components/organisms/threadHistory/sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import uniqBy from 'lodash/uniqBy';
import { useEffect, useRef, useState } from 'react';
import { useRecoilState, useRecoilValue } from 'recoil';

import Box from '@mui/material/Box';
import Drawer from '@mui/material/Drawer';
import Stack from '@mui/material/Stack';
import Typography from '@mui/material/Typography';
Expand Down Expand Up @@ -126,7 +127,7 @@ const _ThreadHistorySideBar = () => {
}, []);

return (
<>
<Box display="flex" position="relative">
<Drawer
className="chat-history-drawer"
anchor="left"
Expand All @@ -146,7 +147,12 @@ const _ThreadHistorySideBar = () => {
gap: 1,
display: 'flex',
padding: '0px 4px',
backgroundImage: 'none'
backgroundImage: 'none',
borderRight: 'none',
boxShadow: (theme) =>
theme.palette.mode === 'dark'
? '0px 4px 20px 0px rgba(0, 0, 0, 0.20)'
: '0px 4px 20px 0px rgba(0, 0, 0, 0.05)'
}
}}
>
Expand Down Expand Up @@ -181,12 +187,22 @@ const _ThreadHistorySideBar = () => {
) : null}
</Drawer>
{!isMobile ? (
<TriggerButton
onClick={() => setChatHistoryOpen(!settings.isChatHistoryOpen)}
open={settings.isChatHistoryOpen}
/>
<Box
position="absolute"
sx={{
top: '50%',
transform: 'translateY(-100%)',
right: -30,
zIndex: 10
}}
>
<TriggerButton
onClick={() => setChatHistoryOpen(!settings.isChatHistoryOpen)}
open={settings.isChatHistoryOpen}
/>
</Box>
) : null}
</>
</Box>
);
};

Expand Down
Loading