1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-19 13:29:41 +02:00
portainer/app/react/kubernetes/components/YAMLInspector.tsx
Ali 4e7d1c7088
Some checks are pending
ci / build_images (map[arch:amd64 platform:linux]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
refactor(app): migrate remaining form sections [EE-6231] (#10938)
2024-01-11 15:13:28 +13:00

72 lines
2.2 KiB
TypeScript

import { useMemo, useState } from 'react';
import YAML from 'yaml';
import { Minus, Plus } from 'lucide-react';
import { FeatureId } from '@/react/portainer/feature-flags/enums';
import { WebEditorForm } from '@@/WebEditorForm';
import { Button } from '@@/buttons';
import { BETeaserButton } from '@@/BETeaserButton';
type Props = {
identifier: string;
data: string;
hideMessage?: boolean;
};
export function YAMLInspector({ identifier, data, hideMessage }: Props) {
const [expanded, setExpanded] = useState(false);
const yaml = useMemo(() => cleanYamlUnwantedFields(data), [data]);
return (
<div>
<WebEditorForm
value={yaml}
placeholder={
hideMessage
? undefined
: 'Define or paste the content of your manifest here'
}
readonly
hideTitle
id={identifier}
yaml
height={expanded ? '800px' : '500px'}
onChange={() => {}} // all kube yaml inspectors in CE are read only
/>
<div className="flex items-center justify-between py-5">
<Button
icon={expanded ? Minus : Plus}
color="default"
className="!ml-0"
onClick={() => setExpanded(!expanded)}
>
{expanded ? 'Collapse' : 'Expand'}
</Button>
<BETeaserButton
featureId={FeatureId.K8S_EDIT_YAML}
heading="Apply YAML changes"
message="Applies any changes that you make in the YAML editor by calling the Kubernetes API to patch the relevant resources. Any resource removals or unexpected resource additions that you make in the YAML will be ignored. Note that editing is disabled for resources in namespaces marked as system."
buttonText="Apply changes"
/>
</div>
</div>
);
}
export function cleanYamlUnwantedFields(yml: string) {
try {
const ymls = yml.split('---');
const cleanYmls = ymls.map((yml) => {
const y = YAML.parse(yml);
if (y.metadata) {
const { managedFields, resourceVersion, ...metadata } = y.metadata;
y.metadata = metadata;
}
return YAML.stringify(y);
});
return cleanYmls.join('---\n');
} catch (e) {
return yml;
}
}