-
Notifications
You must be signed in to change notification settings - Fork 204
feat(app): create DeleteRecordsModal #21856
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
Changes from 4 commits
e68bf59
13476a2
2e715a1
5ff2c40
2d0c00a
2e49b8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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): { | ||
| 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'), | ||
| } | ||
| } | ||
| } | ||
| 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' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
This file was deleted.
This file was deleted.
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.
maybe tweaking the name since this hook doesn't delete anything 🤔
and this can be an util function can't it?
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 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
useTranslationhere. 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 inprotocol-designer/src/components/organisms/AnnouncementModal/announcements.tsxThere 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.
honestly don’t think the implementation in
protocol-designer/src/components/organisms/AnnouncementModal/announcements.tsxis 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.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.
So do you recommend passing
tas an arg to a utility?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 can also add it as an IIF inside DeleteRecordsModal so we don't have to pass the translation object
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 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