मुख्य सामग्री पर जाएँ
Skillpedia
वेबसाइट और UI (frontend)7.8k · #13066

panel-component-colocated-helpers

यह क्या करती है

यह स्किल AI एजेंट को सादे TypeScript में डैशबोर्ड पैनल बनाने का मार्गदर्शन देती है, जिसमें हेल्पर पैनल कोड के साथ रखे जाते हैं। यह उन डेवलपर्स के लिए है जो ऐसी स्व-निहित पैनल फ़ाइलें चाहते हैं जिनमें कम इंपोर्ट हों।

कब इस्तेमाल करें

  • ✓जब आपको ऐसा पैनल चाहिए जो विफल fetch दोबारा करे और विस्तारित या सिकुड़ी स्थिति सहेजे।
  • ✓जब पैनल को timeAgo फ़ॉर्मेटर या स्टेटस आइकन जैसे छोटे हेल्पर फ़ंक्शन चाहिए।
  • ✓जब आप ऐसी पैनल फ़ाइलें पसंद करते हैं जो कई साझा इंपोर्ट पर निर्भर न हों।

Skill का लिंक

https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/panel-component-colocated-helpers/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/panel-component-colocated-helpers/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“सादे TypeScript में एक न्यूज़ पैनल बनाइए जिसमें उसी फ़ाइल में timeAgo हेल्पर हो, विफलता पर रीट्राई हों, और सिकुड़ी स्थिति सहेजी जाए।”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

एजेंट एक Panel क्लास लिखता है जो एक्सपोनेंशियल बैकऑफ़ के साथ fetch दोबारा करती है और स्थिति localStorage में सहेजती है। वह timeAgo और statusIcon जैसे शुद्ध हेल्पर फ़ंक्शन उसी फ़ाइल में पैनल क्लास के साथ रखता है।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।

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.
  • Co-located Helpers: Panel-specific pure utility functions live in the same file as the panel class, keeping implementations self-contained.
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): voi
अक्सर पूछे जाने वाले सवाल

सह-स्थित हेल्पर क्या है?

यह एक छोटा शुद्ध फ़ंक्शन है जो उसी फ़ाइल में रखा जाता है जिस पैनल में वह इस्तेमाल होता है।

कितनी रीट्राई होती हैं?

स्किल के उदाहरण में एक सेकंड से शुरू करके हर बार दोगुने समय के साथ अधिकतम तीन रीट्राई होती हैं।

क्या अगली बार भी स्थिति सहेजी रहती है?

हां, स्किल विस्तारित या सिकुड़ी स्थिति और आकार localStorage में सहेजती है।

जानकारी

लेखक का मूल विवरण

Enhanced dashboard panel component with robust error handling, retry logic, localStorage persistence, and co-located inline helper functions (e.g. timeAgo, statusIcon) for self-contained, import-light panel implementations.

repo: HKUDS/AgentPilot

लोकप्रियता

GitHub स्टार
7.8k
रैंकिंग में स्थान
#13066
लाइसेंस
MIT
अपडेट की गई
1/11/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

मिलती-जुलती skills