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 (
{}} // all kube yaml inspectors in CE are read only />
); } 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; } }