import * as plugins from '../../../plugins.js';
import * as appstate from '../../../appstate.js';
import { viewHostCss } from '../../shared/index.js';
import {
DeesElement,
customElement,
html,
state,
css,
cssManager,
type TemplateResult,
} from '@design.estate/dees-element';
@customElement('gitops-view-connections')
export class GitopsViewConnections extends DeesElement {
@state()
accessor connectionsState: appstate.IConnectionsState = {
connections: [],
activeConnectionId: null,
};
constructor() {
super();
const sub = appstate.connectionsStatePart
.select((s) => s)
.subscribe((s) => { this.connectionsState = s; });
this.rxSubscriptions.push(sub);
}
public static styles = [
cssManager.defaultStyles,
viewHostCss,
];
public render(): TemplateResult {
return html`
Connections
Manage your Gitea and GitLab provider connections
this.addConnection()}>Add Connection
this.refresh()}>Refresh
({
Name: item.name,
Type: item.providerType,
URL: item.baseUrl,
Status: item.status,
Created: new Date(item.createdAt).toLocaleDateString(),
})}
.dataActions=${[
{
name: 'Test',
iconName: 'lucide:plug',
action: async (item: any) => {
await appstate.connectionsStatePart.dispatchAction(
appstate.testConnectionAction,
{ connectionId: item.id },
);
},
},
{
name: 'Delete',
iconName: 'lucide:trash2',
action: async (item: any) => {
const confirmed = await plugins.deesCatalog.DeesModal.createAndShow({
heading: 'Delete Connection',
content: html`Are you sure you want to delete connection "${item.name}"?
`,
menuOptions: [
{ name: 'Cancel', action: async (modal: any) => { modal.destroy(); } },
{
name: 'Delete',
action: async (modal: any) => {
await appstate.connectionsStatePart.dispatchAction(
appstate.deleteConnectionAction,
{ connectionId: item.id },
);
modal.destroy();
},
},
],
});
},
},
]}
>
`;
}
async firstUpdated() {
await this.refresh();
}
private async refresh() {
await appstate.connectionsStatePart.dispatchAction(appstate.fetchConnectionsAction, null);
}
private async addConnection() {
await plugins.deesCatalog.DeesModal.createAndShow({
heading: 'Add Connection',
content: html`
`,
menuOptions: [
{ name: 'Cancel', action: async (modal: any) => { modal.destroy(); } },
{
name: 'Add',
action: async (modal: any) => {
const inputs = modal.shadowRoot.querySelectorAll('dees-input-text, dees-input-dropdown');
const data: any = {};
for (const input of inputs) {
if (input.key === 'providerType') {
data[input.key] = input.selectedOption?.key || 'gitea';
} else {
data[input.key] = input.value || '';
}
}
await appstate.connectionsStatePart.dispatchAction(
appstate.createConnectionAction,
{
name: data.name,
providerType: data.providerType,
baseUrl: data.baseUrl,
token: data.token,
},
);
modal.destroy();
},
},
],
});
}
}