-
Notifications
You must be signed in to change notification settings - Fork 940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add artifacts drawer to code tab #6550
Changes from all commits
3de778e
0db70d9
d50bbf0
4908f2b
c29b61d
10a2bdd
df27869
7682d38
b744c79
c223677
ef2dcbd
eb40eb5
14023a8
00ea58f
7dca1a8
72843ee
0647d81
d4a5b31
26244ef
57549a0
53ce921
4b85541
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,11 @@ | |
} | ||
} | ||
|
||
.openDrawer { | ||
flex: 1; | ||
height: 100%; | ||
} | ||
|
||
.codeDrawerContent { | ||
overflow-y: auto; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,13 @@ export type DependencyDrawerProps = { | |
export function DependencyDrawer({ name, isOpen, onToggle, dependencies }: DependencyDrawerProps) { | ||
if (!dependencies || dependencies.length === 0) return null; | ||
return ( | ||
<DrawerUI isOpen={isOpen} onToggle={onToggle} name={name} className={styles.dependencyDrawer}> | ||
<DrawerUI | ||
isOpen={isOpen} | ||
onToggle={onToggle} | ||
name={name} | ||
className={styles.dependencyDrawer} | ||
contentClass={styles.dependencyDrawerContent} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add TODO to move the |
||
> | ||
<DependencyList deps={dependencies} /> | ||
</DrawerUI> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { ComponentAspect, ComponentUI } from '@teambit/component'; | ||
import { UIRuntime } from '@teambit/ui'; | ||
import React from 'react'; | ||
import { SlotRegistry, Slot } from '@teambit/harmony'; | ||
import { Harmony, SlotRegistry, Slot } from '@teambit/harmony'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. import There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. import |
||
import type { FileIconMatch } from '@teambit/code.ui.utils.get-file-icon'; | ||
import { staticStorageUrl } from '@teambit/base-ui.constants.storage'; | ||
import { CodePage } from '@teambit/code.ui.code-tab-page'; | ||
|
@@ -23,11 +23,12 @@ export class CodeUI { | |
/** | ||
* register an icon for a specific file type. pass icon and a match method/regexp | ||
*/ | ||
private host: string, | ||
private fileIconSlot?: FileIconSlot | ||
) {} | ||
|
||
getCodePage = () => { | ||
return <CodePage fileIconSlot={this.fileIconSlot} />; | ||
return <CodePage fileIconSlot={this.fileIconSlot} host={this.host} />; | ||
}; | ||
|
||
registerEnvFileIcon(icons: FileIconMatch[]) { | ||
|
@@ -42,10 +43,13 @@ export class CodeUI { | |
|
||
static async provider( | ||
[component, componentCompare]: [ComponentUI, ComponentCompareUI], | ||
config, | ||
[fileIconSlot]: [FileIconSlot] | ||
_, | ||
[fileIconSlot]: [FileIconSlot], | ||
harmony: Harmony | ||
) { | ||
const ui = new CodeUI(fileIconSlot); | ||
const { config } = harmony; | ||
const host = String(config.get('teambit.harmony/bit')); | ||
const ui = new CodeUI(host, fileIconSlot); | ||
const section = new CodeSection(ui); | ||
// overrides the default tsx react icon with the typescript icon | ||
ui.registerEnvFileIcon([ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { ArtifactFile } from '@teambit/component.ui.artifacts.models.component-artifacts-model'; | ||
|
||
export const fileNodeClicked = | ||
(files: (ArtifactFile & { id: string })[], opts: 'download' | 'new tab') => (e, node) => { | ||
const { id } = node; | ||
const artifactFile = files.find((file) => file.id === id); | ||
|
||
if (artifactFile?.downloadUrl) { | ||
fetch(artifactFile.downloadUrl, { method: 'GET' }) | ||
.then((res) => res.blob()) | ||
.then((blob) => { | ||
// create blob link to download | ||
const url = window.URL.createObjectURL(new Blob([blob])); | ||
const link = document.createElement('a'); | ||
link.href = url; | ||
if (opts === 'download') link.setAttribute('download', artifactFile.path); | ||
if (opts === 'new tab') link.setAttribute('target', '_blank'); | ||
// append to html page | ||
document.body.appendChild(link); | ||
// force download | ||
link.click(); | ||
// clean up and remove the link | ||
link.parentNode?.removeChild(link); | ||
}) | ||
.catch(() => {}); | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deprecate these components