Skip to content

Commit

Permalink
feat(explorer): export files and packages
Browse files Browse the repository at this point in the history
  • Loading branch information
soofstad committed May 27, 2024
1 parent 70753eb commit 47ac6ff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EBlueprint, TreeNode } from '@development-framework/dm-core'
import { Menu } from '@equinor/eds-core-react'
import React from 'react'
import { toast } from 'react-toastify'
import { downloadNode } from '../../downloadNode'
import { EDialog } from '../../types'

// This function must return a list of Menu.Item, ie not wrapped in a <></>.
Expand Down Expand Up @@ -63,6 +64,11 @@ export function getMenuItems(
View raw
</Menu.Item>
)
menuItems.push(
<Menu.Item key={'export'} onClick={() => downloadNode(node)}>
Export
</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
16 changes: 16 additions & 0 deletions packages/dm-core-plugins/src/explorer/downloadNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TreeNode } from '@development-framework/dm-core'
import { AxiosResponse } from 'axios'
import { createSyntheticFileDownload } from '../utils'

export function downloadNode(node: TreeNode) {
node.tree.dmssApi
._export({ pathAddress: node.getPath() }, { responseType: 'arraybuffer' })
.then(async (response: AxiosResponse) => {
const url = window.URL.createObjectURL(
new File([response.data], `${node.name}.zip`, {
type: 'application/zip',
})
)
createSyntheticFileDownload(url, `${node.name}.zip`)
})
}

0 comments on commit 47ac6ff

Please sign in to comment.