-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathBomGroupTable.tsx
More file actions
99 lines (87 loc) · 2.07 KB
/
BomGroupTable.tsx
File metadata and controls
99 lines (87 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import React from 'react';
import yaml from 'yaml';
import {DataTable, HeaderData} from '../../ui-patterns/data-table/DataTable';
import {
BomGroupModel,
BomModel,
bomPath,
bomCloudProvider,
bomName,
moduleDisplayName,
ModuleGroupModel, moduleLatestVersion,
ModuleModel,
moduleProvider,
moduleStatus,
moduleType,
moduleUrl
} from '../../models';
import {ModuleLink} from '../module-link';
const headers: HeaderData<EnhancedBomModel>[] = [{
header: 'Bom',
key: 'name'
}, {
header: 'Path',
key: 'path'
}, {
header: 'Cloud Provider',
key: 'cloudProvider'
}];
interface BomTableProps {
boms: BomGroupModel[];
category: string;
}
interface EnhancedBomModel extends BomModel {
id: string;
}
export class BomGroupTable extends React.Component<BomTableProps, any> {
get boms(): EnhancedBomModel[] {
return this.props.boms.reduce(
(boms: EnhancedBomModel[], bom: BomGroupModel) => {
boms.push(...bom.boms
.map(b => Object.assign(
{},
b,
{
id: bomPath(b),
modules: this.bomModules(b),
name: bomName(b)+" on "+bomCloudProvider(b),
path: bomPath(b),
cloudProvider: bomCloudProvider(b)
}
))
)
return boms;
},
[]
);
}
get title(): string {
return this.props.category
}
async loadYaml(bom: BomModel) {
const result = await fetch(bomPath(bom));
const text = await result.text();
try {
var bomModules = yaml.parse(text);
var moduleArray=[];
for (var key in bomModules.spec.modules) {
var obj = bomModules.spec.modules[key].name;
moduleArray.push(obj)
}
return moduleArray
} catch (error) {
console.log('Error parsing catalog: ', error)
throw error
}
}
async bomModules(bom: BomModel){
const res = await this.loadYaml(bom)
const final_data = await res
return final_data
}
render() {
return (
<DataTable headers={headers} data={this.boms} title=""></DataTable>
)
}
}