|
1 | 1 | <script lang="ts"> |
2 | | - import type { Bom } from '$lib/cyclonedx/models'; |
| 2 | + import type { Bom, Component } from '$lib/cyclonedx/models'; |
3 | 3 | import ComponentsTable from '$lib/components/ComponentsTable.svelte'; |
4 | 4 | import ComponentsTreeView from '$lib/components/ComponentsTreeView.svelte'; |
5 | 5 | import { Button, Tab, TabContent, Tabs, Tile } from 'carbon-components-svelte'; |
|
11 | 11 |
|
12 | 12 | let { bom = null }: { bom: Bom | null } = $props(); |
13 | 13 |
|
14 | | - let subjectComponentModalOpened = $state(false); |
15 | | -
|
| 14 | + let selectedComponentForModal: Component | undefined = $state(); |
16 | 15 | let selectedComponentRefInTreeView: string | undefined = $state(); |
17 | 16 |
|
18 | 17 | function searchComponentInTreeView(id: string) { |
19 | 18 | selectedComponentRefInTreeView = id; |
20 | 19 | } |
21 | 20 |
|
| 21 | + function showComponentModal(component?: Component) { |
| 22 | + selectedComponentForModal = component; |
| 23 | + } |
| 24 | +
|
22 | 25 | let treeData: TreeItem[] | undefined = $derived.by(() => { |
23 | 26 | if (bom) { |
24 | 27 | return createTreeDataFromBom(bom); |
|
28 | 31 |
|
29 | 32 | {#if bom} |
30 | 33 | {#if bom.metadata?.component} |
31 | | - <section class="tile"> |
| 34 | + <section class="subject-tile"> |
32 | 35 | <Tile> |
33 | | - <div class="tile__content"> |
| 36 | + <div class="subject-tile__content"> |
34 | 37 | <p> |
35 | 38 | SBOM for <strong>{bom.metadata.component.name}</strong> |
36 | 39 | </p> |
|
39 | 42 | icon={Document} |
40 | 43 | iconDescription="Show details" |
41 | 44 | kind="primary" |
42 | | - on:click={() => (subjectComponentModalOpened = true)} |
| 45 | + on:click={() => showComponentModal(bom.metadata?.component)} |
43 | 46 | /> |
44 | 47 | </div> |
45 | 48 | </Tile> |
46 | 49 | </section> |
47 | | - <ComponentModal component={subjectComponentModalOpened ? bom.metadata.component : undefined} /> |
48 | 50 | {/if} |
49 | 51 | {#if bom.components} |
50 | 52 | <section class="tabs"> |
51 | | - <Tabs> |
| 53 | + <Tabs type="default"> |
52 | 54 | <Tab label="Table" /> |
53 | 55 | <Tab label="Chart" /> |
54 | 56 | <svelte:fragment slot="content"> |
55 | 57 | <TabContent> |
56 | 58 | {#if treeData} |
57 | | - <div class="treeview"> |
| 59 | + <div class="tab__tile"> |
58 | 60 | <ComponentsTreeView |
59 | 61 | nodes={treeData} |
60 | 62 | selectedComponentRef={selectedComponentRefInTreeView} |
61 | 63 | /> |
62 | 64 | </div> |
63 | 65 | {/if} |
64 | | - <div class="table"> |
| 66 | + <div class="tab__tile"> |
65 | 67 | <ComponentsTable |
66 | 68 | components={bom.components} |
67 | 69 | searchComponent={searchComponentInTreeView} |
| 70 | + showComponentDetails={showComponentModal} |
68 | 71 | /> |
69 | 72 | </div> |
70 | 73 | </TabContent> |
71 | 74 | <TabContent> |
72 | 75 | {#if treeData} |
73 | | - <ComponentsTreeChart {bom} nodes={treeData} /> |
| 76 | + <div class="tab__tile"> |
| 77 | + <ComponentsTreeChart {bom} nodes={treeData} /> |
| 78 | + </div> |
74 | 79 | {/if} |
75 | 80 | </TabContent> |
76 | 81 | </svelte:fragment> |
|
79 | 84 | {/if} |
80 | 85 | {/if} |
81 | 86 |
|
| 87 | +<ComponentModal component={selectedComponentForModal} /> |
| 88 | + |
82 | 89 | <style lang="scss"> |
83 | 90 | @use '@carbon/layout'; |
| 91 | + @use '@carbon/styles/scss/theme'; |
84 | 92 |
|
85 | | - .tile__content { |
86 | | - display: flex; |
87 | | - align-items: center; |
88 | | - gap: layout.$spacing-03; |
| 93 | + .subject-tile { |
| 94 | + margin-bottom: layout.$spacing-07; |
| 95 | +
|
| 96 | + &__content { |
| 97 | + display: flex; |
| 98 | + align-items: center; |
| 99 | + gap: layout.$spacing-03; |
| 100 | + } |
89 | 101 | } |
90 | 102 |
|
91 | | - .tile { |
92 | | - margin-bottom: layout.$spacing-07; |
| 103 | + :global .bx--tab-content { |
| 104 | + background-color: theme.$layer-accent; |
| 105 | + padding-left: layout.$spacing-07; |
| 106 | + padding-right: layout.$spacing-07; |
| 107 | + margin-left: -2rem; |
| 108 | + margin-right: -2rem; |
| 109 | + margin-bottom: -2rem; |
| 110 | + } |
| 111 | +
|
| 112 | + .tab__tile { |
| 113 | + background-color: theme.$layer-01; |
| 114 | + padding: layout.$spacing-05; |
93 | 115 | } |
94 | 116 |
|
95 | | - .treeview { |
| 117 | + .tab__tile:first-of-type { |
96 | 118 | margin-bottom: layout.$spacing-07; |
97 | 119 | } |
98 | 120 | </style> |
0 commit comments