Skip to content

Commit

Permalink
feature(explorer): menu item to 'view raw' (yaml and basic edit)
Browse files Browse the repository at this point in the history
  • Loading branch information
soofstad committed May 2, 2024
1 parent af27b61 commit a1a9509
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 10 deletions.
34 changes: 28 additions & 6 deletions packages/dm-core-plugins/src/explorer/ExplorerPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,25 @@ import { Progress } from '@equinor/eds-core-react'
import { useState } from 'react'
import Sidebar from './components/Sidebar'
import NodeRightClickMenu from './components/context-menu/NodeRightClickMenu'
import { default_raw_view_ui_recipe_config } from './constants'

export default () => {
const { treeNodes, loading } = useApplication()
const [selectedType, setSelectedType] = useState<string>()
const [asRawView, setAsRawView] = useState<boolean>(false)
const [selectedEntity, setSelectedEntity] = useState<string>()
const [nodeDimensions, setNodeDimensions] = useState<string | undefined>(
undefined
)
const setRawView = (type: string, id: string) => {
setSelectedEntity(id)
setSelectedType(type)
setAsRawView(true)
}
const { getUiPlugin } = useApplication()
const TabsPlugin = getUiPlugin(
'@development-framework/dm-core-plugins/view_selector/tabs'
)
return (
<div className='flex-layout-container flex-row h-full'>
{loading ? (
Expand All @@ -29,21 +40,32 @@ export default () => {
nodes={treeNodes}
onSelect={(node: TreeNode) => {
if (node.type === EBlueprint.PACKAGE) return
setAsRawView(false)
setSelectedType(node.type)
setSelectedEntity(node.nodeId)
setNodeDimensions(Array.isArray(node.entity) ? '*' : undefined)
}}
NodeWrapper={NodeRightClickMenu}
NodeWrapper={(props) =>
NodeRightClickMenu({ ...props, setRawView: setRawView })
}
/>
</Sidebar>
)}
{selectedType && selectedEntity && (
<div className='flex-layout-container scroll'>
<EntityView
type={selectedType}
idReference={selectedEntity}
dimensions={nodeDimensions}
/>
{asRawView ? (
<TabsPlugin
type={selectedType}
idReference={selectedEntity}
config={default_raw_view_ui_recipe_config}
/>
) : (
<EntityView
type={selectedType}
idReference={selectedEntity}
dimensions={nodeDimensions}
/>
)}
</div>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import { getMenuItems } from './getMenuItems'
export const STANDARD_DIALOG_WIDTH = '100%'
export const STANDARD_DIALOG_HEIGHT = '300px'

const NodeRightClickMenu = (props: TNodeWrapperProps) => {
const { node, children, setNodeOpen } = props
const NodeRightClickMenu = (
props: TNodeWrapperProps & { setRawView: (type: string, id: string) => void }
) => {
const { node, children, setNodeOpen, setRawView } = props
const [dialogId, setDialogId] = useState<EDialog | undefined>()
const [showMenu, setShowMenu] = useState<boolean>(false)
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null)
Expand All @@ -42,7 +44,7 @@ const NodeRightClickMenu = (props: TNodeWrapperProps) => {
placement='bottom-start'
matchAnchorWidth={true}
>
{getMenuItems(node, setDialogId)}
{getMenuItems(node, setDialogId, setRawView)}
</Menu>

{dialogId === EDialog.NewFolder && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { EDialog } from '../../types'
// See https://github.com/equinor/design-system/issues/2659
export function getMenuItems(
node: TreeNode,
setDialogId: (id: EDialog | undefined) => void
setDialogId: (id: EDialog | undefined) => void,
setRawView: (type: string, id: string) => void
): React.ReactElement[] {
const menuItems = []
const getMenuItem = (id: EDialog, text: string) => {
Expand Down Expand Up @@ -54,6 +55,14 @@ export function getMenuItems(

// Everything besides dataSources can be deleted, copied, and edited AccessControl
if (node.type !== 'dataSource') {
menuItems.push(
<Menu.Item
key={'viewRaw'}
onClick={() => setRawView(node.type, node.nodeId)}
>
View raw
</Menu.Item>
)
menuItems.push(getMenuItem(EDialog.Delete, 'Delete'))
menuItems.push(getMenuItem(EDialog.EditACL, 'Change permissions'))
menuItems.push(getMenuItem(EDialog.CopyLink, 'Copy or link'))
Expand Down
35 changes: 35 additions & 0 deletions packages/dm-core-plugins/src/explorer/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export const default_raw_view_ui_recipe_config = {
type: 'dmss://system/Plugins/dm-core-plugins/view_selector/ViewSelectorConfig',
items: [
{
type: 'dmss://system/Plugins/dm-core-plugins/view_selector/ViewSelectorItem',
label: 'Yaml',
viewConfig: {
type: 'dmss://system/SIMOS/InlineRecipeViewConfig',
recipe: {
type: 'dmss://system/SIMOS/UiRecipe',
name: 'YAML',
description: 'YAML representation',
plugin: '@development-framework/dm-core-plugins/yaml',
},
scope: 'self',
eds_icon: 'code',
},
},
{
type: 'dmss://system/Plugins/dm-core-plugins/view_selector/ViewSelectorItem',
label: 'Edit',
viewConfig: {
type: 'dmss://system/SIMOS/InlineRecipeViewConfig',
recipe: {
type: 'dmss://system/SIMOS/UiRecipe',
name: 'Edit',
description: 'Default edit',
plugin: '@development-framework/dm-core-plugins/form',
},
scope: 'self',
eds_icon: 'edit',
},
},
],
}

0 comments on commit a1a9509

Please sign in to comment.