Skip to content
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

Merged
merged 22 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3de778e
add artifacts drawer to code tab
luvkapur Oct 17, 2022
0db70d9
hide top level nodes by default
luvkapur Oct 17, 2022
d50bbf0
clean up
luvkapur Oct 17, 2022
4908f2b
Merge branch 'master' into component-artifacts-drawer
luvkapur Oct 18, 2022
c29b61d
lint fix
luvkapur Oct 18, 2022
10a2bdd
Merge branch 'component-artifacts-drawer' of github.com:teambit/bit i…
luvkapur Oct 18, 2022
df27869
artifacts tree loading
luvkapur Oct 18, 2022
7682d38
make dependency drawer scrollable
luvkapur Oct 19, 2022
b744c79
Merge branch 'master' into component-artifacts-drawer
luvkapur Oct 19, 2022
c223677
make artifact node open in new tab by default
luvkapur Oct 19, 2022
ef2dcbd
Merge branch 'component-artifacts-drawer' of github.com:teambit/bit i…
luvkapur Oct 19, 2022
eb40eb5
remove unused styles
luvkapur Oct 19, 2022
14023a8
clean up
luvkapur Oct 19, 2022
00ea58f
memoize + change line height
luvkapur Oct 19, 2022
7dca1a8
Merge branch 'master' into component-artifacts-drawer
luvkapur Oct 19, 2022
72843ee
Merge branch 'master' into component-artifacts-drawer
luvkapur Oct 19, 2022
0647d81
style fixes
luvkapur Oct 19, 2022
d4a5b31
Merge branch 'component-artifacts-drawer' of github.com:teambit/bit i…
luvkapur Oct 19, 2022
26244ef
Merge branch 'master' into component-artifacts-drawer
luvkapur Oct 19, 2022
57549a0
clean up
luvkapur Oct 19, 2022
53ce921
Merge branch 'component-artifacts-drawer' of github.com:teambit/bit i…
luvkapur Oct 19, 2022
4b85541
Merge branch 'master' into component-artifacts-drawer
luvkapur Oct 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 18 additions & 42 deletions .bitmap
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,6 @@
"mainFile": "index.ts",
"rootDir": "scopes/pipelines/modules/builder-data"
},
"builder-ui": {
"scope": "teambit.pipelines",
"version": "0.0.64",
"mainFile": "index.ts",
"rootDir": "scopes/pipelines/builder-ui"
},
"bundler": {
"scope": "teambit.compilation",
"version": "0.0.879",
Expand Down Expand Up @@ -1098,6 +1092,24 @@
"mainFile": "index.ts",
"rootDir": "scopes/design/ui/alert-card"
},
"ui/artifacts/artifacts-tree": {
"scope": "",
"version": "",
"mainFile": "index.ts",
"rootDir": "scopes/component/ui/component-artifacts/artifacts-tree"
},
"ui/artifacts/models/component-artifacts-model": {
"scope": "",
"version": "",
"mainFile": "index.ts",
"rootDir": "scopes/component/ui/component-artifacts/models/component-artifacts-model"
},
"ui/artifacts/queries/use-component-artifacts": {
"scope": "",
"version": "",
"mainFile": "index.ts",
"rootDir": "scopes/component/ui/component-artifacts/queries/use-component-artifacts"
},
"ui/aspect-box": {
"scope": "teambit.harmony",
"version": "0.0.492",
Expand Down Expand Up @@ -1662,42 +1674,6 @@
"mainFile": "index.ts",
"rootDir": "scopes/design/ui/pill-label"
},
"ui/pipelines/artifacts-panel": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deprecate these components

"scope": "teambit.component",
"version": "0.0.19",
"mainFile": "index.ts",
"rootDir": "scopes/component/ui/pipelines/artifacts-panel"
},
"ui/pipelines/component-pipeline": {
"scope": "teambit.component",
"version": "0.0.19",
"mainFile": "index.ts",
"rootDir": "scopes/component/ui/pipelines/component-pipeline"
},
"ui/pipelines/component-pipeline-context": {
"scope": "teambit.component",
"version": "0.0.8",
"mainFile": "index.ts",
"rootDir": "scopes/component/ui/pipelines/component-pipeline-context"
},
"ui/pipelines/component-pipeline-model": {
"scope": "teambit.component",
"version": "0.0.8",
"mainFile": "index.ts",
"rootDir": "scopes/component/ui/pipelines/component-pipeline-model"
},
"ui/pipelines/component-pipeline-queries": {
"scope": "teambit.component",
"version": "0.0.10",
"mainFile": "index.ts",
"rootDir": "scopes/component/ui/pipelines/component-pipeline-queries"
},
"ui/pipelines/component-pipeline-utils": {
"scope": "teambit.component",
"version": "0.0.7",
"mainFile": "index.ts",
"rootDir": "scopes/component/ui/pipelines/component-pipeline-utils"
},
"ui/preview-placeholder": {
"scope": "teambit.preview",
"version": "0.0.493",
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,6 @@ package-lock.json
!.yarn/plugins
!.yarn/sdks
!.yarn/versions

# component issues
scopes/component/component-issues/dist/
5 changes: 4 additions & 1 deletion scopes/code/ui/code-tab-page/code-tab-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import styles from './code-tab-page.module.scss';

type CodePageProps = {
fileIconSlot?: FileIconSlot;
host: string;
} & HTMLAttributes<HTMLDivElement>;

export function CodePage({ className, fileIconSlot }: CodePageProps) {
export function CodePage({ className, fileIconSlot, host }: CodePageProps) {
const urlParams = useCodeParams();
const component = useContext(ComponentContext);
const { mainFile, fileTree = [], dependencies, devFiles } = useCode(component.id);
Expand Down Expand Up @@ -52,6 +53,8 @@ export function CodePage({ className, fileIconSlot }: CodePageProps) {
</HoverSplitter>
<Pane className={styles.right}>
<CodeTabTree
host={host}
componentId={component.id}
currentFile={currentFile}
dependencies={dependencies}
fileTree={fileTree}
Expand Down
5 changes: 5 additions & 0 deletions scopes/code/ui/code-tab-tree/code-tab-tree.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
}
}

.openDrawer {
flex: 1;
height: 100%;
}

.codeDrawerContent {
overflow-y: auto;
}
Expand Down
18 changes: 16 additions & 2 deletions scopes/code/ui/code-tab-tree/code-tab-tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ import type { DependencyType } from '@teambit/code.ui.queries.get-component-code
import { DependencyTree } from '@teambit/code.ui.dependency-tree';
import { TreeNode } from '@teambit/design.ui.tree';
import { WidgetProps } from '@teambit/ui-foundation.ui.tree.tree-node';
import { ComponentID } from '@teambit/component-id';
import { ArtifactsTree } from '@teambit/component.ui.artifacts.artifacts-tree';

import styles from './code-tab-tree.module.scss';

export type CodeTabTreeProps = {
fileTree: any[];
host: string;
componentId: ComponentID;
dependencies?: DependencyType[];
currentFile?: string;
widgets?: ComponentType<WidgetProps<any>>[];
Expand All @@ -26,6 +30,8 @@ export function CodeTabTree({
widgets,
getHref,
getIcon,
host,
componentId,
}: CodeTabTreeProps) {
const [openDrawerList, onToggleDrawer] = useState(['FILES']);

Expand All @@ -45,7 +51,7 @@ export function CodeTabTree({
onToggle={() => handleDrawerToggle('FILES')}
name="FILES"
contentClass={styles.codeDrawerContent}
className={classNames(styles.codeTabDrawer)}
className={classNames(styles.codeTabDrawer, openDrawerList.includes('FILES') && styles.openDrawer)}
>
<FileTree
files={fileTree || ['']}
Expand All @@ -58,12 +64,20 @@ export function CodeTabTree({
<DrawerUI
isOpen={openDrawerList.includes('DEPENDENCIES')}
onToggle={() => handleDrawerToggle('DEPENDENCIES')}
className={classNames(styles.codeTabDrawer)}
className={classNames(styles.codeTabDrawer, openDrawerList.includes('DEPENDENCIES') && styles.openDrawer)}
contentClass={styles.codeDrawerContent}
name="DEPENDENCIES"
>
<DependencyTree dependenciesArray={dependencies} />
</DrawerUI>
<ArtifactsTree
drawerName="ARTIFACTS"
host={host}
componentId={componentId}
getIcon={getIcon}
drawerOpen={openDrawerList.includes('ARTIFACTS')}
onToggleDrawer={() => handleDrawerToggle('ARTIFACTS')}
/>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
padding-left: 16px;
}
}

.dependencyDrawerContent {
overflow-y: auto;
}
.dependencyLink {
height: 32px;
display: flex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add TODO to move the overflow: auto to DrawerUi so all will get this by default

>
<DependencyList deps={dependencies} />
</DrawerUI>
);
Expand Down
14 changes: 9 additions & 5 deletions scopes/component/code/code.ui.runtime.tsx
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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import Harmony as type in all places

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import Harmony as type in all places you can

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';
Expand All @@ -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[]) {
Expand All @@ -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([
Expand Down
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(() => {});
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
border: none;
border-bottom: 1px solid var(--bit-border-color-lightest, #ededed);
}
}
.openDrawer {
flex: 1;
height: 100%;
}

.artifactsPanelCodeDrawerContent {
overflow-y: auto;
}
Expand All @@ -39,10 +41,10 @@
pointer-events: auto;
}

.artifactsPanelTree {
pointer-events: none;
}

.artifactIconLink {
text-decoration: none;
}

.link {
color: var(--bit-accent-color, #6c5ce7);
}
Loading