-
Notifications
You must be signed in to change notification settings - Fork 183
feature(opentrons-ai-client): Attach file #18886
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
base: edge
Are you sure you want to change the base?
feature(opentrons-ai-client): Attach file #18886
Conversation
f635cf7
to
c931478
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code generally looks good! left some comments and questions. I think the big thing is to try to use CSS modules instead of styled-components, if possible 😄
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## edge #18886 +/- ##
===========================================
+ Coverage 25.38% 56.51% +31.12%
===========================================
Files 3333 3333
Lines 287696 287767 +71
Branches 36490 36628 +138
===========================================
+ Hits 73040 162633 +89593
+ Misses 214633 124927 -89706
- Partials 23 207 +184
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
fde7150
to
bf78909
Compare
opentrons-ai-client/src/atoms/AttachFileButton/AttachFileButton.module.css
Show resolved
Hide resolved
opentrons-ai-client/src/atoms/AttachFileButton/AttachFileButton.module.css
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left another round of feedback. it is looking great - thanks for using CSS modules!
opentrons-ai-client/src/atoms/AttachFileButton/AttachFileButton.module.css
Outdated
Show resolved
Hide resolved
opentrons-ai-client/src/atoms/AttachedFileItem/AttachedFileItem.module.css
Outdated
Show resolved
Hide resolved
opentrons-ai-client/src/atoms/AttachedFileItem/AttachedFileItem.module.css
Outdated
Show resolved
Hide resolved
opentrons-ai-client/src/atoms/AttachedFileItem/AttachedFileItem.module.css
Outdated
Show resolved
Hide resolved
fcd8e5a
to
a69df4f
Compare
@@ -0,0 +1,47 @@ | |||
.button { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I posted to #frontend, we decided to use lower case to the module.css file name.
could you rename this to attachfilebutton.module.css?
@@ -0,0 +1,53 @@ | |||
.button { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as AttachFileButton.module.css
@@ -0,0 +1,146 @@ | |||
.main_container { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to change the file name
@@ -0,0 +1,86 @@ | |||
.form { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to change the file name
background-color: var(--white); | ||
border: none; | ||
outline: none; | ||
padding: 1.2rem 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1.2 rem is not our regular spacing var. is this a special case?
font-weight: var(--font-weight-regular); | ||
line-height: var(--line-height-20); | ||
font-family: 'Public Sans', sans-serif; | ||
font-style: normal; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need this?
if you remove this, what will you see in the dev tools?
border: 1px solid var(--grey-20); | ||
border-radius: var(--border-radius-12); | ||
background-color: var(--white); | ||
box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.05); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from our codebase, the team is using px for box-shadow so i recommend you use px instead of rem.
I'll going to add this to the migration doc.
|
||
.main_input_container:focus-within { | ||
border-color: var(--blue-50); | ||
box-shadow: 0 0.125rem 0.5rem rgba(0, 0, 0, 0.1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as the above
} | ||
|
||
.text_input_section { | ||
padding: var(--spacing-16) var(--spacing-16) var(--spacing-4) var(--spacing-16); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
padding: var(--spacing-16) var(--spacing-16) var(--spacing-4) var(--spacing-16); | |
padding: var(--spacing-16) var(--spacing-16) var(--spacing-4); |
const sendButton = screen.getByRole('button', { name: 'Send' }) | ||
expect(sendButton).toBeDisabled() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit
basically we define button const when we will need to check its existence + sytle/click action.
const sendButton = screen.getByRole('button', { name: 'Send' }) | |
expect(sendButton).toBeDisabled() | |
expect(screen.getByRole('button', { name: 'Send' })).toBeDisabled() |
attachedFiles.length > 0 | ||
? attachedFiles.map(file => ({ | ||
name: file.name, | ||
type: getFileType(file) as 'pdf' | 'csv' | 'python', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit
define type like FileType something ?
{/* Error message */} | ||
{fileError && ( | ||
<div className={styles.error_container}> | ||
<StyledText color={COLORS.red50} fontSize={TYPOGRAPHY.fontSizeH3}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for this way, probably adding lineHeight would be good for the migration.
handleClick={() => { | ||
handleClick() | ||
}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not work?
handleClick={() => { | |
handleClick() | |
}} | |
handleClick={handleClick} |
i think the prop name I named isn't good. i will open a pr to mofity that.
pdf: 10 * 1024 * 1024, // 10MB | ||
csv: 2 * 1024 * 1024, // 2MB | ||
python: 1 * 1024 * 1024, // 1MB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just out of curiosity—how did you decide on the size?
@@ -7,6 +7,13 @@ export type ProtocolFormat = 'Protocol Designer' | 'Python' | |||
/** assistant: ChatGPT API, user: user */ | |||
type Role = 'assistant' | 'user' | |||
|
|||
export interface FileAttachment { | |||
name: string | |||
type: 'pdf' | 'csv' | 'python' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't need unknown?
python: ['.py'], | ||
} as const | ||
|
||
export type FileType = 'pdf' | 'csv' | 'python' | 'unknown' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import type { FileAttachment } from
export type FileType = FileAttachment['type'] | 'unknown'
or may move this type to types.ts since it is exported.
|
||
const sizeLimit = FILE_SIZE_LIMITS[fileType] | ||
if (file.size > sizeLimit) { | ||
const sizeMB = Math.round(sizeLimit / (1024 * 1024)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit
const UNIT_MB = 1024 * 1024
export const FILE_SIZE_LIMITS = {
pdf: 10 * UNIT_MB, // 10MB
csv: 2 * UNIT_MB, // 2MB
python: 1 * UNIT_MB, // 1MB
}
const sizeMB = Math.round(sizeLimit / (UNIT_MB))
export const getFileTypeLabel = (type: FileType): string => { | ||
switch (type) { | ||
case 'pdf': | ||
return 'PDF file' | ||
case 'csv': | ||
return 'CSV file' | ||
case 'python': | ||
return 'Python file' | ||
default: | ||
return 'File' | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit
you can use map
const fileTypeLabels: Record<FileType, string> = {
pdf: 'PDF file',
csv: 'CSV file',
python: 'Python file',
unknown: 'File',
}
export const getFileTypeLabel = (type: FileType): string => fileTypeLabels[type]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if possible, i recommend you use a different string for unknonw since there is a type, File
.
|
||
export const formatFileSize = (bytes: number): string => { | ||
if (bytes === 0) { | ||
return '0 B' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the space between B and 0 is intentinal?
const sizes = ['B', 'KB', 'MB', 'GB'] | ||
const i = Math.floor(Math.log(bytes) / Math.log(k)) | ||
|
||
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(1))} ${sizes[i]}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(1))} ${sizes[i]}` | |
const size = bytes / Math.pow(k, i) | |
const rounded = size.toFixed(1) | |
return `${rounded} ${sizes[i] ?? 'B'}` |
Overview
Closes AUTH-2019
Figma
This introduces attach file button and attachments and send button modification
With Attach file button
With Attachment

After Send
Test Plan and Hands on Testing
CI
Review requests
Make sure Attach file and Send button and attachments are visible in UI
Risk assessment
Mid