Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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: 10 additions & 0 deletions app/src/assets/localization/en/device_details.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,17 @@
"deck_fixture_setup_modal_top_description": "First, unscrew and remove the deck slot where you'll install a fixture. Then put the fixture in place and attach it as needed.",
"deck_hardware": "deck hardware",
"deck_slot": "deck slot {{slot}}",
"delete_all_logs": "Delete all logs?",
"delete_all_logs_description": "Deleting all logs will permanently remove them from the robot. This action cannot be undone.",
"delete_all_logs_recommendation": "We recommend downloading all log files before proceeding.",
"delete_all_run_records": "Delete all protocol run records?",
"delete_all_run_records_description": "Deleting all protocol run records will permanently remove them from the robot, along with all associated files. This action cannot be undone.",
"delete_all_run_records_recommendation": "We recommend downloading all protocol files before proceeding.",
"delete_run": "Delete protocol run record",
"delete_selected": "Delete selected",
"delete_selected_run_records": "Delete selected protocol run records?",
"delete_selected_run_records_description": "Deleting the selected protocol run records will permanently remove them from the robot, along with all associated files. This action cannot be undone.",
"delete_selected_run_records_recommendation": "We recommend downloading all protocol files before proceeding.",
"detach_gripper": "Detach gripper",
"detach_pipette": "Detach pipette",
"disable_camera": "Disable camera",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { screen } from '@testing-library/react'
import { describe, it, vi } from 'vitest'

import { renderWithProviders } from '/app/__testing-utils__'
import { i18n } from '/app/i18n'

import { DeleteRecordsModal } from '..'

const render = (
type: React.ComponentProps<typeof DeleteRecordsModal>['type']
) =>
renderWithProviders(
<DeleteRecordsModal type={type} onClose={vi.fn()} onConfirm={vi.fn()} />,
{ i18nInstance: i18n }
)

describe('DeleteRecordsModal', () => {
it('renders allRuns copy', () => {
render('allRuns')
screen.getByText('Delete all protocol run records?')
screen.getByText(
'Deleting all protocol run records will permanently remove them from the robot, along with all associated files. This action cannot be undone.'
)
screen.getByText(
'We recommend downloading all protocol files before proceeding.'
)
})

it('renders selectedRuns copy', () => {
render('selectedRuns')
screen.getByText('Delete selected protocol run records?')
screen.getByText(
'Deleting the selected protocol run records will permanently remove them from the robot, along with all associated files. This action cannot be undone.'
)
screen.getByText(
'We recommend downloading all protocol files before proceeding.'
)
})

it('renders allLogs copy', () => {
render('allLogs')
screen.getByText('Delete all logs?')
screen.getByText(
'Deleting all logs will permanently remove them from the robot. This action cannot be undone.'
)
screen.getByText(
'We recommend downloading all log files before proceeding.'
)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.button_row {
display: flex;
height: 100%;
align-items: center;
justify-content: flex-end;
gap: var(--spacing-8);
}

.description {
display: flex;
flex-direction: column;
gap: var(--spacing-8);
}

.modal_content {
display: flex;
flex-direction: column;
gap: var(--spacing-24);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { useTranslation } from 'react-i18next'

import type { DeleteRecordsType } from '../types'

export function useDeleteRecordsText(type: DeleteRecordsType): {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe tweaking the name since this hook doesn't delete anything 🤔
and this can be an util function can't it?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you mean regarding the name— the "Delete" comes from the name of the component that this hook is relevant to.

I used a hook since we directly call useTranslation here. I suppose we can keep it as a util, but that would require passing in the translation object in as an arg. I don't feel strongly about this either way, but I think there's precedent for this pattern in protocol-designer/src/components/organisms/AnnouncementModal/announcements.tsx

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

honestly don’t think the implementation in ‎protocol-designer/src/components/organisms/AnnouncementModal/announcements.tsx is something we should treat as a recommended pattern. The reason is that it’s structured in a way where code just keeps getting added to the component, even though the component’s core functionality itself isn’t actually changing.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So do you recommend passing t as an arg to a utility?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can also add it as an IIF inside DeleteRecordsModal so we don't have to pass the translation object

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don’t have a strong preference either way, but since most of the app code is maintained by the EXEC team, I think it’s best to follow the EXEC team’s conventions.

@SyntaxColoring

title: string
description: string
recommendation: string
} {
const { t } = useTranslation('device_details')
switch (type) {
case 'allRuns':
return {
title: t('delete_all_run_records'),
description: t('delete_all_run_records_description'),
recommendation: t('delete_all_run_records_recommendation'),
}
case 'selectedRuns':
return {
title: t('delete_selected_run_records'),
description: t('delete_selected_run_records_description'),
recommendation: t('delete_selected_run_records_recommendation'),
}
case 'allLogs':
return {
title: t('delete_all_logs'),
description: t('delete_all_logs_description'),
recommendation: t('delete_all_logs_recommendation'),
}
}
}
50 changes: 50 additions & 0 deletions app/src/organisms/Desktop/Devices/DeleteRecordsModal/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { useTranslation } from 'react-i18next'

import {
AlertPrimaryButton,
Modal,
SecondaryButton,
StyledText,
} from '@opentrons/components'

import styles from './deleterecordsmodal.module.css'
import { useDeleteRecordsText } from './hooks/useDeleteRecordsText'

import type { DeleteRecordsType } from './types'

interface DeleteRecordsModalProps {
onClose: () => void
onConfirm: () => void
type: DeleteRecordsType
}

export function DeleteRecordsModal(
props: DeleteRecordsModalProps
): JSX.Element {
const { onClose, onConfirm, type } = props
const { t } = useTranslation(['device_details', 'shared'])
const { title, description, recommendation } = useDeleteRecordsText(type)

return (
<Modal type="warning" title={title} onClose={onClose}>
<div className={styles.modal_content}>
<div className={styles.description}>
<StyledText desktopStyle="bodyDefaultRegular">
{description}
</StyledText>
<StyledText desktopStyle="bodyDefaultRegular">
{recommendation}
</StyledText>
</div>
<div className={styles.button_row}>
<SecondaryButton onClick={onClose}>
{t('shared:cancel')}
</SecondaryButton>
<AlertPrimaryButton onClick={onConfirm}>
{t('delete_all')}
</AlertPrimaryButton>
</div>
</div>
</Modal>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type DeleteRecordsType = 'allRuns' | 'selectedRuns' | 'allLogs'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit
defining this in the modal component?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do that, but I moved the hook that also uses this type to its own file, so I thought it might be better to have a types.ts file

This file was deleted.

188 changes: 0 additions & 188 deletions app/src/organisms/Desktop/Devices/RecentProtocolRuns.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ import { EMPTY_TIMESTAMP } from '/app/resources/runs'
import { formatInterval } from '/app/transformations/commands'
import { formatTimestamp } from '/app/transformations/runs'

import { RECENT_PROTOCOL_RUNS_HEADER } from './constants'
import styles from './HistoricalProtocolRun.module.css'
import { HistoricalProtocolRunOverflowMenu as OverflowMenu } from './HistoricalProtocolRunOverflowMenu'
import styles from './recentprotocolruns.module.css'

import type { RunData } from '@opentrons/api-client'

// inclusive of overflow menu button
const RECENT_PROTOCOL_RUNS_COLUMNS = '30% 25% 16% 5% 14% 10%'

interface HistoricalProtocolRunProps {
run: RunData
protocolName: string
Expand Down Expand Up @@ -72,7 +74,7 @@ export function HistoricalProtocolRun(
<Flex
width="88%"
display="grid"
gridTemplateColumns={RECENT_PROTOCOL_RUNS_HEADER}
gridTemplateColumns={RECENT_PROTOCOL_RUNS_COLUMNS}
gap={SPACING.spacing20}
alignItems={ALIGN_CENTER}
>
Expand Down
Loading
Loading