panel-retry-localstorage
预览截图
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "panel-retry-localstorage":https://skillpi.com/zh/skills/deepskill-7a2367fe6204d5af56022b76638300ebce7740f3cc3a29727eb66a1d8cf3184a。安装前核对上游来源和版本:https://github.com/HKUDS/OpenSpace。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
增强型仪表板面板组件,具备强大的错误处理与重试逻辑,并将状态通过 localStorage 持久化以便管理。
介绍来源: third_party · HKUDS · 0.0.1 参考来源
SkillPi 解读
- 能完成的任务
- 强化仪表板面板组件,具有强大的错误处理,重试逻辑,以及用于状态管理的本地Storage持久性.
- 实测状态
- 未测试
文件浏览
Frontmatter
name: panel-retry-localstorage
description: Enhanced dashboard panel component with robust error handling, retry logic, and localStorage persistence for state management.Panel Component Pattern
Create dashboard panel components using vanilla TypeScript (no framework, no JSX). Each panel is a class extending a Panel base class.
Architecture Overview
Enhanced Features
- Retry Logic: Automatically retries failed data fetches with exponential backoff.
- State Persistence: Saves panel state (expanded/collapsed, size) to localStorage.
- Detailed Error Handling: Provides more granular error messages and recovery options.
Panel (base class)
├── element: HTMLElement (outer container, .panel)
│ ├── header: HTMLElement (.panel-header)
│ │ ├── headerLeft (.panel-header-left)
│ │ │ ├── title (.panel-title)
│ │ │ └── newBadge (.panel-new-badge) [optional]
│ │ ├── statusBadge (.panel-data-badge) [optional]
│ │ └── countEl (.panel-count) [optional]
│ ├── content: HTMLElement (.panel-content)
│ └── resizeHandle (.panel-resize-handle)
Base Panel Class (Simplified for this project)
export class Panel {
// ... existing code ...
private retryAttempts = 0;
private maxRetries = 3;
private retryDelay = 1000; // starts at 1s, doubles each retry
protected async fetchWithRetry(url: string): Promise<any> {
while (this.retryAttempts < this.maxRetries) {
try {
const response = await fetch(url);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
return await response.json();
} catch (error) {
this.retryAttempts++;
if (this.retryAttempts >= this.maxRetries) {
throw new Error(`Failed after ${this.maxRetries} attempts: ${error.message}`);
}
await new Promise(resolve => setTimeout(resolve, this.retryDelay));
this.retryDelay *= 2;
}
}
}
public saveState(): void {
localStorage.setItem(`panelState_${this.panelId}`, JSON.stringify({
isExpanded: !this.element.classList.contains('collapsed'),
width: this.element.style.width,
height: this.element.style.height
}));
}
public loadState(): void {
const savedState = localStorage.getItem(`panelState_${this.panelId}`);
if (savedState) {
const { isExpanded, width, height } = JSON.parse(savedState);
if (!isExpanded) this.element.classList.add('collapsed');
if (width) this.element.style.width = width;
if (height) this.element.style.height = height;
}
}
}
Create src/components/Panel.ts:
export interface PanelOptions {
id: string;
title: string;
showCount?: boolean;
className?: string;
}
export class Panel {
protected element: HTMLElement;
protected content: HTMLElement;
protected header: HTMLElement;
protected countEl: HTMLElement | null = null;
protected panelId: string;
private _fetching = false;
constructor(options: PanelOptions) {
this.panelId = options.id;
this.element = document.createElement('div');
this.element.className = `panel ${options.className || ''}`;
this.element.dataset.panel = options.id;
// Header
this.header = document.createElement('div');
this.header.className = 'panel-header';
const headerLeft = document.createElement('div');
headerLeft.className = 'panel-header-left';
const title = document.createElement('span');
title.className = 'panel-title';
title.textContent = options.title;
headerLeft.appendChild(title);
this.header.appendChild(headerLeft);
// Count badge (optional)
if (options.showCount) {
this.countEl = document.createElement('span');
this.countEl.className = 'panel-count';
this.countEl.textContent = '0';
this.header.appendChild(this.countEl);
}
// Content area
this.content = document.createElement('div');
this.content.className = 'panel-content';
this.content.id = `${options.id}Content`;
this.element.appendChild(this.header);
this.element.appendChild(this.content);
this.showLoading();
}
public getElement(): HTMLElement { return this.element; }
public showLoading(message = 'Loading...'): void {
this.content.innerHTML = `
<div class="panel-loading">
<div class="panel-loading-spinner"></div>
<div class="panel-loading-text">${message}</div>
</div>`;
}
public showError(message = 'Failed to load', onRetry?: () => void): void {
this.content.innerHTML = `
<div class="panel-error-state">
<div class="panel-error-msg">${message}</div>
${onRetry ? '<button class="panel-retry-btn" data-panel-retry>Retry</button>' : ''}
</div>`;
if (onRetry) {
this.content.querySelector('[data-panel-retry]')?.addEventListener('click', onRetry);
}
}
public setContent(html: string): void {
this.content.innerHTML = html;
}
public setCount(count: number): void {
if (this.countEl) this.countEl.textContent = count.toString();
}
public show(): void { this.element.classList.remove('hidden'); }
public hide(): void { this.element.classList.add('hidden'); }
protected setFetching(v: boolean): void { this._fetching = v; }
protected get isFetching(): boolean { return this._fetching; }
public destroy(): void {
this.element.remove();
}
}
Creating a Concrete Panel (Example: StockPanel)
export class StockPanel extends Panel {
// ... existing code ...
private async fetchData(): Promise<void> {
if (this.isFetching) return;
this.setFetching(true);
try {
const quotes = await this.fetchWithRetry('/api/stocks');
this.render(quotes);
this.setCount(quotes.length);
this.saveState();
} catch (err) {
this.showError(`Failed to load stock data: ${err.message}`, () => {
this.retryAttempts = 0;
this.retryDelay = 1000;
this.fetchData();
});
} finally {
this.setFetching(false);
}
}
}
Each panel extends Panel and manages its own data fetching + rendering:
import { Panel } from './Panel';
interface StockQuote {
symbol: string;
name: string;
price: number | null;
change: number | null;
sparkline?: number[];
}
export class StockPanel extends Panel {
private refreshTimer: ReturnType<typeof setInterval> | null = null;
constructor() {
super({ id: 'stocks', title: 'Stock Market', showCount: true });
this.fetchData();
this.refreshTimer = setInterval(() => this.fetchData(), 60_000);
}
private async fetchData(): Promise<void> {
if (this.isFetching) return;
this.setFetching(true);
try {
const quotes = await fetchStockQuotes(); // from data-service
this.render(quotes);
this.setCount(quotes.length);
} catch (err) {
this.showError('Failed to load stock data', () => this.fetchData());
} finally {
this.setFetching(false);
}
}
private render(quotes: StockQuote[]): void {
const rows = quotes.map(q => `
<div class="stock-row">
<span class="stock-symbol">${q.symbol}</span>
<span class="stock-name">${q.name}</span>
<span class="stock-price">${q.price != null ? '$' + q.price.toFixed(2) : '—'}</span>
<span class="stock-change ${(q.change ?? 0) >= 0 ? 'positive' : 'negative'}">
${q.change != null ? (q.change >= 0 ? '+' : '') + q.change.toFixed(2) + '%' : '—'}
</span>
</div>
`).join('');
this.setContent(`<div class="stock-list">${rows}</div>`);
}
public override destroy(): void {
if (this.refreshTimer) clearInterval(this.refreshTimer);
super.destroy();
}
}
Protected API Reference
All members and methods listed below are accessible from subclasses without importing or inspecting Panel.ts directly:
| Member / Method | Type | Description |
|---|---|---|
element |
HTMLElement |
Outer container div (.panel) |
header |
HTMLElement |
Header bar div (.panel-header) — append extra controls here |
content |
HTMLElement |
Content area div (.panel-content) |
countEl |
HTMLElement \| null |
Count badge span, or null if showCount was not set |
panelId |
string |
The id passed to PanelOptions |
isFetching |
boolean (getter) |
true while an async fetch is in progress |
setFetching(v: boolean) |
void |
Set the fetching guard flag |
showLoading(message?) |
void |
Replace content with a loading spinner |
showError(message?, onRetry?) |
void |
Replace content with an error state and optional retry button |
setContent(html: string) |
void |
Set raw HTML into the content area |
setCount(count: number) |
void |
Update the count badge text (no-op if countEl is null) |
Example — appending a button to the header in a subclass:
constructor() { super({ id: 'insights', title: 'Insights', className: 'panel-wide' }); const btn = document.createElement('button'); btn.className = 'panel-refresh-btn'; btn.textContent = '↻'; btn.addEventListener('click', () => this.generate()); this.header.appendChild(btn); // 'header' is protected — safe to use here }
Key Patterns
- Constructor calls
super()with panel config, then triggers initial data fetch - fetchData() is async, uses
isFetchingguard, shows error on failure with retry - render() builds HTML strings and calls
this.setContent(html) - destroy() cleans up timers and event listeners
- Use
showLoading()during initial load (auto-called in constructor) - Use
showError(msg, retryFn)on failure - Sparkline SVGs use inline
<svg>with<polyline>— see sparkline utility
Icon / Emoji Values
Important: When a panel or component accepts an
iconfield (e.g. in aQuickLinkdefinition), the value must be a literal Unicode emoji character — not a text abbreviation or shortcode.✅ Correct — use the actual emoji character directly:
const DEFAULT_LINKS = [ { label: 'GitHub', icon: '🐙', url: 'https://github.com' }, { label: 'Gmail', icon: '📧', url: 'https://mail.google.com' }, { label: 'Calendar', icon: '📅', url: 'https://calendar.google.com' }, { label: 'Docs', icon: '📝', url: 'https://docs.google.com' }, { label: 'Slack', icon: '💬', url: 'https://slack.com' }, ];❌ Wrong — do NOT use abbreviation strings as icon values:
// BAD: 'GH', 'GM', 'CAL', 'DOC', 'SL' are not emoji; they will render as plain text const DEFAULT_LINKS = [ { label: 'GitHub', icon: 'GH', url: 'https://github.com' }, { label: 'Gmail', icon: 'GM', url: 'https://mail.google.com' }, ];Emoji are standard Unicode code points. Copy-paste them directly into the source string — no escaping, no library, no conversion step required. For example
'🐙'is the literal octopus emoji and will render correctly in any modern browser. Do not attempt to "fix" an abbreviation into an emoji via a shell one-liner ornode -escript; write the file with the correct emoji character in the string literal from the start.
Sparkline Utility
export function miniSparkline(data: number[] | undefined, change: number | null, w = 50, h = 16): string {
if (!data || data.length < 2) return '';
const min = Math.min(...data);
const max = Math.max(...data);
const range = max - min || 1;
const color = change != null && change >= 0 ? 'var(--green)' : 'var(--red)';
const points = data.map((v, i) => {
const x = (i / (data.length - 1)) * w;
const y = h - ((v - min) / range) * (h - 2) - 1;
return `${x.toFixed(1)},${y.toFixed(1)}`;
}).join(' ');
return `<svg width="${w}" height="${h}" viewBox="0 0 ${w} ${h}"><polyline points="${points}" fill="none" stroke="${color}" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/></svg>`;
}当前收录版本
0.0.1
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供完整的仪表板面板组件开发模式,具有明确的实用价值
- 包含错误处理、重试逻辑和状态持久化等增强功能
- 适用于前端开发者的通用工具场景
亮点
- 触发词精准完整,覆盖多种变体
- 边界清晰,不易与其他Skill重叠
亮点
- Phase/步骤清晰,有出口条件
- 包含端到端示例,frontmatter完整
- 文档结构良好,易于理解执行流程
亮点
- 工具来源明确,参数正确
- 覆盖主要异常,不可逆操作有确认机制
- 代码示例完整,执行可靠性良好
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
文档引用的域名或地址
这些地址可能用于文档链接或示例,不是已批准的联网清单。使用前核对实际目的地及发送的数据。
- calendar.google.com
- docs.google.com
- github.com
- mail.google.com
- slack.com
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。