Skip to content

Commit 2b5b8d5

Browse files
authored
Added send via notification feature (#3359)
* added `send via notification` feature * Automatic frontend build * updated check * Automatic frontend build --------- Co-authored-by: Corepex <16717695+Corepex@users.noreply.github.com>
1 parent 3d950f2 commit 2b5b8d5

753 files changed

Lines changed: 30129 additions & 20 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.

assets/js/src/core/modules/asset/editor/toolbar/context-menu/context-menu.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import { ButtonGroup } from '@Pimcore/components/button-group/button-group'
2222
import { useContextMenuSlot } from '@Pimcore/modules/app/context-menu-registry/use-context-menu-slot'
2323
import { contextMenuConfig } from '@Pimcore/modules/app/context-menu-registry/context-menu-config'
2424
import { type AssetEditorContextMenuProps } from '@Pimcore/modules/app/context-menu-registry/context-types'
25+
import { useShareViaNotification } from '@Pimcore/modules/notifications/actions/share-via-notification/use-share-via-notification'
26+
import { isNil } from 'lodash'
2527

2628
export const EditorToolbarContextMenu = (): React.JSX.Element => {
2729
const { t } = useTranslation()
@@ -35,7 +37,15 @@ export const EditorToolbarContextMenu = (): React.JSX.Element => {
3537

3638
const items: DropdownMenuProps['items'] = useContextMenuSlot(contextMenuConfig.assetEditorToolbar.name, contextMenuProps)
3739

38-
const visibleItems = items.filter(item => (item !== null && 'hidden' in item) ? item?.hidden === false : false)
40+
const { shareViaNotificationContextMenuItem, shareViaNotificationModal } = useShareViaNotification(
41+
isNil(asset)
42+
? undefined
43+
: { type: 'asset', id: asset.id, fullPath: asset.fullPath ?? undefined }
44+
)
45+
46+
const allItems = [...items, shareViaNotificationContextMenuItem]
47+
48+
const visibleItems = allItems.filter(item => (item !== null && 'hidden' in item) ? item?.hidden === false : false)
3949

4050
const buttonGroupItems: ReactElement[] = []
4151

@@ -58,7 +68,7 @@ export const EditorToolbarContextMenu = (): React.JSX.Element => {
5868
buttonGroupItems.push(
5969
<Dropdown
6070
key="more-button"
61-
menu={ { items } }
71+
menu={ { items: allItems } }
6272
>
6373
<DropdownButton key="dropdown-button">
6474
{t('toolbar.more')}
@@ -68,10 +78,13 @@ export const EditorToolbarContextMenu = (): React.JSX.Element => {
6878
}
6979

7080
return (
71-
<ButtonGroup
72-
items={ buttonGroupItems }
73-
noSpacing
74-
/>
81+
<>
82+
<ButtonGroup
83+
items={ buttonGroupItems }
84+
noSpacing
85+
/>
86+
{shareViaNotificationModal}
87+
</>
7588
)
7689

7790
function hasDataChanged (): boolean {

assets/js/src/core/modules/data-object/editor/toolbar/context-menu/context-menu.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import { useContextMenuSlot } from '@Pimcore/modules/app/context-menu-registry/u
2121
import { contextMenuConfig } from '@Pimcore/modules/app/context-menu-registry/context-menu-config'
2222
import { type DataObjectEditorContextMenuProps } from '@Pimcore/modules/app/context-menu-registry/context-types'
2323
import { ContextMenuActionName } from '@Pimcore/modules/element/actions'
24+
import { useShareViaNotification } from '@Pimcore/modules/notifications/actions/share-via-notification/use-share-via-notification'
25+
import { isNil } from 'lodash'
2426
import { type MenuProps } from 'antd'
2527
import React, { type ReactElement, useContext, useState } from 'react'
2628
import { useTranslation } from 'react-i18next'
@@ -38,7 +40,15 @@ export const EditorToolbarContextMenu = (): React.JSX.Element => {
3840

3941
const items: DropdownMenuProps['items'] = useContextMenuSlot(contextMenuConfig.dataObjectEditorToolbar.name, contextMenuProps)
4042

41-
const visibleItems = items.filter(item => (item !== null && 'hidden' in item) ? item?.hidden === false : false)
43+
const { shareViaNotificationContextMenuItem, shareViaNotificationModal } = useShareViaNotification(
44+
isNil(dataObject)
45+
? undefined
46+
: { type: 'object', id: dataObject.id, fullPath: dataObject.fullPath ?? undefined }
47+
)
48+
49+
const allItems = [...items, shareViaNotificationContextMenuItem]
50+
51+
const visibleItems = allItems.filter(item => (item !== null && 'hidden' in item) ? item?.hidden === false : false)
4252

4353
const handleMenuClick: MenuProps['onClick'] = (e) => {
4454
if (e.key === ContextMenuActionName.unpublish) {
@@ -57,7 +67,7 @@ export const EditorToolbarContextMenu = (): React.JSX.Element => {
5767
<Dropdown
5868
key="dropdown-button"
5969
menu={ {
60-
items,
70+
items: allItems,
6171
onClick: handleMenuClick
6272
} }
6373
open={ isOpen }
@@ -70,9 +80,12 @@ export const EditorToolbarContextMenu = (): React.JSX.Element => {
7080
}
7181

7282
return (
73-
<ButtonGroup
74-
items={ buttonGroupItems }
75-
noSpacing
76-
/>
83+
<>
84+
<ButtonGroup
85+
items={ buttonGroupItems }
86+
noSpacing
87+
/>
88+
{shareViaNotificationModal}
89+
</>
7790
)
7891
}

assets/js/src/core/modules/document/editor/toolbar/context-menu/context-menu.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import { ReloadButton } from './components/reload-button/reload-button'
2222
import { useContextMenuSlot } from '@Pimcore/modules/app/context-menu-registry/use-context-menu-slot'
2323
import { contextMenuConfig } from '@Pimcore/modules/app/context-menu-registry/context-menu-config'
2424
import { type DocumentEditorContextMenuProps } from '@Pimcore/modules/app/context-menu-registry/context-types'
25+
import { useShareViaNotification } from '@Pimcore/modules/notifications/actions/share-via-notification/use-share-via-notification'
26+
import { isNil } from 'lodash'
2527

2628
export const EditorToolbarContextMenu = (): React.JSX.Element => {
2729
const { t } = useTranslation()
@@ -37,7 +39,15 @@ export const EditorToolbarContextMenu = (): React.JSX.Element => {
3739
// Get context menu items from registry
3840
const items: DropdownMenuProps['items'] = useContextMenuSlot(contextMenuConfig.documentEditorToolbar.name, contextMenuProps)
3941

40-
const visibleItems = items.filter(item => (item !== null && 'hidden' in item) ? item?.hidden === false : false)
42+
const { shareViaNotificationContextMenuItem, shareViaNotificationModal } = useShareViaNotification(
43+
isNil(document)
44+
? undefined
45+
: { type: 'document', id: document.id, fullPath: document.fullPath ?? undefined }
46+
)
47+
48+
const allItems = [...items, shareViaNotificationContextMenuItem]
49+
50+
const visibleItems = allItems.filter(item => (item !== null && 'hidden' in item) ? item?.hidden === false : false)
4151

4252
const handleMenuClick: MenuProps['onClick'] = (e) => {
4353
if (e.key === ContextMenuActionName.unpublish) {
@@ -56,7 +66,7 @@ export const EditorToolbarContextMenu = (): React.JSX.Element => {
5666
<Dropdown
5767
key={ 'dropdown-button' }
5868
menu={ {
59-
items,
69+
items: allItems,
6070
onClick: handleMenuClick
6171
} }
6272
open={ isOpen }
@@ -69,9 +79,12 @@ export const EditorToolbarContextMenu = (): React.JSX.Element => {
6979
}
7080

7181
return (
72-
<ButtonGroup
73-
items={ buttonGroupItems }
74-
noSpacing
75-
/>
82+
<>
83+
<ButtonGroup
84+
items={ buttonGroupItems }
85+
noSpacing
86+
/>
87+
{shareViaNotificationModal}
88+
</>
7689
)
7790
}

assets/js/src/core/modules/element/actions/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,6 @@ export enum ContextMenuActionName {
5656
clearImageThumbnails = 'clearImageThumbnails',
5757
clearVideoThumbnails = 'clearVideoThumbnails',
5858
clearPdfThumbnails = 'clearPdfThumbnails',
59+
60+
shareViaNotification = 'shareViaNotification',
5961
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 { type ItemType } from '@Pimcore/components/dropdown/dropdown'
12+
import { Icon } from '@Pimcore/components/icon/icon'
13+
import { type ManyToOneRelationValue } from '@Pimcore/components/many-to-one-relation/many-to-one-relation'
14+
import { ContextMenuActionName } from '@Pimcore/modules/element/actions'
15+
import { isAllowed } from '@Pimcore/modules/auth/permission-helper'
16+
import { UserPermission } from '@Pimcore/modules/auth/enums/user-permission'
17+
import { SendNotificationModal } from '@Pimcore/modules/notifications/send-notification/send-notification-modal'
18+
import React, { useState } from 'react'
19+
import { useTranslation } from 'react-i18next'
20+
21+
export interface UseShareViaNotificationReturn {
22+
shareViaNotificationContextMenuItem: ItemType
23+
shareViaNotificationModal: React.JSX.Element
24+
}
25+
26+
export const useShareViaNotification = (
27+
attachment: ManyToOneRelationValue | undefined
28+
): UseShareViaNotificationReturn => {
29+
const { t } = useTranslation()
30+
const [isOpen, setIsOpen] = useState<boolean>(false)
31+
32+
const shareViaNotificationContextMenuItem: ItemType = {
33+
label: t('element.share-via-notification'),
34+
key: ContextMenuActionName.shareViaNotification,
35+
icon: <Icon value={ 'notes-events' } />,
36+
hidden: !isAllowed(UserPermission.SendNotifications) || attachment === undefined,
37+
onClick: () => {
38+
setIsOpen(true)
39+
}
40+
}
41+
42+
const shareViaNotificationModal = (
43+
<SendNotificationModal
44+
initialAttachment={ attachment }
45+
onClose={ () => { setIsOpen(false) } }
46+
open={ isOpen }
47+
/>
48+
)
49+
50+
return {
51+
shareViaNotificationContextMenuItem,
52+
shareViaNotificationModal
53+
}
54+
}

assets/js/src/core/modules/notifications/send-notification/send-notification-modal.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,30 @@ import { WindowModal } from '@Pimcore/components/modal/window-modal/window-modal
1313
import { FieldWidthProvider } from '@Pimcore/modules/element/dynamic-types/definitions/objects/data-related/providers/field-width/field-width-provider'
1414
import { Button, Flex, Icon, ModalFooter, useMessage } from '@sdk/components'
1515
import { GeneralError, trackError } from '@sdk/modules/app'
16-
import React from 'react'
16+
import React, { useEffect } from 'react'
1717
import { useTranslation } from 'react-i18next'
1818
import { useNotification } from '../hooks/use-send-notification'
1919
import { NotificationForm } from './components/notification-form/notification-form'
20+
import { type ManyToOneRelationValue } from '@Pimcore/components/many-to-one-relation/many-to-one-relation'
2021

2122
interface SendNotificationModalProps {
2223
open: boolean
2324
onClose: () => void
25+
initialAttachment?: ManyToOneRelationValue
2426
}
2527

26-
export const SendNotificationModal = ({ open, ...props }: SendNotificationModalProps): React.JSX.Element => {
28+
export const SendNotificationModal = ({ open, initialAttachment, ...props }: SendNotificationModalProps): React.JSX.Element => {
2729
const { t } = useTranslation()
2830
const [form] = Form.useForm()
2931
const { sendNotification, isLoading } = useNotification()
3032
const { success } = useMessage()
3133

34+
useEffect(() => {
35+
if (open && initialAttachment !== undefined) {
36+
form.setFieldValue('attachment', initialAttachment)
37+
}
38+
}, [open, initialAttachment])
39+
3240
const onClose = (): void => {
3341
form.resetFields()
3442
props.onClose()

public/build/04c19a96-7b50-4b4c-bf7c-0beb68319c12/documentEditorIframe.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.

public/build/04c19a96-7b50-4b4c-bf7c-0beb68319c12/entrypoints.json

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

public/build/04c19a96-7b50-4b4c-bf7c-0beb68319c12/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/04c19a96-7b50-4b4c-bf7c-0beb68319c12/main.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)