Skip to content

Commit c794407

Browse files
authored
Added context menu to config tabs (#3330)
* added context menu to config tabs * Apply eslint-fixer changes * Automatic frontend build * added sonar fixes * Apply eslint-fixer changes * Automatic frontend build --------- Co-authored-by: Corepex <16717695+Corepex@users.noreply.github.com>
1 parent c6e2d7b commit c794407

748 files changed

Lines changed: 30092 additions & 13 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* This source file is available under the terms of the
3+
* Pimcore Open Core License (POCL)
4+
* Full copyright and license information is available in
5+
* LICENSE.md which is distributed with this source code.
6+
*
7+
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
8+
* @license Pimcore Open Core License (POCL)
9+
*/
10+
11+
import React from 'react'
12+
import { useTranslation } from 'react-i18next'
13+
import { Menu } from '@Pimcore/components/menu/menu'
14+
import { useCloseContextMenu } from '@Pimcore/components/context-menu-wrapper/context-menu-wrapper'
15+
16+
export interface TabContextMenuProps {
17+
tabKey: string
18+
allKeys: string[]
19+
onClose: (key: string) => void
20+
}
21+
22+
export const TabContextMenu = ({ tabKey, allKeys, onClose }: TabContextMenuProps): React.JSX.Element => {
23+
const { t } = useTranslation()
24+
const closeMenu = useCloseContextMenu()
25+
26+
return (
27+
<Menu
28+
items={ [
29+
{
30+
key: 'close-tab',
31+
label: t('close-tab'),
32+
onClick: () => {
33+
onClose(tabKey)
34+
closeMenu?.()
35+
}
36+
},
37+
{
38+
key: 'close-others',
39+
label: t('close-others'),
40+
onClick: () => {
41+
allKeys.forEach((k) => {
42+
if (k !== tabKey) {
43+
onClose(k)
44+
}
45+
})
46+
closeMenu?.()
47+
}
48+
},
49+
{
50+
key: 'close-all',
51+
label: t('close-all'),
52+
onClick: () => {
53+
allKeys.forEach((k) => { onClose(k) })
54+
closeMenu?.()
55+
}
56+
}
57+
] }
58+
/>
59+
)
60+
}

assets/js/src/core/components/tabs/tabs.tsx

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { Tabs as AntdTabs, type TabsProps } from 'antd'
1313
import { useStyles } from '@Pimcore/components/tabs/tabs.styles'
1414
import cn from 'classnames'
1515
import { isUndefined } from 'lodash'
16+
import { ContextMenuWrapper } from '@Pimcore/components/context-menu-wrapper/context-menu-wrapper'
17+
import { TabContextMenu } from '@Pimcore/components/tabs/tab-context-menu'
1618

1719
export interface ITabsProps extends TabsProps {
1820
onClose?: (any) => void
@@ -65,19 +67,44 @@ const Component = ({ items, className, activeKey, onClose, hasStickyHeader = fal
6567
}, [onClose, items])
6668

6769
// Add mouse down handler to each tab item
68-
const enhancedItems = useMemo(() => items?.map(item => ({
69-
...item,
70-
label: (
71-
<button
72-
className={ styles.middleClickButton }
73-
data-tab-key={ item.key }
74-
onMouseDown={ handleMiddleClick }
75-
type="button"
76-
>
77-
{item.label}
78-
</button>
79-
)
80-
})), [items, handleMiddleClick])
70+
const enhancedItems = useMemo(() => {
71+
const allKeys = items?.map(item => item.key) ?? []
72+
73+
return items?.map(item => {
74+
const button = (
75+
<button
76+
className={ styles.middleClickButton }
77+
data-tab-key={ item.key }
78+
onMouseDown={ handleMiddleClick }
79+
type="button"
80+
>
81+
{item.label}
82+
</button>
83+
)
84+
85+
const label = isUndefined(onClose)
86+
? button
87+
: (
88+
<ContextMenuWrapper
89+
calculateAutoHeight={ false }
90+
renderMenu={ () => (
91+
<TabContextMenu
92+
allKeys={ allKeys }
93+
onClose={ onClose }
94+
tabKey={ item.key }
95+
/>
96+
) }
97+
>
98+
{button}
99+
</ContextMenuWrapper>
100+
)
101+
102+
return {
103+
...item,
104+
label
105+
}
106+
})
107+
}, [items, handleMiddleClick, onClose])
81108

82109
return (
83110
<AntdTabs

public/build/3d1320f8-812a-4013-bc6d-3d8d1eca4cb0/entrypoints.json

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/3d1320f8-812a-4013-bc6d-3d8d1eca4cb0/exposeRemote.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/3d1320f8-812a-4013-bc6d-3d8d1eca4cb0/index.html

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)