fix: use proper Headlamp plugin settings interface
SettingsPage now accepts PluginSettingsProps (data, onDataChange) and is registered directly as a component (not wrapped in function). This matches the pattern used in headlamp-polaris-plugin. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -13,15 +13,27 @@ import { PluginConfig } from '../types';
|
|||||||
import { ControllerStatus } from './ControllerStatus';
|
import { ControllerStatus } from './ControllerStatus';
|
||||||
import { VersionWarning } from './VersionWarning';
|
import { VersionWarning } from './VersionWarning';
|
||||||
|
|
||||||
|
interface PluginSettingsProps {
|
||||||
|
data?: { [key: string]: string | number | boolean };
|
||||||
|
onDataChange?: (data: { [key: string]: string | number | boolean }) => void;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Settings page component
|
* Settings page component
|
||||||
*/
|
*/
|
||||||
export function SettingsPage() {
|
export function SettingsPage(props: PluginSettingsProps) {
|
||||||
const [config, setConfig] = React.useState<PluginConfig>(getPluginConfig());
|
const { data, onDataChange } = props;
|
||||||
|
const storedConfig = getPluginConfig();
|
||||||
|
const [config, setConfig] = React.useState<PluginConfig>({
|
||||||
|
controllerName: (data?.controllerName as string) ?? storedConfig.controllerName,
|
||||||
|
controllerNamespace: (data?.controllerNamespace as string) ?? storedConfig.controllerNamespace,
|
||||||
|
controllerPort: (data?.controllerPort as number) ?? storedConfig.controllerPort,
|
||||||
|
});
|
||||||
const { enqueueSnackbar } = useSnackbar();
|
const { enqueueSnackbar } = useSnackbar();
|
||||||
|
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
savePluginConfig(config);
|
savePluginConfig(config);
|
||||||
|
onDataChange?.(config as unknown as { [key: string]: string | number | boolean });
|
||||||
enqueueSnackbar('Settings saved successfully', { variant: 'success' });
|
enqueueSnackbar('Settings saved successfully', { variant: 'success' });
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -73,7 +85,11 @@ export function SettingsPage() {
|
|||||||
fullWidth
|
fullWidth
|
||||||
label="Controller Name"
|
label="Controller Name"
|
||||||
value={config.controllerName}
|
value={config.controllerName}
|
||||||
onChange={e => setConfig({ ...config, controllerName: e.target.value })}
|
onChange={e => {
|
||||||
|
const newConfig = { ...config, controllerName: e.target.value };
|
||||||
|
setConfig(newConfig);
|
||||||
|
onDataChange?.(newConfig as unknown as { [key: string]: string | number | boolean });
|
||||||
|
}}
|
||||||
margin="normal"
|
margin="normal"
|
||||||
helperText="Name of the sealed-secrets-controller deployment/service"
|
helperText="Name of the sealed-secrets-controller deployment/service"
|
||||||
inputProps={{
|
inputProps={{
|
||||||
@@ -89,7 +105,11 @@ export function SettingsPage() {
|
|||||||
fullWidth
|
fullWidth
|
||||||
label="Controller Namespace"
|
label="Controller Namespace"
|
||||||
value={config.controllerNamespace}
|
value={config.controllerNamespace}
|
||||||
onChange={e => setConfig({ ...config, controllerNamespace: e.target.value })}
|
onChange={e => {
|
||||||
|
const newConfig = { ...config, controllerNamespace: e.target.value };
|
||||||
|
setConfig(newConfig);
|
||||||
|
onDataChange?.(newConfig as unknown as { [key: string]: string | number | boolean });
|
||||||
|
}}
|
||||||
margin="normal"
|
margin="normal"
|
||||||
helperText="Namespace where the controller is installed"
|
helperText="Namespace where the controller is installed"
|
||||||
inputProps={{
|
inputProps={{
|
||||||
@@ -106,7 +126,11 @@ export function SettingsPage() {
|
|||||||
label="Controller Port"
|
label="Controller Port"
|
||||||
type="number"
|
type="number"
|
||||||
value={config.controllerPort}
|
value={config.controllerPort}
|
||||||
onChange={e => setConfig({ ...config, controllerPort: parseInt(e.target.value, 10) })}
|
onChange={e => {
|
||||||
|
const newConfig = { ...config, controllerPort: parseInt(e.target.value, 10) };
|
||||||
|
setConfig(newConfig);
|
||||||
|
onDataChange?.(newConfig as unknown as { [key: string]: string | number | boolean });
|
||||||
|
}}
|
||||||
margin="normal"
|
margin="normal"
|
||||||
helperText="HTTP port of the controller service"
|
helperText="HTTP port of the controller service"
|
||||||
inputProps={{
|
inputProps={{
|
||||||
|
|||||||
@@ -104,14 +104,6 @@ registerDetailsViewSection(({ resource }) => {
|
|||||||
/**
|
/**
|
||||||
* Register plugin settings
|
* Register plugin settings
|
||||||
*
|
*
|
||||||
* Settings will appear in Settings → Plugins → Sealed Secrets
|
* Settings will appear in Settings → Plugins → sealed-secrets
|
||||||
*/
|
*/
|
||||||
registerPluginSettings(
|
registerPluginSettings('sealed-secrets', SettingsPage, true);
|
||||||
'Sealed Secrets',
|
|
||||||
() => (
|
|
||||||
<GenericErrorBoundary>
|
|
||||||
<SettingsPage />
|
|
||||||
</GenericErrorBoundary>
|
|
||||||
),
|
|
||||||
true // Display save button
|
|
||||||
);
|
|
||||||
|
|||||||
Reference in New Issue
Block a user