Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
60 changes: 60 additions & 0 deletions assets/js/src/core/components/tabs/tab-context-menu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* This source file is available under the terms of the
* Pimcore Open Core License (POCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
* @license Pimcore Open Core License (POCL)
*/

import React from 'react'
import { useTranslation } from 'react-i18next'
import { Menu } from '@Pimcore/components/menu/menu'
import { useCloseContextMenu } from '@Pimcore/components/context-menu-wrapper/context-menu-wrapper'

export interface TabContextMenuProps {
tabKey: string
allKeys: string[]
onClose: (key: string) => void
}

export const TabContextMenu = ({ tabKey, allKeys, onClose }: TabContextMenuProps): React.JSX.Element => {
const { t } = useTranslation()
const closeMenu = useCloseContextMenu()

return (
<Menu
items={ [
{
key: 'close-tab',
label: t('close-tab'),
onClick: () => {
onClose(tabKey)
closeMenu?.()
}
},
{
key: 'close-others',
label: t('close-others'),
onClick: () => {
allKeys.forEach((k) => {
if (k !== tabKey) {
onClose(k)
}
})
closeMenu?.()
}
},
{
key: 'close-all',
label: t('close-all'),
onClick: () => {
allKeys.forEach((k) => { onClose(k) })
closeMenu?.()
}
}
] }
/>
)
}
53 changes: 40 additions & 13 deletions assets/js/src/core/components/tabs/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import { useStyles } from '@Pimcore/components/tabs/tabs.styles'
import cn from 'classnames'
import { isUndefined } from 'lodash'
import { ContextMenuWrapper } from '@Pimcore/components/context-menu-wrapper/context-menu-wrapper'
import { TabContextMenu } from '@Pimcore/components/tabs/tab-context-menu'

export interface ITabsProps extends TabsProps {
onClose?: (any) => void
Expand Down Expand Up @@ -65,19 +67,44 @@
}, [onClose, items])

// Add mouse down handler to each tab item
const enhancedItems = useMemo(() => items?.map(item => ({
...item,
label: (
<button
className={ styles.middleClickButton }
data-tab-key={ item.key }
onMouseDown={ handleMiddleClick }
type="button"
>
{item.label}
</button>
)
})), [items, handleMiddleClick])
const enhancedItems = useMemo(() => {
const allKeys = items?.map(item => item.key) ?? []

return items?.map(item => {
const button = (
<button
className={ styles.middleClickButton }
data-tab-key={ item.key }
onMouseDown={ handleMiddleClick }
type="button"
>
{item.label}
</button>
)

const label = onClose !== undefined

Check warning on line 85 in assets/js/src/core/components/tabs/tabs.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected negated condition.

See more on https://sonarcloud.io/project/issues?id=pimcore_studio-ui-bundle&issues=AZ124oZzbfjn6n6ioF54&open=AZ124oZzbfjn6n6ioF54&pullRequest=3330
? (
<ContextMenuWrapper
calculateAutoHeight={ false }
renderMenu={ () => (
<TabContextMenu
allKeys={ allKeys }
onClose={ onClose }
tabKey={ item.key }
/>
) }
>
{button}
</ContextMenuWrapper>
)
: button

return {
...item,
label
}
})
}, [items, handleMiddleClick, onClose])

return (
<AntdTabs
Expand Down
22 changes: 0 additions & 22 deletions public/build/1bbc463c-5b2c-499b-ac61-f4eeb3381bdf/entrypoints.json

This file was deleted.

33 changes: 0 additions & 33 deletions public/build/1bbc463c-5b2c-499b-ac61-f4eeb3381bdf/manifest.json

This file was deleted.

23 changes: 0 additions & 23 deletions public/build/303cdcf1-58ee-4ae4-8040-42836066132b/entrypoints.json

This file was deleted.

Loading