@kinvolk/headlamp-plugin
Version:
The needed infrastructure for building Headlamp plugins.
93 lines (92 loc) • 4.5 kB
TypeScript
import { TextFieldProps } from '@mui/material/TextField';
/** An option for a select field. */
export interface SelectOption {
/** The value stored in the resource object. */
value: string;
/** Display label shown in the dropdown. */
label: string;
}
/** A single field within a form section. */
export interface FormField {
/** Unique key for this field. */
key: string;
/** Dot-notation path in the resource object, e.g. "metadata.name". */
path: string;
/** Display label for the field. */
label: string;
/** Input type – defaults to 'text'. */
type?: 'text' | 'labels' | 'select' | 'containers' | 'namespace';
/** Whether the field is required. */
required?: boolean;
/** Helper text displayed below the field. */
helperText?: string;
/** Options for 'select' type fields. */
options?: SelectOption[];
/** Extra top margin (theme spacing units) to visually separate from the field above. */
spacingTop?: number;
}
/** A labelled group of fields. */
export interface FormSection {
/** Section heading displayed above the fields. */
title: string;
/** Fields rendered inside this section. */
fields: FormField[];
}
/** Props for {@link CreateResourceForm}. */
export interface CreateResourceFormProps {
/** Sections containing the form field descriptors. */
sections: FormSection[];
/** The resource as a plain JS object. */
resource: Record<string, any>;
/** Called with the updated resource object when any field changes. */
onChange: (resource: Record<string, any>) => void;
}
/** Data-driven resource creation form. Renders labelled sections of typed
* fields (text, labels, containers, namespace, select) from a declarative
* descriptor and keeps a plain JS resource object in sync via `onChange`. */
export default function CreateResourceForm(props: CreateResourceFormProps): import("react/jsx-runtime").JSX.Element;
/** Pre-styled outlined TextField matching the app's search input style. */
export declare function FormTextField(props: TextFieldProps): import("react/jsx-runtime").JSX.Element;
export interface NamespaceTextFieldProps {
value: string;
onChange: (namespace: string) => void;
label?: string;
required?: boolean;
helperText?: string;
}
/** Autocomplete namespace selector that fetches existing namespaces from the cluster. */
export declare function NamespaceTextField(props: NamespaceTextFieldProps): import("react/jsx-runtime").JSX.Element;
export interface LabelTextFieldProps {
/** Current label map. */
value: Record<string, string>;
/** Called with the updated label map when labels change. */
onChange: (labels: Record<string, string>) => void;
/** Input label text. */
label?: string;
}
/** Editable key/value rows for Kubernetes labels.
* Existing labels are shown as editable rows. Click + New Label to add a placeholder row. */
export declare function LabelTextField(props: LabelTextFieldProps): import("react/jsx-runtime").JSX.Element;
/** Props for {@link ContainerTextField}.
* Each entry in `value` represents a container spec with fields like
* `name`, `image`, `imagePullPolicy`, and `ports`. */
export interface ContainerTextFieldProps {
/** Current list of container objects. */
value: Record<string, any>[];
/** Called with the updated container list when any container is added, removed, or edited. */
onChange: (containers: Record<string, any>[]) => void;
/** Group label displayed above the container rows. */
label?: string;
}
/** Editable list of containers (name + image + pull policy per row).
* Fill in the bottom inputs and click + to add. Existing containers appear
* above as editable rows with × to remove. */
export declare function ContainerTextField(props: ContainerTextFieldProps): import("react/jsx-runtime").JSX.Element;
/** Safely parse a YAML string into an object, returning {} on failure. */
export declare function parseYaml(input: string | undefined): Record<string, any>;
/** Convert a labels map to a display string, e.g. `{a: "1", b: "2"}` → `"a=1, b=2"`. */
export declare function labelsToString(labels: Record<string, string> | undefined): string;
/** Parse a comma-separated `key=value` string into a labels map. */
export declare function parseLabelsString(input: string): Record<string, string>;
/** Serialize a JS value to a YAML string using js-yaml. */
export declare function toYamlString(obj: unknown): string;