forked from guacsec/trustify-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsboms-by-package.tsx
More file actions
156 lines (147 loc) · 4.29 KB
/
sboms-by-package.tsx
File metadata and controls
156 lines (147 loc) · 4.29 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import type React from "react";
import { Link } from "react-router-dom";
import { Toolbar, ToolbarContent, ToolbarItem } from "@patternfly/react-core";
import { Table, Tbody, Td, Th, Thead, Tr } from "@patternfly/react-table";
import { TablePersistenceKeyPrefixes } from "@app/Constants";
import { FilterType } from "@app/components/FilterToolbar";
import { SimplePagination } from "@app/components/SimplePagination";
import {
ConditionalTableBody,
TableHeaderContentWithControls,
} from "@app/components/TableControls";
import {
getHubRequestParams,
useTableControlProps,
useTableControlState,
} from "@app/hooks/table-controls";
import { useSelectionState } from "@app/hooks/useSelectionState";
import { useFetchSbomsByPackageId } from "@app/queries/sboms";
interface SbomsByPackageProps {
purl: string;
}
export const SbomsByPackage: React.FC<SbomsByPackageProps> = ({ purl }) => {
const tableControlState = useTableControlState({
tableName: "sboms",
persistenceKeyPrefix: TablePersistenceKeyPrefixes.sboms_by_package,
columnNames: {
name: "Name",
version: "Version",
supplier: "Supplier",
},
isPaginationEnabled: true,
isSortEnabled: true,
sortableColumns: [],
isFilterEnabled: true,
filterCategories: [
{
categoryKey: "",
title: "Filter text",
placeholderText: "Search",
type: FilterType.search,
},
],
});
const {
result: { data: sboms, total: totalItemCount },
isFetching,
fetchError,
} = useFetchSbomsByPackageId(
purl,
getHubRequestParams({
...tableControlState,
hubSortFieldKeys: {},
}),
);
const tableControls = useTableControlProps({
...tableControlState,
idProperty: "id",
currentPageItems: sboms,
totalItemCount,
isLoading: isFetching,
selectionState: useSelectionState({
items: sboms,
isEqual: (a, b) => a.id === b.id,
}),
});
const {
numRenderedColumns,
currentPageItems,
propHelpers: {
toolbarProps,
paginationToolbarItemProps,
paginationProps,
tableProps,
getThProps,
getTrProps,
getTdProps,
},
} = tableControls;
return (
<>
<Toolbar {...toolbarProps}>
<ToolbarContent>
<ToolbarItem {...paginationToolbarItemProps}>
<SimplePagination
idPrefix="sbom-table"
isTop
paginationProps={paginationProps}
/>
</ToolbarItem>
</ToolbarContent>
</Toolbar>
<Table {...tableProps} aria-label="SBOM table">
<Thead>
<Tr>
<TableHeaderContentWithControls {...tableControls}>
<Th {...getThProps({ columnKey: "name" })} />
<Th {...getThProps({ columnKey: "version" })} />
<Th {...getThProps({ columnKey: "supplier" })} />
</TableHeaderContentWithControls>
</Tr>
</Thead>
<ConditionalTableBody
isLoading={isFetching}
isError={!!fetchError}
isNoData={totalItemCount === 0}
numRenderedColumns={numRenderedColumns}
>
{currentPageItems?.map((item) => {
return (
<Tbody key={item.id}>
<Tr {...getTrProps({ item })}>
<Td
width={35}
modifier="breakWord"
{...getTdProps({ columnKey: "name" })}
>
<Link to={`/sboms/${item.id}`}>{item.name}</Link>
</Td>
<Td
width={15}
modifier="truncate"
{...getTdProps({ columnKey: "version" })}
>
{item.described_by.map((item) => item.version).join(", ")}
</Td>
<Td
width={50}
modifier="truncate"
{...getTdProps({ columnKey: "supplier" })}
>
{item.authors.join(", ")}
</Td>
</Tr>
</Tbody>
);
})}
</ConditionalTableBody>
</Table>
<SimplePagination
idPrefix="sbom-table"
isTop={false}
isCompact
paginationProps={paginationProps}
/>
</>
);
};