import * as plugins from '../plugins.js'; import * as shared from '../elements/shared/index.js'; import { DeesElement, customElement, html, state, css, cssManager, } from '@design.estate/dees-element'; import * as appstate from '../appstate.js'; @customElement('cloudly-view-externalregistries') export class CloudlyViewExternalRegistries extends DeesElement { @state() private data: appstate.IDataState = { secretGroups: [], secretBundles: [], externalRegistries: [], }; constructor() { super(); const subscription = appstate.dataState .select((stateArg) => stateArg) .subscribe((dataArg) => { this.data = dataArg; }); this.rxSubscriptions.push(subscription); } async connectedCallback() { super.connectedCallback(); // Load external registries await appstate.dataState.dispatchAction(appstate.getAllDataAction, {}); } public static styles = [ cssManager.defaultStyles, shared.viewHostCss, css` .status-badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 0.85em; font-weight: 500; color: white; } .status-active { background: #4CAF50; } .status-inactive { background: #9E9E9E; } .status-error { background: #f44336; } .status-unverified { background: #FF9800; } .type-badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 0.85em; font-weight: 500; color: white; } .type-docker { background: #2196F3; } .type-npm { background: #CB3837; } .default-badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 0.85em; font-weight: 500; background: #673AB7; color: white; margin-left: 8px; } `, ]; public render() { return html` External Registries { return { Name: html`${registry.data.name}${registry.data.isDefault ? html`DEFAULT` : ''}`, Type: html`${registry.data.type.toUpperCase()}`, URL: registry.data.url, Username: registry.data.username, Namespace: registry.data.namespace || '-', Status: html`${(registry.data.status || 'unverified').toUpperCase()}`, 'Last Verified': registry.data.lastVerified ? new Date(registry.data.lastVerified).toLocaleString() : 'Never', }; }} .dataActions=${[ { name: 'Add Registry', iconName: 'plus', type: ['header', 'footer'], actionFunc: async (dataActionArg) => { const modal = await plugins.deesCatalog.DeesModal.createAndShow({ heading: 'Add External Registry', content: html` `, menuOptions: [ { name: 'Create Registry', action: async (modalArg) => { const form = modalArg.shadowRoot.querySelector('dees-form') as any; const formData = await form.gatherData(); await appstate.dataState.dispatchAction(appstate.createExternalRegistryAction, { registryData: { type: formData.type, name: formData.name, url: formData.url, username: formData.username, password: formData.password, namespace: formData.namespace || undefined, description: formData.description || undefined, authType: formData.authType, isDefault: formData.isDefault, insecure: formData.insecure, }, }); await modalArg.destroy(); }, }, { name: 'Cancel', action: async (modalArg) => { await modalArg.destroy(); }, }, ], }); }, }, { name: 'Edit', iconName: 'edit', type: ['contextmenu', 'inRow'], actionFunc: async (actionDataArg) => { const registry = actionDataArg.item as plugins.interfaces.data.IExternalRegistry; const modal = await plugins.deesCatalog.DeesModal.createAndShow({ heading: `Edit Registry: ${registry.data.name}`, content: html` `, menuOptions: [ { name: 'Update Registry', action: async (modalArg) => { const form = modalArg.shadowRoot.querySelector('dees-form') as any; const formData = await form.gatherData(); const updateData: any = { type: formData.type, name: formData.name, url: formData.url, username: formData.username, namespace: formData.namespace || undefined, description: formData.description || undefined, authType: formData.authType, isDefault: formData.isDefault, insecure: formData.insecure, }; // Only include password if it was changed if (formData.password) { updateData.password = formData.password; } else { updateData.password = registry.data.password; } await appstate.dataState.dispatchAction(appstate.updateExternalRegistryAction, { registryId: registry.id, registryData: updateData, }); await modalArg.destroy(); }, }, { name: 'Cancel', action: async (modalArg) => { await modalArg.destroy(); }, }, ], }); }, }, { name: 'Test Connection', iconName: 'check-circle', type: ['contextmenu'], actionFunc: async (actionDataArg) => { const registry = actionDataArg.item as plugins.interfaces.data.IExternalRegistry; // Show loading modal const loadingModal = await plugins.deesCatalog.DeesModal.createAndShow({ heading: 'Testing Registry Connection', content: html`

Testing connection to ${registry.data.name}...

`, menuOptions: [], }); // Test the connection await appstate.dataState.dispatchAction(appstate.verifyExternalRegistryAction, { registryId: registry.id, }); // Close loading modal await loadingModal.destroy(); // Get updated registry const updatedRegistry = this.data.externalRegistries?.find(r => r.id === registry.id); // Show result modal const resultModal = await plugins.deesCatalog.DeesModal.createAndShow({ heading: 'Connection Test Result', content: html`
${updatedRegistry?.data.status === 'active' ? html`

Connection successful!

` : html`

Connection failed!

${updatedRegistry?.data.lastError ? html`

Error: ${updatedRegistry.data.lastError}

` : ''} `}
`, menuOptions: [ { name: 'OK', action: async (modalArg) => { await modalArg.destroy(); }, }, ], }); }, }, { name: 'Delete', iconName: 'trash', type: ['contextmenu'], actionFunc: async (actionDataArg) => { const registry = actionDataArg.item as plugins.interfaces.data.IExternalRegistry; plugins.deesCatalog.DeesModal.createAndShow({ heading: `Delete Registry: ${registry.data.name}`, content: html`

Do you really want to delete this external registry?

This will remove all stored credentials and configuration.

${registry.data.name} (${registry.data.url})
`, menuOptions: [ { name: 'Cancel', action: async (modalArg) => { await modalArg.destroy(); }, }, { name: 'Delete', action: async (modalArg) => { await appstate.dataState.dispatchAction(appstate.deleteExternalRegistryAction, { registryId: registry.id, }); await modalArg.destroy(); }, }, ], }); }, }, ] as plugins.deesCatalog.ITableAction[]} >
`; } }