// static/js/components/resourceForms.js
import { cleanupConfigStore } from '../store/configStore.js';
import { addCluster } from '../api/clustersService.js';
import { addListener, appendFilterChain } from '../api/listenersService.js';
import { addSecret } from '../api/secretsService.js';
import { addExtensionConfig } from '../api/extensionConfigsService.js';
import { renderClustersTable } from './clustersTable.js';
import { renderListenersTable } from './listenersTable.js';
import { renderSecretsTable } from './secretsTable.js';
import { renderExtensionConfigsTable } from './extensionConfigsTable.js';
import { hideModal } from './modals.js';
export async function submitCluster() {
const yaml = document.getElementById('add-cluster-yaml-input').value.trim();
const upsert = document.getElementById('add-cluster-upsert-flag')?.checked;
if (!yaml) return alert('Please paste the cluster YAML configuration.');
try {
await addCluster(yaml, upsert);
alert('Cluster successfully added!');
hideModal('addClusterModal');
cleanupConfigStore();
renderClustersTable();
} catch (error) {
alert(`Failed to add cluster. Error: ${error.message}`);
}
}
export async function submitListener() {
const yaml = document.getElementById('add-listener-yaml-input').value.trim();
const upsert = document.getElementById('add-listener-upsert-flag')?.checked;
if (!yaml) return alert('Please paste the listener YAML configuration.');
try {
await addListener(yaml, upsert);
alert('Listener successfully added!');
hideModal('addListenerModal');
cleanupConfigStore();
renderListenersTable();
} catch (error) {
alert(`Failed to add listener. Error: ${error.message}`);
}
}
export async function submitFilterChain() {
const listenerName = document.getElementById('add-fc-listener-name').value;
const yaml = document.getElementById('add-fc-yaml-input').value.trim();
const upsert = document.getElementById('add-filter-chain-upsert-flag')?.checked;
if (!yaml) return alert('Please paste the filter chain YAML configuration.');
try {
await appendFilterChain(listenerName, yaml, upsert);
alert(`Successfully updated filter chain for '${listenerName}'.`);
hideModal('addFilterChainModal');
cleanupConfigStore();
renderListenersTable();
} catch (error) {
alert(`Failed to append filter chain. Error: ${error.message}`);
}
}
export async function submitSecret() {
const yaml = document.getElementById('add-secret-yaml-input').value.trim();
const upsert = document.getElementById('add-secret-upsert-flag')?.checked;
if (!yaml) return alert('Please paste the secret YAML configuration.');
try {
await addSecret(yaml, upsert);
alert('Secret successfully added!');
hideModal('addSecretModal');
cleanupConfigStore();
renderSecretsTable();
} catch (error) {
alert(`Failed to add secret. Error: ${error.message}`);
}
}
export async function submitExtensionConfig() {
const yaml = document.getElementById('add-extension-config-yaml-input').value.trim();
const upsert = document.getElementById('add-extension-config-upsert-flag')?.checked;
if (!yaml) return alert('Please paste the ExtensionConfig YAML configuration.');
try {
await addExtensionConfig(yaml, upsert);
alert('ExtensionConfig successfully added!');
hideModal('addExtensionConfigModal');
cleanupConfigStore();
renderExtensionConfigsTable();
} catch (error) {
alert(`Failed to add ExtensionConfig. Error: ${error.message}`);
}
}