forked from tilt-dev/tilt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OverviewResourceSidebar.stories.tsx
135 lines (123 loc) · 3.69 KB
/
OverviewResourceSidebar.stories.tsx
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
import React from "react"
import { MemoryRouter } from "react-router"
import SplitPane from "react-split-pane"
import Features, { FeaturesTestProvider, Flag } from "./feature"
import LogStore, { LogStoreProvider } from "./LogStore"
import OverviewResourceSidebar from "./OverviewResourceSidebar"
import { ResourceGroupsContextProvider } from "./ResourceGroupsContext"
import { ResourceListOptionsProvider } from "./ResourceListOptionsContext"
import { Width } from "./style-helpers"
import {
nResourceView,
nResourceWithLabelsView,
oneResource,
tenResourceView,
tiltfileResource,
twoResourceView,
} from "./testdata"
import { LogLevel, UIResource, UpdateStatus } from "./types"
export default {
title: "New UI/Log View/OverviewResourceSidebar",
decorators: [
(Story: any, context: any) => {
const features = new Features({
[Flag.Labels]: context?.args?.labelsEnabled ?? true,
})
return (
<MemoryRouter initialEntries={["/"]}>
<FeaturesTestProvider value={features}>
<ResourceGroupsContextProvider>
<div style={{ margin: "-1rem", height: "80vh" }}>
<SplitPane
split="vertical"
minSize={Width.sidebarDefault}
defaultSize={Width.sidebarDefault}
>
<Story />
</SplitPane>
</div>
</ResourceGroupsContextProvider>
</FeaturesTestProvider>
</MemoryRouter>
)
},
],
argTypes: {
labelsEnabled: {
name: "Group resources by label enabled",
control: {
type: "boolean",
},
defaultValue: true,
},
disableResourcesEnabled: {
name: "See disabled resources and bulk actions",
control: {
type: "boolean",
},
defaultValue: true,
},
},
}
export const TwoResources = () => (
<OverviewResourceSidebar name={"vigoda"} view={twoResourceView()} />
)
export const TenResources = () => (
<OverviewResourceSidebar name={"vigoda_1"} view={tenResourceView()} />
)
export const TenResourcesWithLabels = () => (
<OverviewResourceSidebar
name={"vigoda_1"}
view={nResourceWithLabelsView(10)}
/>
)
export const OneHundredResources = () => (
<OverviewResourceSidebar name={"vigoda_1"} view={nResourceView(100)} />
)
export function TwoResourcesTwoTests() {
let all: UIResource[] = [
tiltfileResource(),
oneResource({ isBuilding: true }),
oneResource({ name: "snack" }),
oneResource({ name: "beep" }),
oneResource({ name: "boop" }),
]
let view = { uiResources: all, tiltfileKey: "test" }
return <OverviewResourceSidebar name={""} view={view} />
}
export function TestsWithErrors() {
let logStore = new LogStore()
let segments = []
let spans = {} as any
let all: UIResource[] = [tiltfileResource()]
for (let i = 0; i < 8; i++) {
let name = "test_" + i
let test = oneResource({ name })
let spanId = "build-" + i
spans[spanId] = { manifestName: name }
test.status!.buildHistory![0].spanID = spanId
if (i % 2 === 0) {
test.status!.buildHistory![0].error = "egads!"
test.status!.updateStatus = UpdateStatus.Error
segments.push({
spanId,
text: `egads ${i}!\n`,
time: new Date().toString(),
level: LogLevel.ERROR,
anchor: true,
})
}
all.push(test)
}
logStore.append({ spans, segments })
let view = { uiResources: all, tiltfileKey: "test" }
return (
<MemoryRouter>
<LogStoreProvider value={logStore}>
<ResourceListOptionsProvider>
<OverviewResourceSidebar name={""} view={view} />
</ResourceListOptionsProvider>
</LogStoreProvider>
</MemoryRouter>
)
}