@teambit/graph 0.0.555 → 0.0.559
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +27 -12
- package/tsconfig.json +1 -1
- package/component-graph/component-graph.ts +0 -105
- package/component-graph/index.ts +0 -2
- package/duplicate-dependency.ts +0 -18
- package/edge-type.ts +0 -5
- package/graph-builder.ts +0 -56
- package/graph.aspect.ts +0 -7
- package/graph.graphql.ts +0 -94
- package/graph.main.runtime.ts +0 -15
- package/graph.provider.ts +0 -14
- package/graph.ui.runtime.tsx +0 -41
- package/index.ts +0 -11
- package/model/dependency/dependency.ts +0 -11
- package/model/dependency/index.ts +0 -1
- package/model/graph-filters/graph-filters.ts +0 -1
- package/model/graph-filters/index.ts +0 -1
- package/object-list-to-graph.ts +0 -54
- package/package-tar/teambit-graph-0.0.555.tgz +0 -0
- package/types/asset.d.ts +0 -29
- package/types/style.d.ts +0 -42
- package/ui/component-node/component-node.tsx +0 -61
- package/ui/component-node/index.ts +0 -3
- package/ui/component-node/variants.ts +0 -5
- package/ui/dependencies-graph/calc-elements.tsx +0 -47
- package/ui/dependencies-graph/calc-layout.tsx +0 -36
- package/ui/dependencies-graph/dep-edge/dep-edge.tsx +0 -28
- package/ui/dependencies-graph/dep-edge/index.ts +0 -1
- package/ui/dependencies-graph/dependencies-graph.tsx +0 -98
- package/ui/dependencies-graph/graph-context.ts +0 -9
- package/ui/dependencies-graph/index.ts +0 -3
- package/ui/dependencies-graph/minimap.ts +0 -15
- package/ui/graph-page/graph-filters.tsx +0 -27
- package/ui/graph-page/graph-page.tsx +0 -54
- package/ui/graph-page/index.ts +0 -1
- package/ui/graph.section.tsx +0 -19
- package/ui/query/edge-model.ts +0 -16
- package/ui/query/get-graph.query.ts +0 -73
- package/ui/query/graph-model.ts +0 -12
- package/ui/query/index.ts +0 -6
- package/ui/query/node-model.ts +0 -16
- package/ui/query/use-graph-query.ts +0 -29
- package/ui/query/use-graph.tsx +0 -12
package/package.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "@teambit/graph",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.559",
|
4
4
|
"homepage": "https://bit.dev/teambit/component/graph",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"componentId": {
|
7
7
|
"scope": "teambit.component",
|
8
8
|
"name": "graph",
|
9
|
-
"version": "0.0.
|
9
|
+
"version": "0.0.559"
|
10
10
|
},
|
11
11
|
"dependencies": {
|
12
12
|
"@teambit/harmony": "0.2.11",
|
@@ -23,17 +23,17 @@
|
|
23
23
|
"@teambit/base-ui.text.muted-text": "1.0.1",
|
24
24
|
"@teambit/evangelist.input.checkbox.label": "1.0.3",
|
25
25
|
"@teambit/documenter.ui.heading": "4.1.1",
|
26
|
-
"@teambit/component": "0.0.
|
27
|
-
"@teambit/graphql": "0.0.
|
28
|
-
"@teambit/cli": "0.0.
|
29
|
-
"@teambit/ui": "0.0.
|
30
|
-
"@teambit/legacy-bit-id": "0.0.
|
31
|
-
"@teambit/component.ui.deprecation-icon": "0.0.
|
26
|
+
"@teambit/component": "0.0.559",
|
27
|
+
"@teambit/graphql": "0.0.559",
|
28
|
+
"@teambit/cli": "0.0.389",
|
29
|
+
"@teambit/ui": "0.0.559",
|
30
|
+
"@teambit/legacy-bit-id": "0.0.378",
|
31
|
+
"@teambit/component.ui.deprecation-icon": "0.0.472",
|
32
32
|
"@teambit/design.ui.styles.ellipsis": "0.0.346",
|
33
|
-
"@teambit/envs.ui.env-icon": "0.0.
|
33
|
+
"@teambit/envs.ui.env-icon": "0.0.466",
|
34
34
|
"@teambit/design.ui.pages.not-found": "0.0.352",
|
35
35
|
"@teambit/design.ui.pages.server-error": "0.0.352",
|
36
|
-
"@teambit/ui-foundation.ui.hooks.use-data-query": "0.0.
|
36
|
+
"@teambit/ui-foundation.ui.hooks.use-data-query": "0.0.467"
|
37
37
|
},
|
38
38
|
"devDependencies": {
|
39
39
|
"@types/react": "^17.0.8",
|
@@ -49,7 +49,7 @@
|
|
49
49
|
},
|
50
50
|
"peerDependencies": {
|
51
51
|
"@apollo/client": "^3.0.0",
|
52
|
-
"@teambit/legacy": "1.0.
|
52
|
+
"@teambit/legacy": "1.0.175",
|
53
53
|
"react-dom": "^16.8.0 || ^17.0.0",
|
54
54
|
"react": "^16.8.0 || ^17.0.0"
|
55
55
|
},
|
@@ -77,12 +77,27 @@
|
|
77
77
|
"react": "-"
|
78
78
|
},
|
79
79
|
"peerDependencies": {
|
80
|
-
"@teambit/legacy": "1.0.
|
80
|
+
"@teambit/legacy": "1.0.175",
|
81
81
|
"react-dom": "^16.8.0 || ^17.0.0",
|
82
82
|
"react": "^16.8.0 || ^17.0.0"
|
83
83
|
}
|
84
84
|
}
|
85
85
|
},
|
86
|
+
"files": [
|
87
|
+
"dist",
|
88
|
+
"!dist/tsconfig.tsbuildinfo",
|
89
|
+
"**/*.md",
|
90
|
+
"**/*.mdx",
|
91
|
+
"**/*.js",
|
92
|
+
"**/*.json",
|
93
|
+
"**/*.sass",
|
94
|
+
"**/*.scss",
|
95
|
+
"**/*.less",
|
96
|
+
"**/*.css",
|
97
|
+
"**/*.css",
|
98
|
+
"**/*.jpeg",
|
99
|
+
"**/*.gif"
|
100
|
+
],
|
86
101
|
"private": false,
|
87
102
|
"engines": {
|
88
103
|
"node": ">=12.22.0"
|
package/tsconfig.json
CHANGED
@@ -15,9 +15,9 @@
|
|
15
15
|
"skipLibCheck": true,
|
16
16
|
"moduleResolution": "node",
|
17
17
|
"esModuleInterop": true,
|
18
|
-
"outDir": "dist",
|
19
18
|
"composite": true,
|
20
19
|
"emitDeclarationOnly": true,
|
20
|
+
"outDir": "dist",
|
21
21
|
"experimentalDecorators": true,
|
22
22
|
"emitDecoratorMetadata": true,
|
23
23
|
"allowSyntheticDefaultImports": true,
|
@@ -1,105 +0,0 @@
|
|
1
|
-
import { Component } from '@teambit/component';
|
2
|
-
import { Graph } from 'cleargraph';
|
3
|
-
|
4
|
-
import { Dependency } from '../model/dependency';
|
5
|
-
import { DuplicateDependency, VersionSubgraph } from '../duplicate-dependency';
|
6
|
-
|
7
|
-
export const DEPENDENCIES_TYPES = ['dependencies', 'devDependencies'];
|
8
|
-
|
9
|
-
type Node = { id: string; node: Component };
|
10
|
-
type Edge = { sourceId: string; targetId: string; edge: Dependency };
|
11
|
-
|
12
|
-
export class ComponentGraph extends Graph<Component, Dependency> {
|
13
|
-
versionMap: Map<string, { allVersionNodes: string[]; latestVersionNode: string }>;
|
14
|
-
constructor(nodes: Node[] = [], edges: Edge[] = []) {
|
15
|
-
super(nodes, edges);
|
16
|
-
this.versionMap = new Map();
|
17
|
-
}
|
18
|
-
|
19
|
-
protected create(nodes: Node[] = [], edges: Edge[] = []): this {
|
20
|
-
return new ComponentGraph(nodes, edges) as this;
|
21
|
-
}
|
22
|
-
|
23
|
-
findDuplicateDependencies(): Map<string, DuplicateDependency> {
|
24
|
-
const duplicateDependencies: Map<string, DuplicateDependency> = new Map();
|
25
|
-
for (const [compFullName, versions] of this.versionMap) {
|
26
|
-
if (versions.allVersionNodes.length > 1) {
|
27
|
-
const versionSubgraphs: VersionSubgraph[] = [];
|
28
|
-
const notLatestVersions = versions.allVersionNodes.filter((version) => version !== versions.latestVersionNode);
|
29
|
-
notLatestVersions.forEach((version) => {
|
30
|
-
const predecessors = this.predecessorsSubgraph(version);
|
31
|
-
const immediatePredecessors = this.predecessors(version).map((predecessor) => predecessor.id);
|
32
|
-
const subGraph = this.buildFromCleargraph(predecessors);
|
33
|
-
const versionSubgraph: VersionSubgraph = {
|
34
|
-
versionId: version,
|
35
|
-
subGraph,
|
36
|
-
// TODO: validate that this is working correctly
|
37
|
-
immediateDependents: immediatePredecessors,
|
38
|
-
};
|
39
|
-
versionSubgraphs.push(versionSubgraph);
|
40
|
-
});
|
41
|
-
if (versionSubgraphs.length > 0) {
|
42
|
-
const duplicateDep = new DuplicateDependency(versions.latestVersionNode, versionSubgraphs);
|
43
|
-
duplicateDependencies.set(compFullName, duplicateDep);
|
44
|
-
}
|
45
|
-
}
|
46
|
-
}
|
47
|
-
return duplicateDependencies;
|
48
|
-
}
|
49
|
-
|
50
|
-
buildFromCleargraph(graph: Graph<Component, Dependency>): ComponentGraph {
|
51
|
-
// TODO: once cleargraph constructor and graph.nodes are consistent we should just use this line
|
52
|
-
// this.create(graph.nodes, graph.edges)
|
53
|
-
|
54
|
-
const newGraph = new ComponentGraph();
|
55
|
-
const newGraphNodes: Node[] = graph.nodes.map((node) => {
|
56
|
-
return {
|
57
|
-
id: node.id,
|
58
|
-
node: node.attr,
|
59
|
-
};
|
60
|
-
});
|
61
|
-
const newGraphEdges: Edge[] = graph.edges.map((edge) => {
|
62
|
-
return {
|
63
|
-
sourceId: edge.sourceId,
|
64
|
-
targetId: edge.targetId,
|
65
|
-
edge: edge.attr,
|
66
|
-
};
|
67
|
-
});
|
68
|
-
newGraph.setNodes(newGraphNodes);
|
69
|
-
newGraph.setEdges(newGraphEdges);
|
70
|
-
|
71
|
-
return newGraph;
|
72
|
-
}
|
73
|
-
|
74
|
-
runtimeOnly(componentIds: string[]) {
|
75
|
-
return this.successorsSubgraph(componentIds, (edge) => edge.attr.type === 'runtime');
|
76
|
-
}
|
77
|
-
|
78
|
-
_calculateVersionMap() {
|
79
|
-
const versionMap: Map<string, { allVersionNodes: string[]; latestVersionNode: string }> = new Map();
|
80
|
-
for (const node of this.nodes) {
|
81
|
-
const comp = node.attr;
|
82
|
-
const compKey = node.id;
|
83
|
-
const compFullName = comp.id._legacy.toStringWithoutVersion();
|
84
|
-
if (!versionMap.has(compFullName)) {
|
85
|
-
versionMap.set(compFullName, {
|
86
|
-
allVersionNodes: [compKey],
|
87
|
-
latestVersionNode: compKey,
|
88
|
-
});
|
89
|
-
} else {
|
90
|
-
const value = versionMap.get(compFullName);
|
91
|
-
if (value) {
|
92
|
-
if (Object.prototype.hasOwnProperty.call(value, 'allVersionNodes')) {
|
93
|
-
value.allVersionNodes.push(compKey);
|
94
|
-
}
|
95
|
-
const currentCompVersion = this.node(compKey)?.attr.id._legacy.getVersion();
|
96
|
-
const latestCompVersion = this.node(value.latestVersionNode)?.attr.id._legacy.getVersion();
|
97
|
-
if (!!currentCompVersion && !!latestCompVersion && currentCompVersion.isLaterThan(latestCompVersion)) {
|
98
|
-
value.latestVersionNode = compKey;
|
99
|
-
}
|
100
|
-
}
|
101
|
-
}
|
102
|
-
}
|
103
|
-
return versionMap;
|
104
|
-
}
|
105
|
-
}
|
package/component-graph/index.ts
DELETED
package/duplicate-dependency.ts
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
// eslint-disable-next-line import/no-cycle
|
2
|
-
import type { ComponentGraph } from './component-graph';
|
3
|
-
|
4
|
-
export class DuplicateDependency {
|
5
|
-
latestVersionId: string;
|
6
|
-
priorVersions: VersionSubgraph[];
|
7
|
-
|
8
|
-
constructor(latestVersionId: string, priorVersions: VersionSubgraph[]) {
|
9
|
-
this.latestVersionId = latestVersionId;
|
10
|
-
this.priorVersions = priorVersions;
|
11
|
-
}
|
12
|
-
}
|
13
|
-
|
14
|
-
export type VersionSubgraph = {
|
15
|
-
versionId: string;
|
16
|
-
subGraph: ComponentGraph;
|
17
|
-
immediateDependents: string[];
|
18
|
-
};
|
package/edge-type.ts
DELETED
package/graph-builder.ts
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
import { ComponentFactory, ComponentID, ComponentMain } from '@teambit/component';
|
2
|
-
import type LegacyGraph from '@teambit/legacy/dist/scope/graph/graph';
|
3
|
-
import { ComponentGraph } from './component-graph';
|
4
|
-
import { Dependency } from './model/dependency';
|
5
|
-
|
6
|
-
type GetGraphOpts = {
|
7
|
-
host?: ComponentFactory;
|
8
|
-
};
|
9
|
-
|
10
|
-
type BuildFromLegacyGraphOpts = {
|
11
|
-
host?: ComponentFactory;
|
12
|
-
};
|
13
|
-
export class GraphBuilder {
|
14
|
-
_graph?: ComponentGraph;
|
15
|
-
_initialized = false;
|
16
|
-
constructor(private componentAspect: ComponentMain) {}
|
17
|
-
|
18
|
-
async getGraph(ids?: ComponentID[], opts: GetGraphOpts = {}): Promise<ComponentGraph> {
|
19
|
-
const componentHost = opts.host || this.componentAspect.getHost();
|
20
|
-
|
21
|
-
const legacyGraph = await componentHost.getLegacyGraph(ids);
|
22
|
-
const graph = await this.buildFromLegacy(legacyGraph, { host: opts.host });
|
23
|
-
this._graph = graph;
|
24
|
-
this._initialized = true;
|
25
|
-
return this._graph;
|
26
|
-
}
|
27
|
-
|
28
|
-
private async buildFromLegacy(
|
29
|
-
legacyGraph: LegacyGraph,
|
30
|
-
opts: BuildFromLegacyGraphOpts = {}
|
31
|
-
): Promise<ComponentGraph> {
|
32
|
-
const newGraph = new ComponentGraph();
|
33
|
-
const componentHost = opts.host || this.componentAspect.getHost();
|
34
|
-
|
35
|
-
const setNodeP = legacyGraph.nodes().map(async (nodeId) => {
|
36
|
-
const componentId = await componentHost.resolveComponentId(nodeId);
|
37
|
-
const component = await componentHost.get(componentId);
|
38
|
-
if (component) {
|
39
|
-
newGraph.setNode(componentId.toString(), component);
|
40
|
-
}
|
41
|
-
});
|
42
|
-
await Promise.all(setNodeP);
|
43
|
-
|
44
|
-
const setEdgePromise = legacyGraph.edges().map(async (edgeId) => {
|
45
|
-
const source = await componentHost.resolveComponentId(edgeId.v);
|
46
|
-
const target = await componentHost.resolveComponentId(edgeId.w);
|
47
|
-
const edgeObj =
|
48
|
-
legacyGraph.edge(edgeId.v, edgeId.w) === 'dependencies' ? new Dependency('runtime') : new Dependency('dev');
|
49
|
-
newGraph.setEdge(source.toString(), target.toString(), edgeObj);
|
50
|
-
});
|
51
|
-
await Promise.all(setEdgePromise);
|
52
|
-
|
53
|
-
newGraph.versionMap = newGraph._calculateVersionMap();
|
54
|
-
return newGraph;
|
55
|
-
}
|
56
|
-
}
|
package/graph.aspect.ts
DELETED
package/graph.graphql.ts
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
import { ComponentMain } from '@teambit/component';
|
2
|
-
import { Schema } from '@teambit/graphql';
|
3
|
-
import gql from 'graphql-tag';
|
4
|
-
|
5
|
-
import { GraphBuilder } from './graph-builder';
|
6
|
-
import { ComponentGraph } from './component-graph';
|
7
|
-
import { GraphFilter } from './model/graph-filters';
|
8
|
-
import { DependencyType } from './model/dependency';
|
9
|
-
import { EdgeType } from './edge-type';
|
10
|
-
|
11
|
-
const textCmp = new Intl.Collator().compare;
|
12
|
-
|
13
|
-
export function graphSchema(graphBuilder: GraphBuilder, componentAspect: ComponentMain): Schema {
|
14
|
-
return {
|
15
|
-
typeDefs: gql`
|
16
|
-
type ComponentGraph {
|
17
|
-
nodes: [ComponentGraphNode]
|
18
|
-
edges: [ComponentGraphEdge]
|
19
|
-
}
|
20
|
-
|
21
|
-
type ComponentGraphNode {
|
22
|
-
id: String
|
23
|
-
component: Component
|
24
|
-
}
|
25
|
-
|
26
|
-
enum DependencyLifecycleType {
|
27
|
-
PEER
|
28
|
-
RUNTIME
|
29
|
-
DEV
|
30
|
-
}
|
31
|
-
|
32
|
-
type ComponentGraphEdge {
|
33
|
-
sourceId: String
|
34
|
-
targetId: String
|
35
|
-
dependencyLifecycleType: DependencyLifecycleType
|
36
|
-
}
|
37
|
-
|
38
|
-
extend type Query {
|
39
|
-
graph(ids: [String], filter: String): ComponentGraph
|
40
|
-
}
|
41
|
-
`,
|
42
|
-
resolvers: {
|
43
|
-
ComponentGraph: {
|
44
|
-
nodes: (graph: ComponentGraph) => {
|
45
|
-
return graph.nodes
|
46
|
-
.map((node) => {
|
47
|
-
return {
|
48
|
-
id: node.id,
|
49
|
-
component: node.attr,
|
50
|
-
};
|
51
|
-
})
|
52
|
-
.sort((a, b) => textCmp(a.id, b.id));
|
53
|
-
},
|
54
|
-
edges: (graph: ComponentGraph) => {
|
55
|
-
return graph.edges
|
56
|
-
.map(
|
57
|
-
(edge) =>
|
58
|
-
({
|
59
|
-
sourceId: edge.sourceId,
|
60
|
-
targetId: edge.targetId,
|
61
|
-
dependencyLifecycleType: getDependencyLifecycleType(edge.attr.type),
|
62
|
-
} as { sourceId: string; targetId: string; dependencyLifecycleType: EdgeType })
|
63
|
-
)
|
64
|
-
.sort((a, b) => textCmp(a.sourceId, b.sourceId))
|
65
|
-
.sort((a, b) => textCmp(a.targetId, b.targetId));
|
66
|
-
},
|
67
|
-
},
|
68
|
-
Query: {
|
69
|
-
graph: async (_parent, { ids, filter }: { ids?: string[]; filter?: GraphFilter }) => {
|
70
|
-
const componentsHost = componentAspect.getHost();
|
71
|
-
const resolvedIds = ids
|
72
|
-
? await componentsHost.resolveMultipleComponentIds(ids)
|
73
|
-
: (await componentsHost.list()).map((x) => x.id);
|
74
|
-
|
75
|
-
const graph = await graphBuilder.getGraph(resolvedIds);
|
76
|
-
if (!graph) return undefined;
|
77
|
-
|
78
|
-
if (filter === 'runtimeOnly') {
|
79
|
-
const runtimeGraph = graph.runtimeOnly(resolvedIds.map((x) => x.toString()));
|
80
|
-
return runtimeGraph;
|
81
|
-
}
|
82
|
-
|
83
|
-
return graph;
|
84
|
-
},
|
85
|
-
},
|
86
|
-
},
|
87
|
-
};
|
88
|
-
}
|
89
|
-
|
90
|
-
function getDependencyLifecycleType(edgeRawData: DependencyType): EdgeType {
|
91
|
-
if (edgeRawData === 'dev') return EdgeType.dev;
|
92
|
-
if (edgeRawData === 'runtime') return EdgeType.runtime;
|
93
|
-
return EdgeType.peer;
|
94
|
-
}
|
package/graph.main.runtime.ts
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
import { MainRuntime } from '@teambit/cli';
|
2
|
-
import GraphqlAspect from '@teambit/graphql';
|
3
|
-
import { ComponentAspect } from '@teambit/component';
|
4
|
-
|
5
|
-
import { GraphAspect } from './graph.aspect';
|
6
|
-
import { provide } from './graph.provider';
|
7
|
-
|
8
|
-
export const GraphMain = {
|
9
|
-
name: 'graph',
|
10
|
-
runtime: MainRuntime,
|
11
|
-
dependencies: [GraphqlAspect, ComponentAspect],
|
12
|
-
provider: provide,
|
13
|
-
};
|
14
|
-
|
15
|
-
GraphAspect.addRuntime(GraphMain);
|
package/graph.provider.ts
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
import { GraphqlMain } from '@teambit/graphql';
|
2
|
-
import { ComponentMain } from '@teambit/component';
|
3
|
-
|
4
|
-
import { GraphBuilder } from './graph-builder';
|
5
|
-
import { graphSchema } from './graph.graphql';
|
6
|
-
|
7
|
-
export type GraphDeps = [GraphqlMain, ComponentMain];
|
8
|
-
|
9
|
-
export async function provide([graphql, componentAspect]: GraphDeps): Promise<GraphBuilder> {
|
10
|
-
const graphBuilder = new GraphBuilder(componentAspect);
|
11
|
-
// TODO: make sure it's working (the host here might be undefined?)
|
12
|
-
graphql.register(graphSchema(graphBuilder, componentAspect));
|
13
|
-
return graphBuilder;
|
14
|
-
}
|
package/graph.ui.runtime.tsx
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
import { ComponentType } from 'react';
|
2
|
-
import { UIRuntime } from '@teambit/ui';
|
3
|
-
import { Slot, SlotRegistry } from '@teambit/harmony';
|
4
|
-
|
5
|
-
import { ComponentAspect, ComponentUI, ComponentModel } from '@teambit/component';
|
6
|
-
import { GraphAspect } from './graph.aspect';
|
7
|
-
import { GraphSection } from './ui/graph.section';
|
8
|
-
|
9
|
-
export interface ComponentWidgetProps extends React.HTMLAttributes<HTMLDivElement> {
|
10
|
-
component: ComponentModel;
|
11
|
-
}
|
12
|
-
export type ComponentWidget = ComponentType<ComponentWidgetProps>;
|
13
|
-
export type ComponentWidgetSlot = SlotRegistry<ComponentWidget>;
|
14
|
-
|
15
|
-
/**
|
16
|
-
* Presents dependencies graph in the component page
|
17
|
-
*/
|
18
|
-
export class GraphUI {
|
19
|
-
/**
|
20
|
-
* adds plugins to component nodes
|
21
|
-
* @param value
|
22
|
-
*/
|
23
|
-
registerComponentWidget(value: ComponentWidget) {
|
24
|
-
this.componentWidgetSlot.register(value);
|
25
|
-
}
|
26
|
-
|
27
|
-
constructor(private componentWidgetSlot: ComponentWidgetSlot) {}
|
28
|
-
static dependencies = [ComponentAspect];
|
29
|
-
static runtime = UIRuntime;
|
30
|
-
static slots = [Slot.withType<ComponentWidget>()];
|
31
|
-
static async provider([componentUI]: [ComponentUI], config, [componentWidgetSlot]: [ComponentWidgetSlot]) {
|
32
|
-
const graphUI = new GraphUI(componentWidgetSlot);
|
33
|
-
const section = new GraphSection(componentWidgetSlot);
|
34
|
-
componentUI.registerNavigation(section.navigationLink, section.order);
|
35
|
-
componentUI.registerRoute(section.route);
|
36
|
-
|
37
|
-
return graphUI;
|
38
|
-
}
|
39
|
-
}
|
40
|
-
|
41
|
-
GraphAspect.addRuntime(GraphUI);
|
package/index.ts
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
export { GraphAspect as default, GraphAspect } from './graph.aspect';
|
2
|
-
|
3
|
-
export { Dependency } from './model/dependency';
|
4
|
-
export { DuplicateDependency, VersionSubgraph } from './duplicate-dependency';
|
5
|
-
export type { ComponentGraph } from './component-graph';
|
6
|
-
export type { GraphBuilder } from './graph-builder';
|
7
|
-
export type { GraphMain } from './graph.main.runtime';
|
8
|
-
export { EdgeType } from './edge-type';
|
9
|
-
export type { GraphUI, ComponentWidget, ComponentWidgetSlot, ComponentWidgetProps } from './graph.ui.runtime';
|
10
|
-
export { useGraph, useGraphQuery, GraphModel, EdgeModel, NodeModel } from './ui/query';
|
11
|
-
export { objectListToGraph, IdGraph } from './object-list-to-graph';
|
@@ -1 +0,0 @@
|
|
1
|
-
export { Dependency, DependencyType } from './dependency';
|
@@ -1 +0,0 @@
|
|
1
|
-
export type GraphFilter = 'runtimeOnly' | undefined;
|
@@ -1 +0,0 @@
|
|
1
|
-
export type { GraphFilter } from './graph-filters';
|
package/object-list-to-graph.ts
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
import { Graph } from 'cleargraph';
|
2
|
-
import { uniqBy } from 'lodash';
|
3
|
-
import { BitId } from '@teambit/legacy-bit-id';
|
4
|
-
import { ObjectList } from '@teambit/legacy/dist/scope/objects/object-list';
|
5
|
-
import { getAllVersionsInfo } from '@teambit/legacy/dist/scope/component-ops/traverse-versions';
|
6
|
-
import { Dependency } from './model/dependency';
|
7
|
-
|
8
|
-
type Node = { id: string; node: BitId };
|
9
|
-
type Edge = { sourceId: string; targetId: string; edge: Dependency };
|
10
|
-
|
11
|
-
export class IdGraph extends Graph<BitId, Dependency> {
|
12
|
-
constructor(nodes: Node[] = [], edges: Edge[] = []) {
|
13
|
-
super(nodes, edges);
|
14
|
-
}
|
15
|
-
}
|
16
|
-
|
17
|
-
export async function objectListToGraph(objectList: ObjectList): Promise<IdGraph> {
|
18
|
-
const bitObjectsList = await objectList.toBitObjects();
|
19
|
-
const components = bitObjectsList.getComponents();
|
20
|
-
const versions = bitObjectsList.getVersions();
|
21
|
-
const nodes: Node[] = [];
|
22
|
-
const edges: Edge[] = [];
|
23
|
-
await Promise.all(
|
24
|
-
components.map(async (component) => {
|
25
|
-
const versionsInfo = await getAllVersionsInfo({
|
26
|
-
modelComponent: component,
|
27
|
-
versionObjects: versions,
|
28
|
-
throws: false,
|
29
|
-
});
|
30
|
-
versionsInfo.forEach((versionInfo) => {
|
31
|
-
const id = component.toBitId().changeVersion(versionInfo.tag || versionInfo.ref.toString());
|
32
|
-
const idStr = id.toString();
|
33
|
-
nodes.push({ id: idStr, node: id });
|
34
|
-
if (!versionInfo.version) {
|
35
|
-
return;
|
36
|
-
}
|
37
|
-
const { dependencies, devDependencies, extensionDependencies } = versionInfo.version.depsIdsGroupedByType;
|
38
|
-
const addDep = (depId: BitId, edge: Dependency) => {
|
39
|
-
const depIdStr = depId.toString();
|
40
|
-
nodes.push({ id: depIdStr, node: depId });
|
41
|
-
edges.push({ sourceId: idStr, targetId: depIdStr, edge });
|
42
|
-
};
|
43
|
-
const runTime = new Dependency('runtime');
|
44
|
-
const dev = new Dependency('dev');
|
45
|
-
dependencies.forEach((depId) => addDep(depId, runTime));
|
46
|
-
[...devDependencies, ...extensionDependencies].forEach((depId) => addDep(depId, dev));
|
47
|
-
});
|
48
|
-
})
|
49
|
-
);
|
50
|
-
const uniqNodes = uniqBy(nodes, 'id');
|
51
|
-
const idGraph = new IdGraph(uniqNodes, edges);
|
52
|
-
|
53
|
-
return idGraph;
|
54
|
-
}
|
Binary file
|
package/types/asset.d.ts
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
declare module '*.png' {
|
2
|
-
const value: any;
|
3
|
-
export = value;
|
4
|
-
}
|
5
|
-
declare module '*.svg' {
|
6
|
-
import type { FunctionComponent, SVGProps } from 'react';
|
7
|
-
|
8
|
-
export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
|
9
|
-
const src: string;
|
10
|
-
export default src;
|
11
|
-
}
|
12
|
-
|
13
|
-
// @TODO Gilad
|
14
|
-
declare module '*.jpg' {
|
15
|
-
const value: any;
|
16
|
-
export = value;
|
17
|
-
}
|
18
|
-
declare module '*.jpeg' {
|
19
|
-
const value: any;
|
20
|
-
export = value;
|
21
|
-
}
|
22
|
-
declare module '*.gif' {
|
23
|
-
const value: any;
|
24
|
-
export = value;
|
25
|
-
}
|
26
|
-
declare module '*.bmp' {
|
27
|
-
const value: any;
|
28
|
-
export = value;
|
29
|
-
}
|
package/types/style.d.ts
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
declare module '*.module.css' {
|
2
|
-
const classes: { readonly [key: string]: string };
|
3
|
-
export default classes;
|
4
|
-
}
|
5
|
-
declare module '*.module.scss' {
|
6
|
-
const classes: { readonly [key: string]: string };
|
7
|
-
export default classes;
|
8
|
-
}
|
9
|
-
declare module '*.module.sass' {
|
10
|
-
const classes: { readonly [key: string]: string };
|
11
|
-
export default classes;
|
12
|
-
}
|
13
|
-
|
14
|
-
declare module '*.module.less' {
|
15
|
-
const classes: { readonly [key: string]: string };
|
16
|
-
export default classes;
|
17
|
-
}
|
18
|
-
|
19
|
-
declare module '*.less' {
|
20
|
-
const classes: { readonly [key: string]: string };
|
21
|
-
export default classes;
|
22
|
-
}
|
23
|
-
|
24
|
-
declare module '*.css' {
|
25
|
-
const classes: { readonly [key: string]: string };
|
26
|
-
export default classes;
|
27
|
-
}
|
28
|
-
|
29
|
-
declare module '*.sass' {
|
30
|
-
const classes: { readonly [key: string]: string };
|
31
|
-
export default classes;
|
32
|
-
}
|
33
|
-
|
34
|
-
declare module '*.scss' {
|
35
|
-
const classes: { readonly [key: string]: string };
|
36
|
-
export default classes;
|
37
|
-
}
|
38
|
-
|
39
|
-
declare module '*.mdx' {
|
40
|
-
const component: any;
|
41
|
-
export default component;
|
42
|
-
}
|
@@ -1,61 +0,0 @@
|
|
1
|
-
import React, { useContext } from 'react';
|
2
|
-
import classnames from 'classnames';
|
3
|
-
import { mutedText } from '@teambit/base-ui.text.muted-text';
|
4
|
-
import { ComponentID } from '@teambit/component';
|
5
|
-
import { DeprecationIcon } from '@teambit/component.ui.deprecation-icon';
|
6
|
-
import { EnvIcon } from '@teambit/envs.ui.env-icon';
|
7
|
-
import { ellipsis } from '@teambit/design.ui.styles.ellipsis';
|
8
|
-
import { Card, CardProps } from '@teambit/base-ui.surfaces.card';
|
9
|
-
import { NodeModel } from '../query/node-model';
|
10
|
-
import { ComponentGraphContext } from '../dependencies-graph/';
|
11
|
-
|
12
|
-
// keep order: styles, then variants
|
13
|
-
import styles from './component-node.module.scss';
|
14
|
-
import variants from './variants.module.scss';
|
15
|
-
|
16
|
-
export interface ComponentNode extends CardProps {
|
17
|
-
node: NodeModel;
|
18
|
-
type: string;
|
19
|
-
}
|
20
|
-
|
21
|
-
export function ComponentNode({ node, type = 'defaultNode', ...rest }: ComponentNode) {
|
22
|
-
const graphContext = useContext(ComponentGraphContext);
|
23
|
-
const { component } = node;
|
24
|
-
const { id } = component;
|
25
|
-
|
26
|
-
return (
|
27
|
-
<Card className={classnames(styles.compNode, variants[type])} elevation="none" {...rest}>
|
28
|
-
<div className={styles.firstRow}>
|
29
|
-
<EnvIcon component={component} className={styles.envIcon} />
|
30
|
-
<Breadcrumbs componentId={id} className={mutedText} />
|
31
|
-
</div>
|
32
|
-
<div className={styles.nameLine}>
|
33
|
-
<span className={classnames(styles.name, ellipsis)}>{id.name}</span>
|
34
|
-
{id.version && <span className={classnames(styles.version, ellipsis)}>{id.version}</span>}
|
35
|
-
|
36
|
-
<div className={styles.buffs}>
|
37
|
-
<DeprecationIcon component={component} />
|
38
|
-
{graphContext &&
|
39
|
-
graphContext.componentWidgets
|
40
|
-
.toArray()
|
41
|
-
.map(([widgetId, Widget]) => <Widget key={widgetId} component={component} />)}
|
42
|
-
</div>
|
43
|
-
</div>
|
44
|
-
</Card>
|
45
|
-
);
|
46
|
-
}
|
47
|
-
|
48
|
-
type BreadcrumbsProps = { componentId: ComponentID } & React.HTMLAttributes<HTMLDivElement>;
|
49
|
-
|
50
|
-
function Breadcrumbs({ componentId, className, ...rest }: BreadcrumbsProps) {
|
51
|
-
const { scope, namespace } = componentId;
|
52
|
-
const showSep = !!scope && !!namespace;
|
53
|
-
|
54
|
-
return (
|
55
|
-
<div {...rest} className={classnames(styles.breadcrumbs, ellipsis, className)}>
|
56
|
-
{scope}
|
57
|
-
{showSep && '/'}
|
58
|
-
{namespace}
|
59
|
-
</div>
|
60
|
-
);
|
61
|
-
}
|
@@ -1,47 +0,0 @@
|
|
1
|
-
import { useMemo } from 'react';
|
2
|
-
import { Node, Edge, ArrowHeadType } from 'react-flow-renderer';
|
3
|
-
import { ComponentID } from '@teambit/component';
|
4
|
-
import { calcLayout } from './calc-layout';
|
5
|
-
import { GraphModel } from '../query';
|
6
|
-
|
7
|
-
import { depTypeToClass, depTypeToLabel } from './dep-edge';
|
8
|
-
|
9
|
-
type ElementsOptions = {
|
10
|
-
rootNode?: ComponentID;
|
11
|
-
};
|
12
|
-
|
13
|
-
/**
|
14
|
-
* generate Nodes and Edges for the ReactFlowRenderer graph renderer
|
15
|
-
*/
|
16
|
-
export function calcElements(graph: GraphModel | undefined, { rootNode }: ElementsOptions) {
|
17
|
-
return useMemo(() => {
|
18
|
-
if (!graph) return [];
|
19
|
-
|
20
|
-
const positions = calcLayout(graph);
|
21
|
-
|
22
|
-
const nodes: Node[] = Array.from(graph.nodes.values()).map((x) => {
|
23
|
-
return {
|
24
|
-
id: x.id,
|
25
|
-
type: 'ComponentNode',
|
26
|
-
data: {
|
27
|
-
node: x,
|
28
|
-
type: rootNode && x.component.id.isEqual(rootNode, { ignoreVersion: true }) ? 'root' : undefined,
|
29
|
-
},
|
30
|
-
position: positions.get(x.id) || { x: 0, y: 0 },
|
31
|
-
};
|
32
|
-
});
|
33
|
-
|
34
|
-
const edges: Edge[] = graph.edges.map((e) => ({
|
35
|
-
id: `_${e.sourceId}__${e.targetId}`,
|
36
|
-
source: e.sourceId,
|
37
|
-
target: e.targetId,
|
38
|
-
label: depTypeToLabel(e.dependencyLifecycleType),
|
39
|
-
labelBgPadding: [4, 4],
|
40
|
-
type: 'smoothstep',
|
41
|
-
className: depTypeToClass(e.dependencyLifecycleType),
|
42
|
-
arrowHeadType: ArrowHeadType.Arrow,
|
43
|
-
}));
|
44
|
-
|
45
|
-
return [...nodes, ...edges];
|
46
|
-
}, [graph]);
|
47
|
-
}
|
@@ -1,36 +0,0 @@
|
|
1
|
-
import dagre, { graphlib } from 'dagre';
|
2
|
-
import { GraphModel } from '../query';
|
3
|
-
|
4
|
-
const NODE_WIDTH = 260;
|
5
|
-
const NODE_HEIGHT = 90;
|
6
|
-
|
7
|
-
const BOTTOM_TO_TOP = 'BT';
|
8
|
-
|
9
|
-
/**
|
10
|
-
* calculate the specific location of each node in the graph
|
11
|
-
*/
|
12
|
-
export function calcLayout(graph: GraphModel) {
|
13
|
-
const g = new graphlib.Graph();
|
14
|
-
g.setGraph({ rankdir: BOTTOM_TO_TOP });
|
15
|
-
g.setDefaultEdgeLabel(() => ({}));
|
16
|
-
|
17
|
-
// make a new instance of { width, height } per node, or dagre will get confused and place all nodes in the same spot
|
18
|
-
graph.nodes.forEach((n) => g.setNode(n.id, { width: NODE_WIDTH, height: NODE_HEIGHT }));
|
19
|
-
graph.edges.forEach((e) => g.setEdge({ v: e.sourceId, w: e.targetId }));
|
20
|
-
|
21
|
-
// position items in graph
|
22
|
-
dagre.layout(g);
|
23
|
-
|
24
|
-
const positionsArr: [string, { x: number; y: number }][] = g.nodes().map((nodeId) => {
|
25
|
-
const node = g.node(nodeId);
|
26
|
-
|
27
|
-
const pos = {
|
28
|
-
x: node.x - node.width / 2,
|
29
|
-
y: node.y - node.height / 2,
|
30
|
-
};
|
31
|
-
|
32
|
-
return [nodeId, pos];
|
33
|
-
});
|
34
|
-
|
35
|
-
return new Map(positionsArr);
|
36
|
-
}
|
@@ -1,28 +0,0 @@
|
|
1
|
-
import { EdgeType } from '@teambit/graph';
|
2
|
-
import edgeStyles from './edge.module.scss';
|
3
|
-
|
4
|
-
export function depTypeToClass(depType: string) {
|
5
|
-
switch (depType) {
|
6
|
-
case 'DEV':
|
7
|
-
return edgeStyles.dev;
|
8
|
-
case 'PEER':
|
9
|
-
return edgeStyles.peer;
|
10
|
-
case 'RUNTIME':
|
11
|
-
return edgeStyles.runtime;
|
12
|
-
default:
|
13
|
-
return undefined;
|
14
|
-
}
|
15
|
-
}
|
16
|
-
|
17
|
-
export function depTypeToLabel(type: EdgeType) {
|
18
|
-
switch (type) {
|
19
|
-
case EdgeType.peer:
|
20
|
-
return 'Peer Dependency';
|
21
|
-
case EdgeType.dev:
|
22
|
-
return 'Development Dependency';
|
23
|
-
case EdgeType.runtime:
|
24
|
-
return 'Dependency';
|
25
|
-
default:
|
26
|
-
return (type as string).toLowerCase();
|
27
|
-
}
|
28
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
export { depTypeToClass, depTypeToLabel } from './dep-edge';
|
@@ -1,98 +0,0 @@
|
|
1
|
-
import React, { useMemo, useCallback, useRef, useEffect } from 'react';
|
2
|
-
import classnames from 'classnames';
|
3
|
-
import ReactFlow, {
|
4
|
-
Controls,
|
5
|
-
Background,
|
6
|
-
MiniMap,
|
7
|
-
OnLoadParams,
|
8
|
-
NodeTypesType,
|
9
|
-
Handle,
|
10
|
-
Position,
|
11
|
-
NodeProps,
|
12
|
-
ReactFlowProps,
|
13
|
-
} from 'react-flow-renderer';
|
14
|
-
import { ComponentID } from '@teambit/component';
|
15
|
-
|
16
|
-
import { ComponentWidgetSlot } from '../../graph.ui.runtime';
|
17
|
-
import { ComponentNode } from '../component-node';
|
18
|
-
import { GraphModel } from '../query';
|
19
|
-
import { calcElements } from './calc-elements';
|
20
|
-
import { calcMinimapColors } from './minimap';
|
21
|
-
import { ComponentGraphContext } from './graph-context';
|
22
|
-
|
23
|
-
import styles from './dependencies-graph.module.scss';
|
24
|
-
|
25
|
-
function ComponentNodeContainer(props: NodeProps) {
|
26
|
-
const { sourcePosition = Position.Top, targetPosition = Position.Bottom, data, id } = props;
|
27
|
-
|
28
|
-
return (
|
29
|
-
<div key={id}>
|
30
|
-
<Handle type="target" position={targetPosition} isConnectable={false} />
|
31
|
-
<Handle type="source" position={sourcePosition} isConnectable={false} />
|
32
|
-
<ComponentNode node={data.node} type={data.type} />
|
33
|
-
</div>
|
34
|
-
);
|
35
|
-
}
|
36
|
-
|
37
|
-
const NodeTypes: NodeTypesType = { ComponentNode: ComponentNodeContainer };
|
38
|
-
|
39
|
-
export type DependenciesGraphProps = {
|
40
|
-
rootNode: ComponentID;
|
41
|
-
graph: GraphModel;
|
42
|
-
componentWidgets: ComponentWidgetSlot;
|
43
|
-
onLoad?: (instance: OnLoadParams) => void;
|
44
|
-
} & Omit<ReactFlowProps, 'elements'>;
|
45
|
-
|
46
|
-
export function DependenciesGraph({
|
47
|
-
graph,
|
48
|
-
rootNode,
|
49
|
-
componentWidgets,
|
50
|
-
className,
|
51
|
-
onLoad,
|
52
|
-
children,
|
53
|
-
...rest
|
54
|
-
}: DependenciesGraphProps) {
|
55
|
-
const graphRef = useRef<OnLoadParams>();
|
56
|
-
const elements = calcElements(graph, { rootNode });
|
57
|
-
const context = useMemo(() => ({ componentWidgets }), [componentWidgets]);
|
58
|
-
|
59
|
-
const handleLoad = useCallback(
|
60
|
-
(instance: OnLoadParams) => {
|
61
|
-
graphRef.current = instance;
|
62
|
-
instance.fitView();
|
63
|
-
onLoad?.(instance);
|
64
|
-
},
|
65
|
-
[onLoad]
|
66
|
-
);
|
67
|
-
|
68
|
-
// clear ref on unmount
|
69
|
-
useEffect(() => () => (graphRef.current = undefined), []);
|
70
|
-
|
71
|
-
useEffect(() => {
|
72
|
-
graphRef.current?.fitView();
|
73
|
-
}, [graph]);
|
74
|
-
|
75
|
-
return (
|
76
|
-
<ComponentGraphContext.Provider value={context}>
|
77
|
-
<ReactFlow
|
78
|
-
draggable={false}
|
79
|
-
nodesDraggable={true}
|
80
|
-
selectNodesOnDrag={false}
|
81
|
-
nodesConnectable={false}
|
82
|
-
zoomOnDoubleClick={false}
|
83
|
-
elementsSelectable={false}
|
84
|
-
maxZoom={1}
|
85
|
-
{...rest}
|
86
|
-
className={classnames(styles.graph, className)}
|
87
|
-
elements={elements}
|
88
|
-
nodeTypes={NodeTypes}
|
89
|
-
onLoad={handleLoad}
|
90
|
-
>
|
91
|
-
<Background />
|
92
|
-
<Controls className={styles.controls} />
|
93
|
-
<MiniMap nodeColor={calcMinimapColors} className={styles.minimap} />
|
94
|
-
{children}
|
95
|
-
</ReactFlow>
|
96
|
-
</ComponentGraphContext.Provider>
|
97
|
-
);
|
98
|
-
}
|
@@ -1,9 +0,0 @@
|
|
1
|
-
import { createContext } from 'react';
|
2
|
-
import { ComponentWidgetSlot } from '../../graph.ui.runtime';
|
3
|
-
|
4
|
-
/** internal context, to pass shared information to all nodes */
|
5
|
-
export type ComponentGraph = {
|
6
|
-
componentWidgets: ComponentWidgetSlot;
|
7
|
-
};
|
8
|
-
|
9
|
-
export const ComponentGraphContext = createContext<ComponentGraph | undefined>(undefined);
|
@@ -1,15 +0,0 @@
|
|
1
|
-
import { Node } from 'react-flow-renderer';
|
2
|
-
import { rootNodeColor, defaultNodeColor, externalNodeColor } from '../component-node';
|
3
|
-
|
4
|
-
export function calcMinimapColors(node: Node) {
|
5
|
-
const type = node.data?.type;
|
6
|
-
|
7
|
-
switch (type) {
|
8
|
-
case 'root':
|
9
|
-
return rootNodeColor;
|
10
|
-
case 'external':
|
11
|
-
return externalNodeColor;
|
12
|
-
default:
|
13
|
-
return defaultNodeColor;
|
14
|
-
}
|
15
|
-
}
|
@@ -1,27 +0,0 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
import { Card, CardProps } from '@teambit/base-ui.surfaces.card';
|
3
|
-
import { CheckboxLabel } from '@teambit/evangelist.input.checkbox.label';
|
4
|
-
|
5
|
-
type GraphFilters = {
|
6
|
-
isFiltered: boolean;
|
7
|
-
onChangeFilter: (isFiltered: boolean) => void;
|
8
|
-
disable?: boolean;
|
9
|
-
} & CardProps;
|
10
|
-
|
11
|
-
export function GraphFilters({ onChangeFilter, isFiltered, disable, ...rest }: GraphFilters) {
|
12
|
-
return (
|
13
|
-
<Card {...rest}>
|
14
|
-
<div>
|
15
|
-
{/* show non-runtime === !isFiltered */}
|
16
|
-
<CheckboxLabel
|
17
|
-
checked={!isFiltered}
|
18
|
-
disabled={disable}
|
19
|
-
onInputChanged={(e) => onChangeFilter(!e.target.checked)}
|
20
|
-
>
|
21
|
-
{' '}
|
22
|
-
show non-runtime
|
23
|
-
</CheckboxLabel>
|
24
|
-
</div>
|
25
|
-
</Card>
|
26
|
-
);
|
27
|
-
}
|
@@ -1,54 +0,0 @@
|
|
1
|
-
import React, { useContext, useState } from 'react';
|
2
|
-
|
3
|
-
import { H2 } from '@teambit/documenter.ui.heading';
|
4
|
-
import { NotFoundPage } from '@teambit/design.ui.pages.not-found';
|
5
|
-
import { ServerErrorPage } from '@teambit/design.ui.pages.server-error';
|
6
|
-
import { ComponentContext } from '@teambit/component';
|
7
|
-
import { FullLoader } from '@teambit/legacy/dist/to-eject/full-loader';
|
8
|
-
|
9
|
-
import { useGraphQuery } from '../query';
|
10
|
-
import { DependenciesGraph } from '../dependencies-graph';
|
11
|
-
import { ComponentWidgetSlot } from '../../graph.ui.runtime';
|
12
|
-
import type { GraphFilter } from '../../model/graph-filters';
|
13
|
-
|
14
|
-
import { GraphFilters } from './graph-filters';
|
15
|
-
|
16
|
-
import styles from './graph-page.module.scss';
|
17
|
-
|
18
|
-
type GraphPageProps = {
|
19
|
-
componentWidgets: ComponentWidgetSlot;
|
20
|
-
};
|
21
|
-
|
22
|
-
export function GraphPage({ componentWidgets }: GraphPageProps) {
|
23
|
-
const component = useContext(ComponentContext);
|
24
|
-
|
25
|
-
const [filter, setFilter] = useState<GraphFilter>('runtimeOnly');
|
26
|
-
const onCheckFilter = (isFiltered: boolean) => {
|
27
|
-
setFilter(isFiltered ? 'runtimeOnly' : undefined);
|
28
|
-
};
|
29
|
-
|
30
|
-
const { graph, error, loading } = useGraphQuery([component.id.toString()], filter);
|
31
|
-
if (error) return error.code === 404 ? <NotFoundPage /> : <ServerErrorPage />;
|
32
|
-
if (!graph) return <FullLoader />;
|
33
|
-
|
34
|
-
const isFiltered = filter === 'runtimeOnly';
|
35
|
-
|
36
|
-
return (
|
37
|
-
<div className={styles.page}>
|
38
|
-
<H2 size="xs">Component Dependencies</H2>
|
39
|
-
<DependenciesGraph
|
40
|
-
componentWidgets={componentWidgets}
|
41
|
-
graph={graph}
|
42
|
-
rootNode={component.id}
|
43
|
-
className={styles.graph}
|
44
|
-
>
|
45
|
-
<GraphFilters
|
46
|
-
className={styles.filters}
|
47
|
-
disable={loading}
|
48
|
-
isFiltered={isFiltered}
|
49
|
-
onChangeFilter={onCheckFilter}
|
50
|
-
/>
|
51
|
-
</DependenciesGraph>
|
52
|
-
</div>
|
53
|
-
);
|
54
|
-
}
|
package/ui/graph-page/index.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export { GraphPage } from './graph-page';
|
package/ui/graph.section.tsx
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
import { Section } from '@teambit/component';
|
2
|
-
import React from 'react';
|
3
|
-
|
4
|
-
import { GraphPage } from './graph-page';
|
5
|
-
import { ComponentWidgetSlot } from '../graph.ui.runtime';
|
6
|
-
|
7
|
-
export class GraphSection implements Section {
|
8
|
-
constructor(private componentWidgetSlot: ComponentWidgetSlot) {}
|
9
|
-
|
10
|
-
route = {
|
11
|
-
path: '~dependencies',
|
12
|
-
children: <GraphPage componentWidgets={this.componentWidgetSlot} />,
|
13
|
-
};
|
14
|
-
navigationLink = {
|
15
|
-
href: '~dependencies',
|
16
|
-
children: 'Dependencies',
|
17
|
-
};
|
18
|
-
order = 40;
|
19
|
-
}
|
package/ui/query/edge-model.ts
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
import { EdgeType } from '@teambit/graph';
|
2
|
-
import { RawEdge } from './get-graph.query';
|
3
|
-
|
4
|
-
export class EdgeModel {
|
5
|
-
sourceId: string;
|
6
|
-
targetId: string;
|
7
|
-
dependencyLifecycleType: EdgeType;
|
8
|
-
|
9
|
-
static from(rawEdge: RawEdge) {
|
10
|
-
const edge = new EdgeModel();
|
11
|
-
edge.sourceId = rawEdge.sourceId;
|
12
|
-
edge.targetId = rawEdge.targetId;
|
13
|
-
edge.dependencyLifecycleType = rawEdge.dependencyLifecycleType;
|
14
|
-
return edge;
|
15
|
-
}
|
16
|
-
}
|
@@ -1,73 +0,0 @@
|
|
1
|
-
import { gql } from '@apollo/client';
|
2
|
-
import { EdgeType } from '@teambit/graph';
|
3
|
-
|
4
|
-
// please update types when updating query, for added safety
|
5
|
-
|
6
|
-
export const GET_GRAPH = gql`
|
7
|
-
query graph($ids: [String], $filter: String) {
|
8
|
-
graph(ids: $ids, filter: $filter) {
|
9
|
-
nodes {
|
10
|
-
id
|
11
|
-
component {
|
12
|
-
id {
|
13
|
-
name
|
14
|
-
version
|
15
|
-
scope
|
16
|
-
}
|
17
|
-
displayName
|
18
|
-
|
19
|
-
deprecation {
|
20
|
-
isDeprecate
|
21
|
-
}
|
22
|
-
|
23
|
-
env {
|
24
|
-
id
|
25
|
-
icon
|
26
|
-
}
|
27
|
-
}
|
28
|
-
}
|
29
|
-
edges {
|
30
|
-
sourceId
|
31
|
-
targetId
|
32
|
-
dependencyLifecycleType
|
33
|
-
}
|
34
|
-
}
|
35
|
-
}
|
36
|
-
`;
|
37
|
-
|
38
|
-
export type RawGraphQuery = {
|
39
|
-
graph: RawGraph;
|
40
|
-
};
|
41
|
-
|
42
|
-
export type RawGraph = {
|
43
|
-
nodes: RawNode[];
|
44
|
-
edges: [];
|
45
|
-
};
|
46
|
-
|
47
|
-
export type RawNode = {
|
48
|
-
id: string;
|
49
|
-
component: {
|
50
|
-
id: {
|
51
|
-
name: string;
|
52
|
-
scope: string;
|
53
|
-
version: string;
|
54
|
-
};
|
55
|
-
|
56
|
-
displayName: string;
|
57
|
-
|
58
|
-
deprecation: {
|
59
|
-
isDeprecate: boolean;
|
60
|
-
};
|
61
|
-
|
62
|
-
env: {
|
63
|
-
id: string;
|
64
|
-
icon: string;
|
65
|
-
};
|
66
|
-
};
|
67
|
-
};
|
68
|
-
|
69
|
-
export type RawEdge = {
|
70
|
-
sourceId: string;
|
71
|
-
targetId: string;
|
72
|
-
dependencyLifecycleType: EdgeType;
|
73
|
-
};
|
package/ui/query/graph-model.ts
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
import { RawGraph } from './get-graph.query';
|
2
|
-
import { NodeModel } from './node-model';
|
3
|
-
import { EdgeModel } from './edge-model';
|
4
|
-
|
5
|
-
export class GraphModel {
|
6
|
-
constructor(public nodes: NodeModel[], public edges: EdgeModel[]) {}
|
7
|
-
static from(rawGraph: RawGraph) {
|
8
|
-
const nodes = rawGraph.nodes.map(NodeModel.from);
|
9
|
-
const edges = rawGraph.edges.map(EdgeModel.from);
|
10
|
-
return new GraphModel(nodes, edges);
|
11
|
-
}
|
12
|
-
}
|
package/ui/query/index.ts
DELETED
package/ui/query/node-model.ts
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
import { ComponentModel } from '@teambit/component';
|
2
|
-
import { RawNode } from './get-graph.query';
|
3
|
-
|
4
|
-
export class NodeModel {
|
5
|
-
id: string;
|
6
|
-
component: ComponentModel;
|
7
|
-
|
8
|
-
static from(rawNode: RawNode) {
|
9
|
-
const node = new NodeModel();
|
10
|
-
node.id = rawNode.id;
|
11
|
-
// @TODO - component model should not expect all fields to have values
|
12
|
-
// @ts-ignore
|
13
|
-
node.component = ComponentModel.from(rawNode.component);
|
14
|
-
return node;
|
15
|
-
}
|
16
|
-
}
|
@@ -1,29 +0,0 @@
|
|
1
|
-
import { useMemo } from 'react';
|
2
|
-
import { useDataQuery } from '@teambit/ui-foundation.ui.hooks.use-data-query';
|
3
|
-
import { GraphQlError } from '@teambit/graphql';
|
4
|
-
import { GET_GRAPH, RawGraphQuery } from './get-graph.query';
|
5
|
-
import { GraphModel } from './graph-model';
|
6
|
-
|
7
|
-
type QueryVariables = {
|
8
|
-
ids: string[];
|
9
|
-
filter?: string;
|
10
|
-
};
|
11
|
-
|
12
|
-
/** provides dependencies graph data from graphQL */
|
13
|
-
export function useGraphQuery(componentId: string[], filter?: string) {
|
14
|
-
const { data, error, loading } = useDataQuery<RawGraphQuery, QueryVariables>(GET_GRAPH, {
|
15
|
-
variables: { ids: componentId, filter },
|
16
|
-
});
|
17
|
-
|
18
|
-
const rawGraph = data?.graph;
|
19
|
-
const clientError = !rawGraph && !loading ? new GraphQlError(404) : undefined;
|
20
|
-
const serverError = error ? new GraphQlError(500, error.message) : undefined;
|
21
|
-
|
22
|
-
return useMemo(() => {
|
23
|
-
return {
|
24
|
-
graph: rawGraph ? GraphModel.from(rawGraph) : undefined,
|
25
|
-
error: serverError || clientError,
|
26
|
-
loading,
|
27
|
-
};
|
28
|
-
}, [rawGraph, error]);
|
29
|
-
}
|
package/ui/query/use-graph.tsx
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
import { useRouteMatch } from 'react-router-dom';
|
2
|
-
|
3
|
-
import { useGraphQuery } from './use-graph-query';
|
4
|
-
|
5
|
-
export function useGraph() {
|
6
|
-
const {
|
7
|
-
// @ts-ignore
|
8
|
-
params: { componentId },
|
9
|
-
} = useRouteMatch();
|
10
|
-
|
11
|
-
return useGraphQuery([componentId]);
|
12
|
-
}
|