@appscode/design-system 1.0.43-alpha.173 → 1.0.43-alpha.174

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appscode/design-system",
3
- "version": "1.0.43-alpha.173",
3
+ "version": "1.0.43-alpha.174",
4
4
  "description": "A design system for Appscode websites and dashboards made using Bulma",
5
5
  "main": "main.scss",
6
6
  "scripts": {
@@ -0,0 +1,92 @@
1
+ <template>
2
+ <span href="" class="task-item" :class="[statusClass]">
3
+ <i class="fa" :class="`fa-${statusIcon}`" />
4
+ {{ title }}
5
+ </span>
6
+ </template>
7
+
8
+ <script setup lang="ts">
9
+ import { computed, toRefs } from 'vue'
10
+ import { TaskStatus } from '../../typings/long-running-tasks'
11
+
12
+ const props = withDefaults(
13
+ defineProps<{ title: string; status: TaskStatus }>(),
14
+ {
15
+ title: '',
16
+ status: 'Pending',
17
+ }
18
+ )
19
+
20
+ const { status } = toRefs(props)
21
+ const statusClass = computed(() => `is-${status.value.toLowerCase()}`)
22
+ const statusIcon = computed(() => {
23
+ if (status.value === 'Running' || status.value === 'Started')
24
+ return 'circle-o-notch'
25
+ else if (status.value === 'Success') return 'check-circle'
26
+ else if (status.value === 'Failed') return 'times-circle'
27
+ else return 'spinner'
28
+ })
29
+ </script>
30
+
31
+ <style scoped lang="scss">
32
+ .task-item {
33
+ font-size: 14px;
34
+ display: block;
35
+ padding: 5px;
36
+ border-radius: 5px;
37
+ transition: all 0.3s ease-in-out;
38
+ &:hover {
39
+ background-color: var(--ac-white-light);
40
+ cursor: pointer;
41
+ }
42
+ &.is-active {
43
+ background-color: var(--ac-white-light);
44
+ }
45
+ &.is-pending {
46
+ color: var(--ac-gray-light);
47
+ i {
48
+ visibility: hidden;
49
+ }
50
+ &:hover {
51
+ background-color: transparent;
52
+ cursor: not-allowed;
53
+ }
54
+ }
55
+ &.is-aborted {
56
+ color: var(--ac-gray-light);
57
+ &:hover {
58
+ background-color: transparent;
59
+ cursor: not-allowed;
60
+ }
61
+ }
62
+ &.is-running,
63
+ &.is-started {
64
+ i {
65
+ color: var(--ac-primary);
66
+ animation-name: spin;
67
+ animation-duration: 1000ms;
68
+ animation-iteration-count: infinite;
69
+ animation-timing-function: linear;
70
+ }
71
+
72
+ @keyframes spin {
73
+ from {
74
+ transform: rotate(0deg);
75
+ }
76
+ to {
77
+ transform: rotate(360deg);
78
+ }
79
+ }
80
+ }
81
+ &.is-success {
82
+ i {
83
+ color: #158748;
84
+ }
85
+ }
86
+ &.is-failed {
87
+ i {
88
+ color: #ff3729;
89
+ }
90
+ }
91
+ }
92
+ </style>
@@ -0,0 +1,334 @@
1
+ <template>
2
+ <modal
3
+ :open="open"
4
+ :title="title"
5
+ :is-close-option-disabled="!enableModalClose"
6
+ :ignore-outside-click="true"
7
+ :hide-action-footer="!enableModalFooter"
8
+ @closemodal="$emit('close')"
9
+ >
10
+ <div v-if="connectionError" class="task-simple-wrapper">
11
+ <div class="task-cogs-icon">
12
+ <i class="fa fa-times-circle has-text-danger fa-5x fa-fw"></i>
13
+ </div>
14
+ <div class="task-log">
15
+ <span class="task-title">
16
+ <i class="fa fa-times-circle mr-5 is-failed" />
17
+ <span> Connection error </span>
18
+ </span>
19
+ <span>{{ connectionError }}</span>
20
+ </div>
21
+ </div>
22
+ <div
23
+ v-else-if="isNatsConnectionLoading || !activeStep"
24
+ class="is-justify-content-center"
25
+ :class="simple ? 'task-simple-wrapper' : 'task-complex-wrapper'"
26
+ >
27
+ <preloader
28
+ :style="{ height: '100%' }"
29
+ class="is-fullheight"
30
+ message="Connecting..."
31
+ />
32
+ </div>
33
+ <div v-else-if="simple" class="task-simple-wrapper">
34
+ <div class="task-cogs-icon">
35
+ <i class="fa fa-cog fa-spin fa-5x fa-fw"></i>
36
+ <span class="is-flex is-flex-direction-column">
37
+ <i class="fa fa-cog fa-spin fa-3x fa-bw"></i>
38
+ <i class="fa fa-cog fa-spin fa-3x fa-bw"></i>
39
+ </span>
40
+ </div>
41
+ <div class="task-log">
42
+ <span class="task-title">
43
+ <i
44
+ v-if="activeTask?.status === 'Running'"
45
+ class="fa fa-circle-o-notch fa-spin mr-5"
46
+ />
47
+ <i
48
+ v-else-if="activeTask?.status === 'Success'"
49
+ class="fa fa-check-circle mr-5 is-success"
50
+ />
51
+ <i
52
+ v-else-if="activeTask?.status === 'Failed'"
53
+ class="fa fa-times-circle mr-5 is-failed"
54
+ />
55
+ <span>
56
+ {{ activeTask?.step }}
57
+ </span>
58
+ </span>
59
+ <span>{{ activeTask?.logs[activeTask?.logs.length - 1] }}</span>
60
+ </div>
61
+ </div>
62
+ <div v-else class="task-complex-wrapper">
63
+ <ul class="task-list">
64
+ <li v-for="task in tasks" :key="task.step">
65
+ <long-running-task-item
66
+ :title="task.step"
67
+ :status="task.status"
68
+ :class="{ 'is-active': activeStep === task.step }"
69
+ />
70
+ </li>
71
+ </ul>
72
+ <long-running-task-terminal
73
+ :key="activeTask?.step"
74
+ :logs="activeTask?.logs"
75
+ class="task-log"
76
+ />
77
+ </div>
78
+
79
+ <template #modal-footer-controls>
80
+ <ac-button
81
+ title="Close"
82
+ modifier-classes="is-outlined"
83
+ @click.stop="$emit('close')"
84
+ />
85
+ <ac-button
86
+ v-if="showSuccessButton"
87
+ :title="successCtx?.btnTitle"
88
+ :is-loader-active="successCtx?.isLoaderActive"
89
+ modifier-classes="is-primary"
90
+ icon-class="step-forward"
91
+ @click="successCtx.onSuccessBtnClick"
92
+ />
93
+ <ac-button
94
+ v-if="showReportButton"
95
+ title="Report Issue"
96
+ modifier-classes="is-danger"
97
+ icon-class="external-link"
98
+ @click="onReportIssueClick"
99
+ />
100
+ </template>
101
+ </modal>
102
+ </template>
103
+ <script setup lang="ts">
104
+ import {
105
+ computed,
106
+ getCurrentInstance,
107
+ onBeforeUnmount,
108
+ Ref,
109
+ toRefs,
110
+ watch,
111
+ watchEffect,
112
+ } from "vue";
113
+ import { defineAsyncComponent, ref } from "vue";
114
+ import { Task, TaskLog } from "../../typings/long-running-tasks";
115
+ import { Subscription, StringCodec } from "nats.ws";
116
+
117
+ const Modal = defineAsyncComponent(() => import("../modal/Modal.vue"));
118
+ const LongRunningTaskItem = defineAsyncComponent(
119
+ () => import("../long-running-tasks/LongRunningTaskItem.vue")
120
+ );
121
+ const LongRunningTaskTerminal = defineAsyncComponent(
122
+ () => import("../terminal/LongRunningTaskTerminal.vue")
123
+ );
124
+ const Preloader = defineAsyncComponent(
125
+ () => import("../../v2/preloader/Preloader.vue")
126
+ );
127
+ const AcButton = defineAsyncComponent(() => import("../button/Button.vue"));
128
+
129
+ defineEmits(["close"]);
130
+
131
+ const props = withDefaults(
132
+ defineProps<{
133
+ open: boolean;
134
+ title: string;
135
+ simple: boolean;
136
+ natsSubject: string;
137
+ isNatsConnectionLoading: boolean;
138
+ errorCtx?: {
139
+ connectionError: string;
140
+ onError: (msg: string) => void;
141
+ };
142
+ successCtx?: {
143
+ btnTitle?: string;
144
+ isLoaderActive?: boolean;
145
+ onSuccess: () => void;
146
+ onSuccessBtnClick?: () => void;
147
+ };
148
+ }>(),
149
+ {
150
+ open: true,
151
+ simple: true,
152
+ title: "Sample title",
153
+ natsSubject: "",
154
+ isNatsConnectionLoading: false,
155
+ errorCtx: undefined,
156
+ successCtx: undefined,
157
+ }
158
+ );
159
+
160
+ const { natsSubject, open, errorCtx, successCtx } = toRefs(props);
161
+ const connectionError = computed(() => errorCtx.value?.connectionError);
162
+ const currentInstance = getCurrentInstance();
163
+ const $nats = currentInstance?.appContext.config.globalProperties.$nc;
164
+ let subscription: Subscription;
165
+
166
+ const tasks: Ref<Array<Task>> = ref([]);
167
+ const activeStep: Ref<string> = ref("");
168
+ const activeTask = computed(() => {
169
+ const task = tasks.value.find((task) => task.step === activeStep.value);
170
+ return task;
171
+ });
172
+
173
+ function handleTaskLog(log: TaskLog) {
174
+ if (log.step) {
175
+ // log has a step
176
+ // so add new task
177
+ tasks.value.push({
178
+ ...log,
179
+ logs: [(log.msg && log.msg) || ""],
180
+ });
181
+ activeStep.value = log.step;
182
+ } else {
183
+ const task = tasks.value.find((task) => task.step === activeStep.value);
184
+ if (task) {
185
+ task.status = log.status;
186
+ if (log.status === "Failed") {
187
+ task.logs.push(log.error || "");
188
+ } else {
189
+ task.logs.push(log.msg || "");
190
+ }
191
+ }
192
+ }
193
+ }
194
+
195
+ async function subscribeToChannel(channelId: string) {
196
+ subscription = $nats?.subscribe(channelId);
197
+
198
+ console.log("Started listening", channelId);
199
+
200
+ if (subscription) {
201
+ // listen to channel events
202
+ for await (const msg of subscription) {
203
+ console.log("hi");
204
+ console.log({ data: StringCodec().decode(msg.data) });
205
+ const log: TaskLog = JSON.parse(StringCodec().decode(msg.data));
206
+ console.log({ log });
207
+ handleTaskLog(log);
208
+ }
209
+ console.log("Stopped listening", channelId);
210
+ console.log("Closed Channel", channelId);
211
+ }
212
+ }
213
+
214
+ watchEffect(() => {
215
+ if (natsSubject.value) {
216
+ subscribeToChannel(natsSubject.value);
217
+ }
218
+ });
219
+
220
+ watch(open, (n) => {
221
+ if (!n) {
222
+ subscription && subscription.unsubscribe();
223
+ }
224
+ });
225
+ onBeforeUnmount(() => {
226
+ subscription && subscription.unsubscribe();
227
+ });
228
+
229
+ // modal close / footer feature
230
+ const enableModalClose = computed(() => {
231
+ return (
232
+ connectionError.value ||
233
+ activeTask.value?.status === "Failed" ||
234
+ activeTask.value?.status === "Success"
235
+ );
236
+ });
237
+ const enableModalFooter = computed(() => {
238
+ return showReportButton.value || showSuccessButton.value;
239
+ });
240
+
241
+ // report button
242
+ const showReportButton = computed(() => activeTask.value?.status === "Failed");
243
+ function onReportIssueClick() {
244
+ const url = `https://github.com/bytebuilders/community/issues/new?title=Chart Install: ${
245
+ activeStep.value
246
+ }&labels[]=bug&body=${window.location.href} %0A%0A %60%60%60 %0A ${
247
+ activeTask.value?.logs[activeTask.value?.logs.length - 1 || 0]
248
+ } %0A %60%60%60`;
249
+ window.open(url, "_blank");
250
+ }
251
+
252
+ // success button
253
+ const showSuccessButton = computed(
254
+ () => activeTask.value?.status === "Success" && successCtx.value?.btnTitle
255
+ );
256
+
257
+ // execute on success and on error functions
258
+ watch(
259
+ () => activeTask.value?.status,
260
+ (n) => {
261
+ if (n === "Success") {
262
+ successCtx.value.onSuccess();
263
+ } else if (n === "Failed") {
264
+ errorCtx.value.onError(
265
+ activeTask.value?.logs[activeTask.value?.logs.length - 1 || 0] || ""
266
+ );
267
+ }
268
+ }
269
+ );
270
+ </script>
271
+
272
+ <style scoped lang="scss">
273
+ .task-simple-wrapper {
274
+ display: flex;
275
+ flex-direction: column;
276
+ justify-content: space-between;
277
+ width: 40vw;
278
+ height: 40vh;
279
+ .task-cogs-icon {
280
+ width: 100%;
281
+ height: 70%;
282
+ display: flex;
283
+ align-items: center;
284
+ justify-content: center;
285
+ font-size: 20px;
286
+ color: var(--ac-primary);
287
+ }
288
+ .task-log {
289
+ width: 100%;
290
+ height: 30%;
291
+ display: flex;
292
+ flex-direction: column;
293
+ align-items: center;
294
+ justify-content: center;
295
+ .task-title {
296
+ span,
297
+ i {
298
+ font-size: 16px;
299
+ }
300
+ i {
301
+ color: var(--ac-primary);
302
+ &.is-success {
303
+ color: #158748;
304
+ }
305
+ &.is-failed {
306
+ color: #ff3729;
307
+ }
308
+ }
309
+ font-weight: 500;
310
+ }
311
+ span {
312
+ font-size: 14px;
313
+ }
314
+ }
315
+ }
316
+ .task-complex-wrapper {
317
+ display: flex;
318
+ flex-direction: row;
319
+ justify-content: space-between;
320
+ width: 60vw;
321
+ height: 60vh;
322
+
323
+ .task-list {
324
+ width: 25%;
325
+ height: 100%;
326
+ }
327
+ .task-log {
328
+ width: 70%;
329
+ height: 100%;
330
+ border-radius: 1rem;
331
+ font-size: 13px;
332
+ }
333
+ }
334
+ </style>
@@ -0,0 +1,76 @@
1
+ <template>
2
+ <div ref="terminalRef" class="terminal-body"></div>
3
+ </template>
4
+
5
+ <script setup lang="ts">
6
+ import { computed, nextTick, ref, toRefs, watch, watchPostEffect } from 'vue'
7
+ import { Terminal } from 'xterm'
8
+ import { FitAddon } from 'xterm-addon-fit'
9
+ import { WebglAddon } from 'xterm-addon-webgl'
10
+ import { Material, MaterialDark } from 'xterm-theme' //https://github.com/ysk2014/xterm-theme/tree/master/src/iterm
11
+
12
+ const props = withDefaults(
13
+ defineProps<{
14
+ logs: string[]
15
+ }>(),
16
+ { logs: () => [] }
17
+ )
18
+ // terminal print logic
19
+ const { logs } = toRefs(props)
20
+ const lastPrintIdx = ref(0)
21
+ watch(
22
+ logs,
23
+ (n) => {
24
+ if (n.length > lastPrintIdx.value) {
25
+ nextTick(() => {
26
+ writeOnTerminal(n.slice(lastPrintIdx.value).join('\n'))
27
+ lastPrintIdx.value = n.length
28
+ })
29
+ }
30
+ },
31
+ { immediate: true, deep: true }
32
+ )
33
+
34
+ //theme
35
+ const theme = ref('light') // handle theme logic later, without the useStore function because they are different in console and kubedb ui
36
+ const bodyBgc = computed(() =>
37
+ theme.value === 'light' ? '#eaeaea' : '#232322'
38
+ )
39
+
40
+ // xterm component logic
41
+ const terminalRef = ref<HTMLElement>()
42
+ const terminal = new Terminal({
43
+ windowsMode: false,
44
+ theme: theme.value === 'light' ? Material : MaterialDark,
45
+ })
46
+ const fitAddon = new FitAddon()
47
+ terminal.loadAddon(fitAddon)
48
+ const webGlAddon = new WebglAddon()
49
+ webGlAddon.onContextLoss(() => {
50
+ webGlAddon.dispose()
51
+ })
52
+ watchPostEffect(() => {
53
+ if (terminalRef.value) {
54
+ terminal.open(terminalRef.value)
55
+ fitAddon.fit()
56
+ terminal.focus()
57
+ terminal.loadAddon(webGlAddon)
58
+ }
59
+ })
60
+ function writeOnTerminal(msg: string) {
61
+ const lines = msg.split('\n')
62
+ lines.forEach((line, index) => {
63
+ if (lines.length === 1 || index < lines.length - 1) terminal.writeln(line)
64
+ else terminal.write(line)
65
+ })
66
+ }
67
+ </script>
68
+
69
+ <style lang="scss">
70
+ .terminal-body {
71
+ width: 100%;
72
+ height: 100%;
73
+ background-color: v-bind(bodyBgc);
74
+ padding: 5px 0px 0px 10px;
75
+ }
76
+ </style>