mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 15:59:41 +02:00
refactor(app): migrate the yaml inspector to react [EE-5356] (#10058)
Co-authored-by: testa113 <testa113>
This commit is contained in:
parent
23295d2736
commit
0f6607e703
14 changed files with 98 additions and 112 deletions
67
app/react/kubernetes/components/YAMLInspector.tsx
Normal file
67
app/react/kubernetes/components/YAMLInspector.tsx
Normal file
|
@ -0,0 +1,67 @@
|
|||
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;
|
||||
};
|
||||
|
||||
export function YAMLInspector({ identifier, data }: Props) {
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
const yaml = useMemo(() => cleanYamlUnwantedFields(data), [data]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<WebEditorForm
|
||||
value={yaml}
|
||||
placeholder="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>
|
||||
);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue