Merge pull request #17815 from overleaf/ar-allow-labels-to-be-added-in-label-list

Allow labels to be added from label list

GitOrigin-RevId: 61abbc74aff1901f4adb16575b02148f8dbf99e2
This commit is contained in:
Andrew Rumble 2024-04-10 10:56:17 +01:00 committed by Copybot
parent 8e0e2041a7
commit b053e73e76
6 changed files with 19 additions and 51 deletions

View file

@ -201,7 +201,7 @@ function AllHistoryList() {
update.toV update.toV
) )
const dropdownActive = const dropdownActive =
update === activeDropdownItem.item && update.toV === activeDropdownItem.item &&
activeDropdownItem.whichDropDown === 'moreOptions' activeDropdownItem.whichDropDown === 'moreOptions'
const compareDropdownActive = const compareDropdownActive =
update === activeDropdownItem.item && update === activeDropdownItem.item &&

View file

@ -1,38 +1,38 @@
import AddLabel from './menu-item/add-label' import AddLabel from './menu-item/add-label'
import Download from './menu-item/download' import Download from './menu-item/download'
import { LoadedUpdate } from '../../../services/types/update' import { Version } from '../../../services/types/update'
import { useCallback } from 'react' import { useCallback } from 'react'
import { ActiveDropdown } from '../../../hooks/use-dropdown-active-item' import { ActiveDropdown } from '../../../hooks/use-dropdown-active-item'
type VersionDropdownContentProps = { type VersionDropdownContentProps = {
projectId: string projectId: string
update: LoadedUpdate version: Version
closeDropdownForItem: ActiveDropdown['closeDropdownForItem'] closeDropdownForItem: ActiveDropdown['closeDropdownForItem']
} }
function VersionDropdownContent({ function HistoryDropdownContent({
projectId, projectId,
update, version,
closeDropdownForItem, closeDropdownForItem,
}: VersionDropdownContentProps) { }: VersionDropdownContentProps) {
const closeDropdown = useCallback(() => { const closeDropdown = useCallback(() => {
closeDropdownForItem(update, 'moreOptions') closeDropdownForItem(version, 'moreOptions')
}, [closeDropdownForItem, update]) }, [closeDropdownForItem, version])
return ( return (
<> <>
<AddLabel <AddLabel
projectId={projectId} projectId={projectId}
version={update.toV} version={version}
closeDropdown={closeDropdown} closeDropdown={closeDropdown}
/> />
<Download <Download
projectId={projectId} projectId={projectId}
version={update.toV} version={version}
closeDropdown={closeDropdown} closeDropdown={closeDropdown}
/> />
</> </>
) )
} }
export default VersionDropdownContent export default HistoryDropdownContent

View file

@ -1,32 +0,0 @@
import Download from './menu-item/download'
import { Version } from '../../../services/types/update'
import { ActiveDropdown } from '../../../hooks/use-dropdown-active-item'
import { useCallback } from 'react'
type LabelDropdownContentProps = {
projectId: string
version: Version
closeDropdownForItem: ActiveDropdown['closeDropdownForItem']
}
function LabelDropdownContent({
projectId,
version,
closeDropdownForItem,
}: LabelDropdownContentProps) {
const closeDropdown = useCallback(() => {
closeDropdownForItem(version, 'moreOptions')
}, [closeDropdownForItem, version])
return (
<>
<Download
projectId={projectId}
version={version}
closeDropdown={closeDropdown}
/>
</>
)
}
export default LabelDropdownContent

View file

@ -15,7 +15,7 @@ import {
} from '../../utils/history-details' } from '../../utils/history-details'
import { ActiveDropdown } from '../../hooks/use-dropdown-active-item' import { ActiveDropdown } from '../../hooks/use-dropdown-active-item'
import { HistoryContextValue } from '../../context/types/history-context-value' import { HistoryContextValue } from '../../context/types/history-context-value'
import VersionDropdownContent from './dropdown/version-dropdown-content' import HistoryDropdownContent from './dropdown/history-dropdown-content'
import CompareItems from './dropdown/menu-item/compare-items' import CompareItems from './dropdown/menu-item/compare-items'
import CompareVersionDropdown from './dropdown/compare-version-dropdown' import CompareVersionDropdown from './dropdown/compare-version-dropdown'
import { CompareVersionDropdownContentAllHistory } from './dropdown/compare-version-dropdown-content' import { CompareVersionDropdownContentAllHistory } from './dropdown/compare-version-dropdown-content'
@ -55,7 +55,7 @@ function HistoryVersion({
}: HistoryVersionProps) { }: HistoryVersionProps) {
const orderedLabels = orderBy(update.labels, ['created_at'], ['desc']) const orderedLabels = orderBy(update.labels, ['created_at'], ['desc'])
const closeDropdown = useCallback(() => { const closeDropdown = useCallback(() => {
closeDropdownForItem(update, 'moreOptions') closeDropdownForItem(update.toV, 'moreOptions')
}, [closeDropdownForItem, update]) }, [closeDropdownForItem, update])
const updateRange = updateRangeForUpdate(update) const updateRange = updateRangeForUpdate(update)
@ -102,15 +102,15 @@ function HistoryVersion({
isOpened={dropdownOpen} isOpened={dropdownOpen}
setIsOpened={(isOpened: boolean) => setIsOpened={(isOpened: boolean) =>
setActiveDropdownItem({ setActiveDropdownItem({
item: update, item: update.toV,
isOpened, isOpened,
whichDropDown: 'moreOptions', whichDropDown: 'moreOptions',
}) })
} }
> >
{dropdownActive ? ( {dropdownActive ? (
<VersionDropdownContent <HistoryDropdownContent
update={update} version={update.toV}
projectId={projectId} projectId={projectId}
closeDropdownForItem={closeDropdownForItem} closeDropdownForItem={closeDropdownForItem}
/> />

View file

@ -8,11 +8,11 @@ import { LoadedLabel } from '../../services/types/label'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { ActiveDropdown } from '../../hooks/use-dropdown-active-item' import { ActiveDropdown } from '../../hooks/use-dropdown-active-item'
import { HistoryContextValue } from '../../context/types/history-context-value' import { HistoryContextValue } from '../../context/types/history-context-value'
import LabelDropdownContent from './dropdown/label-dropdown-content'
import CompareItems from './dropdown/menu-item/compare-items' import CompareItems from './dropdown/menu-item/compare-items'
import { ItemSelectionState } from '../../utils/history-details' import { ItemSelectionState } from '../../utils/history-details'
import CompareVersionDropdown from './dropdown/compare-version-dropdown' import CompareVersionDropdown from './dropdown/compare-version-dropdown'
import { CompareVersionDropdownContentLabelsList } from './dropdown/compare-version-dropdown-content' import { CompareVersionDropdownContentLabelsList } from './dropdown/compare-version-dropdown-content'
import HistoryDropdownContent from '@/features/history/components/change-list/dropdown/history-dropdown-content'
type LabelListItemProps = { type LabelListItemProps = {
version: Version version: Version
@ -87,7 +87,7 @@ function LabelListItem({
setIsOpened={setIsOpened} setIsOpened={setIsOpened}
> >
{dropdownActive ? ( {dropdownActive ? (
<LabelDropdownContent <HistoryDropdownContent
version={version} version={version}
projectId={projectId} projectId={projectId}
closeDropdownForItem={closeDropdownForItem} closeDropdownForItem={closeDropdownForItem}

View file

@ -319,7 +319,7 @@ describe('change list', function () {
cy.findByLabelText(/labels/i).click({ force: true }) cy.findByLabelText(/labels/i).click({ force: true })
}) })
it('does not show the dropdown menu item for adding new labels', function () { it('shows the dropdown menu item for adding new labels', function () {
cy.findAllByTestId('history-version-details') cy.findAllByTestId('history-version-details')
.eq(1) .eq(1)
.within(() => { .within(() => {
@ -327,7 +327,7 @@ describe('change list', function () {
cy.findByRole('menu').within(() => { cy.findByRole('menu').within(() => {
cy.findByRole('menuitem', { cy.findByRole('menuitem', {
name: /label this version/i, name: /label this version/i,
}).should('not.exist') }).should('exist')
}) })
}) })
}) })