Skip to content

Commit

Permalink
refactor: simplify data structure
Browse files Browse the repository at this point in the history
  • Loading branch information
fbelginetw committed Oct 16, 2024
1 parent 84f8237 commit d8941e1
Showing 1 changed file with 10 additions and 29 deletions.
39 changes: 10 additions & 29 deletions opentrons-ai-client/src/molecules/PromptPreview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,17 @@ import {

const PROMPT_PREVIEW_PLACEHOLDER_MESSAGE =
'As you complete the sections on the left, your prompt will be built here. When all requirements are met you will be able to generate the protocol.'
const SECTION_TITLES = [
'Application',
'Instruments',
'Modules',
'Labware and Liquids',
'Steps',
]

interface SectionData {
title: string
items: string[]
}

interface AccordionProps {
id?: string
isSubmitButtonEnabled?: boolean
handleSubmit: () => void
promptPreviewData: PromptPreviewData
}

interface PromptPreviewData {
application: string[]
instruments: string[]
modules: string[]
labwareAndLiquids: string[]
steps: string[]
promptPreviewData: SectionData[]
}

const PromptPreviewContainer = styled(Flex)`
Expand Down Expand Up @@ -74,16 +64,7 @@ export function PromptPreview({
promptPreviewData,
}: AccordionProps): JSX.Element {
const areAllSectionsEmpty = (): boolean => {
const {
application,
instruments,
modules,
labwareAndLiquids,
steps,
} = promptPreviewData
return [application, instruments, modules, labwareAndLiquids, steps].every(
arr => arr.length === 0
)
return promptPreviewData.every(section => section.items.length === 0)
}

return (
Expand All @@ -104,13 +85,13 @@ export function PromptPreview({

{Object.values(promptPreviewData).map(
(section, index) =>
section.length > 0 && (
section.items.length > 0 && (
<PromptPreviewSection key={`section-${index}`}>
<SectionHeading desktopStyle="bodyLargeSemiBold">
{SECTION_TITLES[index]}
{section.title}
</SectionHeading>
<TagGrid>
{section.map((item: string, index: number) => (
{section.items.map((item: string, index: number) => (
<Tag key={`tag-${index}`} text={item} type={'default'} />
))}
</TagGrid>
Expand Down

0 comments on commit d8941e1

Please sign in to comment.