blob: 1df27d8b6db4152091bc61080d5afaeaf0586279 [file] [log] [blame]
bankseanbdc68892025-07-28 17:28:13 -07001import { html, TemplateResult } from "lit";
2import { customElement, property, state } from "lit/decorators.js";
3import { ExternalMessage } from "../types";
4import { SketchTailwindElement } from "./sketch-tailwind-element";
5import type { WorkflowRunEvent } from "@octokit/webhooks-types";
6
7@customElement("sketch-external-message")
8export class SketchExternalMessage extends SketchTailwindElement {
9 @property() message: ExternalMessage | null = null;
10 @property() open: boolean;
11 @property() summaryContent: TemplateResult | string = "";
12 @property() detailsContent: TemplateResult | string = "";
13 @state() detailsVisible: boolean = false;
14
15 _toggleDetails(e: Event) {
16 e.stopPropagation();
17 this.detailsVisible = !this.detailsVisible;
18 }
19
20 constructor() {
21 super();
22 }
23
24 render() {
25 if (this.message?.message_type === "github_workflow_run") {
26 const run = this.message.body as WorkflowRunEvent;
27 this.summaryContent = html`<svg
28 class="inline-block w-4 h-4"
29 viewBox="0 0 16 16"
30 width="16"
31 height="16"
32 >
33 <path
34 fill="currentColor"
35 d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"
36 ></path>
37 </svg>
38 <span
39 class="inline-flex items-center px-1.5 py-1
40 ${run.workflow_run.conclusion === "success"
41 ? "bg-green-600/10 text-green-600"
42 : run.workflow_run.conclusion === "failure"
43 ? "bg-red-600/10 text-red-600"
44 : "bg-gray-600/10 text-gray-600"}
45 rounded-md text-xs flex-shrink-0 transition-colors"
46 >${run.workflow.name} -
47 ${run.workflow_run.conclusion || run.workflow_run.status}</span
48 >
49 on ${run.workflow_run.head_branch} at ${run.workflow_run.head_commit}`;
50
51 this.detailsContent = html`
52 <div class="flex items-center gap-2">
53 <span class="text-gray-700 dark:text-gray-300">Workflow ID:</span>
54 <span class="font-mono font-medium text-gray-800 dark:text-gray-200">${run.workflow_run.id}</span>
55 </div>
56 <div class="flex items-center gap-2">
57 bg-gray-600/10 text-gray-600
58 {{end}}
59 rounded-md text-xs flex-shrink-0 transition-colors'><a target="_blank"
60 rel="noopener noreferrer"href="${run.workflow_run.html_url}">${run.workflow.name} - ${run.workflow_run.conclusion}</a>
61 on ${run.workflow_run.head_branch} at ${run.workflow_run.head_commit}</span>
62 </span>`;
63
64 this.detailsContent = html`
65 <div class="flex items-center gap-2">
66 <span class="text-gray-700 dark:text-gray-300">Workflow Run ID:</span>
67 <span class="font-mono font-medium text-gray-800 dark:text-gray-200"
68 >${run.workflow_run.id}</span
69 >
70 </div>
71 <div class="flex items-center gap-2">
72 <span class="text-gray-700 dark:text-gray-300">Status:</span>
73 <span class="font-mono font-medium text-gray-800 dark:text-gray-200"
74 >${run.workflow_run.status}</span
75 >
76 </div>
77 <div class="flex items-center gap-2">
78 <span class="text-gray-700 dark:text-gray-300">Conclusion:</span>
79 <span class="font-mono font-medium text-gray-800 dark:text-gray-200"
80 >${run.workflow_run.conclusion}</span
81 >
82 </div>
83 <div class="flex items-center gap-2">
84 <span class="text-gray-700 dark:text-gray-300">Run URL:</span>
85 <a
86 class="text-blue-600 dark:text-blue-400 hover:underline"
87 href="${run.workflow_run.html_url}"
88 target="_blank"
89 rel="noopener noreferrer"
90 >
91 ${run.workflow_run.html_url}
92 </a>
93 </div>
94 `;
95 }
96
97 return html`
98 <div class="block max-w-full w-full box-border overflow-hidden">
99 <div class="flex flex-col w-full">
100 <div
101 class="flex w-full box-border py-1.5 px-2 pl-3 items-center gap-2 cursor-pointer rounded relative overflow-hidden flex-wrap hover:bg-black/[0.02] dark:hover:bg-white/[0.05]"
102 @click=${this._toggleDetails}
103 >
104 <span
105 class="whitespace-nowrap flex-grow flex-shrink text-gray-700 dark:text-gray-300 font-mono text-xs px-1 min-w-[50px] max-w-[calc(100%-150px)] inline-block"
106 >${this.summaryContent}</span
107 >
108 </div>
109 <div
110 class="${this.detailsVisible
111 ? "block"
112 : "hidden"} p-2 bg-black/[0.02] dark:bg-white/[0.05] mt-px border-t border-black/[0.05] dark:border-white/[0.1] font-mono text-xs text-gray-800 dark:text-gray-200 rounded-b max-w-full w-full box-border overflow-hidden"
113 >
114 ${this.detailsContent
115 ? html`<div class="mb-2">${this.detailsContent}</div>`
116 : ""}
117 </div>
118 </div>
119 </div>
120 `;
121 }
122}
123
124declare global {
125 interface HTMLElementTagNameMap {
126 "sketch-notification-message": SketchExternalMessage;
127 }
128}