311 lines
9.1 KiB
TypeScript
311 lines
9.1 KiB
TypeScript
import {
|
|
DeesElement,
|
|
customElement,
|
|
html,
|
|
css,
|
|
cssManager,
|
|
property,
|
|
type TemplateResult,
|
|
} from '@design.estate/dees-element';
|
|
|
|
declare global {
|
|
interface HTMLElementTagNameMap {
|
|
'sz-tokens-view': SzTokensView;
|
|
}
|
|
}
|
|
|
|
export interface IToken {
|
|
id: string;
|
|
name: string;
|
|
type: 'global' | 'ci';
|
|
service?: string;
|
|
createdAt: string;
|
|
lastUsed?: string;
|
|
}
|
|
|
|
@customElement('sz-tokens-view')
|
|
export class SzTokensView extends DeesElement {
|
|
public static demo = () => html`
|
|
<div style="padding: 24px; max-width: 1000px;">
|
|
<sz-tokens-view
|
|
.globalTokens=${[
|
|
{ id: '1', name: 'CI/CD Pipeline', type: 'global', createdAt: '2024-01-15', lastUsed: '2024-01-20' },
|
|
{ id: '2', name: 'Development', type: 'global', createdAt: '2024-01-10' },
|
|
]}
|
|
.ciTokens=${[
|
|
{ id: '3', name: 'hello-world-ci', type: 'ci', service: 'hello-world', createdAt: '2024-01-18' },
|
|
{ id: '4', name: 'api-service-ci', type: 'ci', service: 'api-service', createdAt: '2024-01-12', lastUsed: '2024-01-19' },
|
|
]}
|
|
></sz-tokens-view>
|
|
</div>
|
|
`;
|
|
|
|
public static demoGroups = ['Auth & Settings'];
|
|
|
|
@property({ type: Array })
|
|
public accessor globalTokens: IToken[] = [];
|
|
|
|
@property({ type: Array })
|
|
public accessor ciTokens: IToken[] = [];
|
|
|
|
public static styles = [
|
|
cssManager.defaultStyles,
|
|
css`
|
|
:host {
|
|
display: block;
|
|
}
|
|
|
|
.section {
|
|
background: ${cssManager.bdTheme('#ffffff', '#09090b')};
|
|
border: 1px solid ${cssManager.bdTheme('#e4e4e7', '#27272a')};
|
|
border-radius: 8px;
|
|
margin-bottom: 24px;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.section-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: flex-start;
|
|
padding: 16px;
|
|
border-bottom: 1px solid ${cssManager.bdTheme('#e4e4e7', '#27272a')};
|
|
}
|
|
|
|
.section-info {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 4px;
|
|
}
|
|
|
|
.section-title {
|
|
font-size: 16px;
|
|
font-weight: 600;
|
|
color: ${cssManager.bdTheme('#18181b', '#fafafa')};
|
|
}
|
|
|
|
.section-subtitle {
|
|
font-size: 13px;
|
|
color: ${cssManager.bdTheme('#71717a', '#a1a1aa')};
|
|
}
|
|
|
|
.create-button {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 6px;
|
|
padding: 8px 14px;
|
|
background: ${cssManager.bdTheme('#18181b', '#fafafa')};
|
|
border: none;
|
|
border-radius: 6px;
|
|
font-size: 13px;
|
|
font-weight: 500;
|
|
color: ${cssManager.bdTheme('#fafafa', '#18181b')};
|
|
cursor: pointer;
|
|
transition: all 200ms ease;
|
|
}
|
|
|
|
.create-button:hover {
|
|
opacity: 0.9;
|
|
}
|
|
|
|
.token-list {
|
|
padding: 16px;
|
|
}
|
|
|
|
.token-item {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
padding: 12px 16px;
|
|
background: ${cssManager.bdTheme('#f4f4f5', '#18181b')};
|
|
border-radius: 6px;
|
|
margin-bottom: 8px;
|
|
}
|
|
|
|
.token-item:last-child {
|
|
margin-bottom: 0;
|
|
}
|
|
|
|
.token-info {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 4px;
|
|
}
|
|
|
|
.token-name {
|
|
font-size: 14px;
|
|
font-weight: 500;
|
|
color: ${cssManager.bdTheme('#18181b', '#fafafa')};
|
|
}
|
|
|
|
.token-meta {
|
|
font-size: 12px;
|
|
color: ${cssManager.bdTheme('#71717a', '#a1a1aa')};
|
|
}
|
|
|
|
.token-service {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
padding: 2px 8px;
|
|
background: ${cssManager.bdTheme('#dbeafe', 'rgba(59, 130, 246, 0.2)')};
|
|
color: ${cssManager.bdTheme('#2563eb', '#60a5fa')};
|
|
border-radius: 4px;
|
|
font-size: 12px;
|
|
font-weight: 500;
|
|
margin-right: 8px;
|
|
}
|
|
|
|
.token-actions {
|
|
display: flex;
|
|
gap: 8px;
|
|
}
|
|
|
|
.action-button {
|
|
padding: 6px 12px;
|
|
background: transparent;
|
|
border: 1px solid ${cssManager.bdTheme('#e4e4e7', '#27272a')};
|
|
border-radius: 4px;
|
|
font-size: 12px;
|
|
color: ${cssManager.bdTheme('#71717a', '#a1a1aa')};
|
|
cursor: pointer;
|
|
transition: all 200ms ease;
|
|
}
|
|
|
|
.action-button:hover {
|
|
background: ${cssManager.bdTheme('#ffffff', '#09090b')};
|
|
color: ${cssManager.bdTheme('#18181b', '#fafafa')};
|
|
}
|
|
|
|
.action-button.delete {
|
|
color: ${cssManager.bdTheme('#dc2626', '#ef4444')};
|
|
border-color: ${cssManager.bdTheme('#fee2e2', 'rgba(239, 68, 68, 0.3)')};
|
|
}
|
|
|
|
.action-button.delete:hover {
|
|
background: ${cssManager.bdTheme('#fee2e2', 'rgba(239, 68, 68, 0.2)')};
|
|
}
|
|
|
|
.empty-state {
|
|
padding: 32px 16px;
|
|
text-align: center;
|
|
}
|
|
|
|
.empty-text {
|
|
font-size: 14px;
|
|
color: ${cssManager.bdTheme('#71717a', '#a1a1aa')};
|
|
margin-bottom: 16px;
|
|
}
|
|
|
|
.empty-button {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 6px;
|
|
padding: 8px 14px;
|
|
background: ${cssManager.bdTheme('#ffffff', '#09090b')};
|
|
border: 1px solid ${cssManager.bdTheme('#e4e4e7', '#27272a')};
|
|
border-radius: 6px;
|
|
font-size: 13px;
|
|
font-weight: 500;
|
|
color: ${cssManager.bdTheme('#18181b', '#fafafa')};
|
|
cursor: pointer;
|
|
transition: all 200ms ease;
|
|
}
|
|
|
|
.empty-button:hover {
|
|
background: ${cssManager.bdTheme('#f4f4f5', '#18181b')};
|
|
}
|
|
`,
|
|
];
|
|
|
|
public render(): TemplateResult {
|
|
return html`
|
|
<div class="section">
|
|
<div class="section-header">
|
|
<div class="section-info">
|
|
<div class="section-title">Global Tokens</div>
|
|
<div class="section-subtitle">Tokens that can push images to multiple services</div>
|
|
</div>
|
|
<button class="create-button" @click=${() => this.handleCreate('global')}>
|
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
<line x1="12" y1="5" x2="12" y2="19"></line>
|
|
<line x1="5" y1="12" x2="19" y2="12"></line>
|
|
</svg>
|
|
Create Token
|
|
</button>
|
|
</div>
|
|
${this.globalTokens.length > 0 ? html`
|
|
<div class="token-list">
|
|
${this.globalTokens.map(token => this.renderToken(token))}
|
|
</div>
|
|
` : html`
|
|
<div class="empty-state">
|
|
<div class="empty-text">No global tokens created</div>
|
|
<button class="empty-button" @click=${() => this.handleCreate('global')}>Create Global Token</button>
|
|
</div>
|
|
`}
|
|
</div>
|
|
|
|
<div class="section">
|
|
<div class="section-header">
|
|
<div class="section-info">
|
|
<div class="section-title">CI Tokens (Service-specific)</div>
|
|
<div class="section-subtitle">Tokens tied to individual services for CI/CD pipelines</div>
|
|
</div>
|
|
<button class="create-button" @click=${() => this.handleCreate('ci')}>
|
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
<line x1="12" y1="5" x2="12" y2="19"></line>
|
|
<line x1="5" y1="12" x2="19" y2="12"></line>
|
|
</svg>
|
|
Create Token
|
|
</button>
|
|
</div>
|
|
${this.ciTokens.length > 0 ? html`
|
|
<div class="token-list">
|
|
${this.ciTokens.map(token => this.renderToken(token))}
|
|
</div>
|
|
` : html`
|
|
<div class="empty-state">
|
|
<div class="empty-text">No CI tokens created</div>
|
|
<button class="empty-button" @click=${() => this.handleCreate('ci')}>Create CI Token</button>
|
|
</div>
|
|
`}
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
private renderToken(token: IToken): TemplateResult {
|
|
return html`
|
|
<div class="token-item">
|
|
<div class="token-info">
|
|
<div class="token-name">${token.name}</div>
|
|
<div class="token-meta">
|
|
${token.service ? html`<span class="token-service">${token.service}</span>` : ''}
|
|
Created ${token.createdAt}
|
|
${token.lastUsed ? html` · Last used ${token.lastUsed}` : ''}
|
|
</div>
|
|
</div>
|
|
<div class="token-actions">
|
|
<button class="action-button" @click=${() => this.handleCopy(token)}>Copy</button>
|
|
<button class="action-button" @click=${() => this.handleRegenerate(token)}>Regenerate</button>
|
|
<button class="action-button delete" @click=${() => this.handleDelete(token)}>Delete</button>
|
|
</div>
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
private handleCreate(type: 'global' | 'ci') {
|
|
this.dispatchEvent(new CustomEvent('create', { detail: { type }, bubbles: true, composed: true }));
|
|
}
|
|
|
|
private handleCopy(token: IToken) {
|
|
this.dispatchEvent(new CustomEvent('copy', { detail: token, bubbles: true, composed: true }));
|
|
}
|
|
|
|
private handleRegenerate(token: IToken) {
|
|
this.dispatchEvent(new CustomEvent('regenerate', { detail: token, bubbles: true, composed: true }));
|
|
}
|
|
|
|
private handleDelete(token: IToken) {
|
|
this.dispatchEvent(new CustomEvent('delete', { detail: token, bubbles: true, composed: true }));
|
|
}
|
|
}
|