Files
catalog/ts_web/elements/upl-statuspage-statusdetails.ts

355 lines
10 KiB
TypeScript
Raw Normal View History

2022-03-24 16:07:15 +01:00
import * as plugins from '../plugins.js';
2021-09-27 00:45:17 +02:00
import {
DeesElement,
property,
html,
customElement,
type TemplateResult,
2021-09-27 00:45:17 +02:00
css,
cssManager,
2025-06-29 19:55:58 +00:00
unsafeCSS,
} from '@design.estate/dees-element';
2025-06-29 19:55:58 +00:00
import type { IStatusHistoryPoint } from '../interfaces/index.js';
import { fonts, colors, shadows, borderRadius, spacing, commonStyles, getStatusColor } from '../styles/shared.styles.js';
2021-09-23 14:30:02 +02:00
2022-03-24 16:07:15 +01:00
import './internal/uplinternal-miniheading.js';
2025-06-29 19:55:58 +00:00
import { demoFunc } from './upl-statuspage-statusdetails.demo.js';
2021-09-23 14:30:02 +02:00
declare global {
interface HTMLElementTagNameMap {
'upl-statuspage-statusdetails': UplStatuspageStatusdetails;
}
}
@customElement('upl-statuspage-statusdetails')
export class UplStatuspageStatusdetails extends DeesElement {
2025-06-29 19:55:58 +00:00
public static demo = demoFunc;
@property({ type: Array })
public historyData: IStatusHistoryPoint[] = [];
2025-06-29 23:53:05 +00:00
@property({ type: Array })
public dataPoints: IStatusHistoryPoint[] = [];
2025-06-29 19:55:58 +00:00
@property({ type: String })
public serviceId: string = '';
@property({ type: String })
public serviceName: string = 'Service';
@property({ type: Boolean })
public loading: boolean = false;
@property({ type: Number })
public hoursToShow: number = 48;
2021-09-23 14:30:02 +02:00
constructor() {
super();
}
2021-09-27 00:45:17 +02:00
public static styles = [
plugins.domtools.elementBasic.staticStyles,
2025-06-29 19:55:58 +00:00
commonStyles,
2021-09-27 00:45:17 +02:00
css`
:host {
position: relative;
display: block;
2025-06-29 19:55:58 +00:00
background: transparent;
font-family: ${unsafeCSS(fonts.base)};
color: ${colors.text.primary};
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 0 ${unsafeCSS(spacing.lg)} ${unsafeCSS(spacing.lg)} ${unsafeCSS(spacing.lg)};
2021-09-27 00:45:17 +02:00
}
2025-06-29 23:53:05 +00:00
.graph-wrapper {
display: flex;
flex-direction: column;
gap: 4px;
}
.graph-container {
position: relative;
}
2021-09-27 00:45:17 +02:00
.mainbox {
2025-06-29 23:53:05 +00:00
background: transparent;
border: none;
border-radius: 0;
padding: 0;
2021-09-27 00:45:17 +02:00
}
2021-09-23 14:30:02 +02:00
2021-09-27 00:45:17 +02:00
.mainbox .barContainer {
position: relative;
display: flex;
2025-06-30 00:17:43 +00:00
gap: 2px;
2025-06-29 19:55:58 +00:00
padding: ${unsafeCSS(spacing.sm)};
2025-06-29 23:53:05 +00:00
background: ${cssManager.bdTheme('#fafafa', '#0a0a0a')};
2025-06-30 00:17:43 +00:00
border: 1px solid ${cssManager.bdTheme('#e5e7eb', '#27272a')};
2025-06-29 19:55:58 +00:00
border-radius: ${unsafeCSS(borderRadius.base)};
2021-09-27 00:45:17 +02:00
overflow: hidden;
2025-06-29 23:53:05 +00:00
height: 40px;
2021-09-27 00:45:17 +02:00
}
2021-09-23 14:30:02 +02:00
2021-09-27 00:45:17 +02:00
.mainbox .barContainer .bar {
2025-06-29 19:55:58 +00:00
flex: 1;
2025-06-29 23:53:05 +00:00
height: 100%;
2025-06-29 19:55:58 +00:00
cursor: pointer;
2025-06-30 00:17:43 +00:00
transition: all 0.15s ease;
2025-06-29 19:55:58 +00:00
position: relative;
2025-06-30 00:17:43 +00:00
border-radius: 2px;
2025-06-29 19:55:58 +00:00
}
.mainbox .barContainer .bar:hover {
2025-06-30 00:17:43 +00:00
transform: scaleY(1.1);
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
2021-09-27 00:45:17 +02:00
}
2025-06-29 19:55:58 +00:00
.mainbox .barContainer .bar.operational {
2025-06-29 23:53:05 +00:00
background: ${cssManager.bdTheme('#22c55e', '#22c55e')};
2025-06-29 19:55:58 +00:00
}
.mainbox .barContainer .bar.degraded {
2025-06-29 23:53:05 +00:00
background: ${cssManager.bdTheme('#fbbf24', '#fbbf24')};
2025-06-29 19:55:58 +00:00
}
.mainbox .barContainer .bar.partial_outage {
2025-06-29 23:53:05 +00:00
background: ${cssManager.bdTheme('#f87171', '#f87171')};
2025-06-29 19:55:58 +00:00
}
.mainbox .barContainer .bar.major_outage {
2025-06-29 23:53:05 +00:00
background: ${cssManager.bdTheme('#ef4444', '#ef4444')};
2025-06-29 19:55:58 +00:00
}
.mainbox .barContainer .bar.maintenance {
2025-06-29 23:53:05 +00:00
background: ${cssManager.bdTheme('#60a5fa', '#60a5fa')};
2025-06-29 19:55:58 +00:00
}
.mainbox .barContainer .bar.no-data {
2025-06-30 00:17:43 +00:00
background: ${cssManager.bdTheme('#e5e7eb', '#27272a')};
opacity: 0.6;
2025-06-29 19:55:58 +00:00
}
.time-labels {
display: flex;
justify-content: space-between;
2025-06-29 23:53:05 +00:00
padding: 0;
margin-top: ${unsafeCSS(spacing.xs)};
font-size: 10px;
color: ${cssManager.bdTheme('#9ca3af', '#71717a')};
font-family: ${unsafeCSS(fonts.base)};
opacity: 0.8;
2025-06-29 19:55:58 +00:00
}
.tooltip {
position: absolute;
2025-06-29 23:53:05 +00:00
background: ${cssManager.bdTheme('#0a0a0a', '#fafafa')};
color: ${cssManager.bdTheme('#fafafa', '#0a0a0a')};
padding: 6px 10px;
border-radius: 4px;
font-size: 11px;
2025-06-29 19:55:58 +00:00
pointer-events: none;
opacity: 0;
2025-06-29 23:53:05 +00:00
transition: opacity 0.15s;
z-index: 50;
2025-06-29 19:55:58 +00:00
white-space: nowrap;
2025-06-29 23:53:05 +00:00
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
line-height: 1.4;
2025-06-29 19:55:58 +00:00
}
.tooltip.visible {
2025-06-29 23:53:05 +00:00
opacity: 1;
2025-06-29 19:55:58 +00:00
}
2025-06-29 23:53:05 +00:00
.tooltip-time {
2025-06-29 19:55:58 +00:00
font-weight: 600;
display: block;
2025-06-29 23:53:05 +00:00
margin-bottom: 2px;
2025-06-29 19:55:58 +00:00
}
2025-06-29 23:53:05 +00:00
.tooltip-stat {
font-size: 10px;
opacity: 0.9;
2025-06-29 19:55:58 +00:00
}
.loading-skeleton {
display: flex;
2025-06-29 23:53:05 +00:00
gap: 1px;
height: 24px;
2025-06-29 19:55:58 +00:00
}
.loading-skeleton .skeleton-bar {
flex: 1;
2025-06-29 23:53:05 +00:00
height: 100%;
background: ${cssManager.bdTheme('#f3f4f6', '#27272a')};
animation: pulse 2s infinite;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
2025-06-29 19:55:58 +00:00
}
@keyframes loading {
0% { background-position: 200% 0; }
100% { background-position: -200% 0; }
}
@media (max-width: 640px) {
.container {
padding: 0 ${unsafeCSS(spacing.md)} ${unsafeCSS(spacing.md)} ${unsafeCSS(spacing.md)};
}
2025-06-29 23:53:05 +00:00
.graph-container {
2025-06-29 19:55:58 +00:00
padding: ${unsafeCSS(spacing.sm)};
}
2025-06-29 23:53:05 +00:00
.mainbox .barContainer {
height: 32px;
padding: ${unsafeCSS(spacing.xs)};
}
2025-06-29 19:55:58 +00:00
.time-labels {
2025-06-29 23:53:05 +00:00
font-size: 9px;
2025-06-29 19:55:58 +00:00
}
2025-06-29 23:53:05 +00:00
.stats-row {
font-size: 11px;
flex-direction: column;
gap: ${unsafeCSS(spacing.sm)};
align-items: flex-start;
2025-06-29 19:55:58 +00:00
}
2021-09-27 00:45:17 +02:00
}
`,
];
2021-09-23 14:30:02 +02:00
2021-09-27 00:45:17 +02:00
public render(): TemplateResult {
return html`
2025-06-29 22:36:12 +00:00
<div class="container">
<uplinternal-miniheading>${this.serviceName} - Last ${this.hoursToShow} Hours</uplinternal-miniheading>
<div class="mainbox">
${this.loading ? html`
2025-06-29 23:53:05 +00:00
<div class="graph-container">
<div class="barContainer" style="background: ${cssManager.bdTheme('#fafafa', '#0a0a0a')}; border: 1px solid ${cssManager.bdTheme('#f3f4f6', '#1f1f1f')}; border-radius: ${borderRadius.base}; padding: ${spacing.sm}; height: 40px;">
<div class="loading-skeleton">
${Array(this.hoursToShow).fill(0).map(() => html`<div class="skeleton-bar"></div>`)}
</div>
</div>
2025-06-29 19:55:58 +00:00
</div>
` : html`
2025-06-29 23:53:05 +00:00
<div class="graph-container">
<div class="barContainer" @mouseleave=${this.hideTooltip}>
${this.renderBars()}
</div>
2025-06-29 19:55:58 +00:00
</div>
<div class="time-labels">
2025-06-29 23:53:05 +00:00
<span>${this.getTimeLabel(this.hoursToShow - 1)}</span>
2025-06-29 19:55:58 +00:00
<span>${this.getTimeLabel(Math.floor(this.hoursToShow * 3 / 4))}</span>
2025-06-29 23:53:05 +00:00
<span>${this.getTimeLabel(Math.floor(this.hoursToShow / 2))}</span>
<span>${this.getTimeLabel(Math.floor(this.hoursToShow / 4))}</span>
<span>now</span>
2025-06-29 19:55:58 +00:00
</div>
`}
</div>
2025-06-29 22:36:12 +00:00
<div class="tooltip" id="tooltip"></div>
</div>
2025-06-29 19:55:58 +00:00
`;
}
private renderBars(): TemplateResult[] {
const bars: TemplateResult[] = [];
const now = Date.now();
for (let i = 0; i < this.hoursToShow; i++) {
const hourIndex = this.hoursToShow - 1 - i;
const timestamp = now - (hourIndex * 60 * 60 * 1000);
const dataPoint = this.findDataPointForTime(timestamp);
const status = dataPoint?.status || 'no-data';
const responseTime = dataPoint?.responseTime || 0;
bars.push(html`
<div
class="bar ${status}"
@mouseenter=${(e: MouseEvent) => this.showTooltip(e, timestamp, status, responseTime)}
@click=${() => this.handleBarClick(timestamp, status, responseTime)}
></div>
`);
}
return bars;
}
2025-06-29 23:53:05 +00:00
private getData(): IStatusHistoryPoint[] {
return this.dataPoints?.length > 0 ? this.dataPoints : this.historyData || [];
}
2025-06-29 19:55:58 +00:00
private findDataPointForTime(timestamp: number): IStatusHistoryPoint | undefined {
2025-06-29 23:53:05 +00:00
const data = this.getData();
if (!data || data.length === 0) return undefined;
2025-06-29 19:55:58 +00:00
// Find the closest data point within the same hour
const targetHour = new Date(timestamp).getHours();
const targetDate = new Date(timestamp).toDateString();
2025-06-29 23:53:05 +00:00
return data.find(point => {
2025-06-29 19:55:58 +00:00
const pointDate = new Date(point.timestamp);
return pointDate.toDateString() === targetDate &&
pointDate.getHours() === targetHour;
});
}
private getTimeLabel(hoursAgo: number): string {
const date = new Date(Date.now() - (hoursAgo * 60 * 60 * 1000));
if (hoursAgo >= 24) {
2025-06-29 23:53:05 +00:00
return `${date.getMonth() + 1}/${date.getDate()}`;
2025-06-29 19:55:58 +00:00
}
2025-06-29 23:53:05 +00:00
return `${date.getHours()}h`;
2025-06-29 19:55:58 +00:00
}
private showTooltip(event: MouseEvent, timestamp: number, status: string, responseTime: number) {
const tooltip = this.shadowRoot?.getElementById('tooltip') as HTMLElement;
if (!tooltip) return;
const date = new Date(timestamp);
const timeStr = date.toLocaleString();
const statusStr = status.replace(/_/g, ' ').replace('no-data', 'No Data');
tooltip.innerHTML = `
2025-06-29 23:53:05 +00:00
<div class="tooltip-time">${timeStr}</div>
<div class="tooltip-stat">Status: ${statusStr}</div>
${responseTime > 0 ? `<div class="tooltip-stat">Response Time: ${responseTime.toFixed(0)}ms</div>` : ''}
2021-09-23 14:30:02 +02:00
`;
2025-06-29 19:55:58 +00:00
const rect = (event.target as HTMLElement).getBoundingClientRect();
const containerRect = this.getBoundingClientRect();
tooltip.style.left = `${rect.left - containerRect.left + rect.width / 2}px`;
2025-06-29 23:53:05 +00:00
tooltip.style.top = `${rect.top - containerRect.top - 10}px`;
tooltip.style.transform = 'translate(-50%, -100%)';
2025-06-29 19:55:58 +00:00
tooltip.classList.add('visible');
}
private hideTooltip() {
const tooltip = this.shadowRoot?.getElementById('tooltip') as HTMLElement;
if (tooltip) {
tooltip.classList.remove('visible');
}
}
private handleBarClick(timestamp: number, status: string, responseTime: number) {
this.dispatchEvent(new CustomEvent('barClick', {
detail: { timestamp, status, responseTime, serviceId: this.serviceId },
bubbles: true,
composed: true
}));
2021-09-23 14:30:02 +02:00
}
2025-06-29 23:53:05 +00:00
2021-09-27 00:45:17 +02:00
}