From 0d932a226bea1c52b36183cf903422a9b2b17348 Mon Sep 17 00:00:00 2001 From: Jimmy Domagala-Tang Date: Tue, 5 Sep 2023 10:00:19 -0400 Subject: [PATCH] Merge pull request #14492 from overleaf/ds-remake-compare HIstory UI - Adding a new compare component for drop down GitOrigin-RevId: 3e01e8fedd5966c1bc6253df0e8868e4a41b8504 --- .../compare-version-dropdown-content.tsx | 136 ++++++++++-------- .../menu-item/compare-dropdown-item.tsx | 43 ++++++ .../dropdown/menu-item/compare-items.tsx | 4 - .../dropdown/menu-item/compare.tsx | 3 - .../history/components/change-list.spec.tsx | 8 +- 5 files changed, 126 insertions(+), 68 deletions(-) create mode 100644 services/web/frontend/js/features/history/components/change-list/dropdown/menu-item/compare-dropdown-item.tsx diff --git a/services/web/frontend/js/features/history/components/change-list/dropdown/compare-version-dropdown-content.tsx b/services/web/frontend/js/features/history/components/change-list/dropdown/compare-version-dropdown-content.tsx index 70e7f49c58..ae5e77a5b5 100644 --- a/services/web/frontend/js/features/history/components/change-list/dropdown/compare-version-dropdown-content.tsx +++ b/services/web/frontend/js/features/history/components/change-list/dropdown/compare-version-dropdown-content.tsx @@ -1,10 +1,11 @@ import { LoadedUpdate, Version } from '../../../services/types/update' -import { ReactNode, useCallback } from 'react' +import { useCallback } from 'react' import { ActiveDropdown } from '../../../hooks/use-dropdown-active-item' -import { MenuItem } from 'react-bootstrap' import { useTranslation } from 'react-i18next' -import CompareItems from './menu-item/compare-items' import { updateRangeForUpdate } from '../../../utils/history-details' +import CompareDropDownItem from './menu-item/compare-dropdown-item' +import { useHistoryContext } from '../../../context/history-context' +import MaterialIcon from '../../../../../shared/components/material-icon' type VersionDropdownContentAllHistoryProps = { update: LoadedUpdate @@ -22,25 +23,45 @@ function CompareVersionDropdownContentAllHistory({ }, [closeDropdownForItem, update]) const { t } = useTranslation() - + const { selection } = useHistoryContext() + const { updateRange: selRange } = selection + if (selRange === null) { + return null + } return ( <> - - - - - - + + } + /> + + } + /> ) } @@ -61,47 +82,46 @@ function CompareVersionDropdownContentLabelsList({ }, [closeDropdownForItem, version]) const { t } = useTranslation() + const { selection } = useHistoryContext() + const { updateRange: selRange } = selection + if (selRange === null) { + return null + } return ( <> - - - - - - - - ) -} - -type DropdownOptionProps = { - children: ReactNode -} - -function DropdownOption({ children, ...props }: DropdownOptionProps) { - return ( - <> - {children} + + } + /> + + } + /> ) } diff --git a/services/web/frontend/js/features/history/components/change-list/dropdown/menu-item/compare-dropdown-item.tsx b/services/web/frontend/js/features/history/components/change-list/dropdown/menu-item/compare-dropdown-item.tsx new file mode 100644 index 0000000000..fa907f2abf --- /dev/null +++ b/services/web/frontend/js/features/history/components/change-list/dropdown/menu-item/compare-dropdown-item.tsx @@ -0,0 +1,43 @@ +import Icon from '../../../../../../shared/components/icon' +import { useHistoryContext } from '../../../../context/history-context' +import { UpdateRange } from '../../../../services/types/update' +import { ReactNode } from 'react' +import { Button, MenuItem } from 'react-bootstrap' + +type CompareProps = { + comparisonRange: UpdateRange + icon: ReactNode + text: string + closeDropdown: () => void +} + +function CompareDropDownItem({ + comparisonRange, + text, + closeDropdown, + icon = , + ...props +}: CompareProps) { + const { setSelection } = useHistoryContext() + + const handleCompareVersion = (e: React.MouseEvent ) diff --git a/services/web/test/frontend/features/history/components/change-list.spec.tsx b/services/web/test/frontend/features/history/components/change-list.spec.tsx index 0221b3a4b7..6a387d4463 100644 --- a/services/web/test/frontend/features/history/components/change-list.spec.tsx +++ b/services/web/test/frontend/features/history/components/change-list.spec.tsx @@ -363,9 +363,11 @@ describe('change list', function () { .eq(1) .within(() => { cy.findByRole('button', { name: /compare drop down/i }).click() - cy.findByRole('button', { - name: /compare up to this version/i, - }).click() + cy.findByRole('menu').within(() => { + cy.findByRole('menuitem', { + name: /compare up to this version/i, + }).click() + }) }) cy.findAllByTestId('history-version-details').should($versions => {