Skip to content

Commit

Permalink
added open context menu item
Browse files Browse the repository at this point in the history
  • Loading branch information
Corepex committed Dec 3, 2024
1 parent afa66e6 commit 6b9ade4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Icon } from '@Pimcore/components/icon/icon'
import { useRename } from '@Pimcore/modules/element/actions/rename/use-rename'
import { useDelete } from '@Pimcore/modules/element/actions/delete/use-delete'
import { useDownload } from '@Pimcore/modules/asset/actions/download/use-download'
import { useOpen } from '@Pimcore/modules/element/actions/open/open'

interface FlexContainerProps {
assets: AssetGetTreeApiResponse
Expand All @@ -36,6 +37,7 @@ const FlexContainer = (props: FlexContainerProps): React.JSX.Element => {
const { renameContextMenuItem } = useRename('asset')
const { deleteContextMenuItem } = useDelete('asset')
const { downloadContextMenuItem } = useDownload()
const { openContextMenuItem } = useOpen('asset')

const cards: ReactNode[] = []
assets.items.forEach((asset) => {
Expand All @@ -48,6 +50,7 @@ const FlexContainer = (props: FlexContainerProps): React.JSX.Element => {
}

const dropdownItems: DropdownProps['menu']['items'] = [
openContextMenuItem(asset),
{
key: 'locate-in-tree',
icon: <Icon value="target" />,
Expand Down
49 changes: 49 additions & 0 deletions assets/js/src/core/modules/element/actions/open/open.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Pimcore
*
* This source file is available under two different licenses:
* - Pimcore Open Core License (POCL)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL
*/

import React from 'react'
import { type ItemType } from '@Pimcore/components/dropdown/dropdown'
import { Icon } from '@Pimcore/components/icon/icon'
import { checkElementPermission } from '@Pimcore/modules/element/permissions/permission-helper'
import { useTranslation } from 'react-i18next'
import { type Element } from '@Pimcore/modules/element/element-helper'
import { useElementHelper } from '@Pimcore/modules/element/hooks/use-element-helper'
import { type ElementType } from 'types/element-type.d'

export interface UseOpenHookReturn {
openContextMenuItem: (node: Element, onFinish?: () => void) => ItemType
}

export const useOpen = (elementType: ElementType): UseOpenHookReturn => {
const { t } = useTranslation()
const { openElement } = useElementHelper()

const openContextMenuItem = (node: Element): ItemType => {
return {
label: t('element.open'),
key: 'open',
icon: <Icon value={ 'type-square' } />,
hidden: !checkElementPermission(node.permissions!, 'rename') || node.isLocked,
onClick: async () => {
await openElement({
id: node.id,
type: elementType
})
}
}
}

return {
openContextMenuItem
}
}
3 changes: 2 additions & 1 deletion translations/studio.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ element.delete: Delete
element.delete.confirmation.title: Delete item
element.delete.confirmation.text: Do you really want to delete this item?
element.delete.confirmation.ok: Delete permanently
element.open: Open
male: Male
female: Female
other: Other
Expand Down Expand Up @@ -363,4 +364,4 @@ processing: Processing
upload: Upload
upload.assets-items-failed-message: Some items could not be uploaded.
quantity-value.converted-units: Converted Units
structured-table.empty.confirm: Are you sure you want to clear all data?
structured-table.empty.confirm: Are you sure you want to clear all data?

0 comments on commit 6b9ade4

Please sign in to comment.