From 0f6607e7035560133c7e9b5494150e5fd0512176 Mon Sep 17 00:00:00 2001 From: Ali <83188384+testA113@users.noreply.github.com> Date: Thu, 17 Aug 2023 22:01:10 +1200 Subject: [PATCH] refactor(app): migrate the yaml inspector to react [EE-5356] (#10058) Co-authored-by: testa113 --- .../yaml-inspector/yamlInspector.html | 34 ---------- .../yaml-inspector/yamlInspector.js | 8 --- .../yaml-inspector/yamlInspectorController.js | 46 ------------- app/kubernetes/react/components/index.ts | 8 +++ .../views/applications/edit/application.html | 2 +- app/kubernetes/views/cluster/node/node.html | 2 +- .../configmap/edit/configMap.html | 2 +- .../configurations/secret/edit/secret.html | 2 +- .../resource-pools/edit/resourcePool.html | 2 +- app/kubernetes/views/volumes/edit/volume.html | 2 +- app/react/components/CodeEditor.tsx | 28 ++++---- app/react/components/WebEditorForm.tsx | 3 + .../ApplicationServicesTable.tsx | 4 +- .../kubernetes/components/YAMLInspector.tsx | 67 +++++++++++++++++++ 14 files changed, 98 insertions(+), 112 deletions(-) delete mode 100644 app/kubernetes/components/yaml-inspector/yamlInspector.html delete mode 100644 app/kubernetes/components/yaml-inspector/yamlInspector.js delete mode 100644 app/kubernetes/components/yaml-inspector/yamlInspectorController.js create mode 100644 app/react/kubernetes/components/YAMLInspector.tsx diff --git a/app/kubernetes/components/yaml-inspector/yamlInspector.html b/app/kubernetes/components/yaml-inspector/yamlInspector.html deleted file mode 100644 index 4ef25e5ec..000000000 --- a/app/kubernetes/components/yaml-inspector/yamlInspector.html +++ /dev/null @@ -1,34 +0,0 @@ -
- - -
- - - Copy to clipboard - - - - - {{ $ctrl.expanded ? 'Collapse' : 'Expand' }} - - - - -
-
diff --git a/app/kubernetes/components/yaml-inspector/yamlInspector.js b/app/kubernetes/components/yaml-inspector/yamlInspector.js deleted file mode 100644 index c84bd8828..000000000 --- a/app/kubernetes/components/yaml-inspector/yamlInspector.js +++ /dev/null @@ -1,8 +0,0 @@ -angular.module('portainer.kubernetes').component('kubernetesYamlInspector', { - templateUrl: './yamlInspector.html', - controller: 'KubernetesYamlInspectorController', - bindings: { - key: '@', - data: '<', - }, -}); diff --git a/app/kubernetes/components/yaml-inspector/yamlInspectorController.js b/app/kubernetes/components/yaml-inspector/yamlInspectorController.js deleted file mode 100644 index cd2bf00c8..000000000 --- a/app/kubernetes/components/yaml-inspector/yamlInspectorController.js +++ /dev/null @@ -1,46 +0,0 @@ -import angular from 'angular'; -import YAML from 'yaml'; -import { FeatureId } from '@/react/portainer/feature-flags/enums'; - -class KubernetesYamlInspectorController { - /* @ngInject */ - - constructor(clipboard) { - this.clipboard = clipboard; - this.expanded = false; - } - - cleanYamlUnwantedFields(yml) { - try { - const ymls = yml.split('---'); - const cleanYmls = ymls.map((yml) => { - const y = YAML.parse(yml); - if (y.metadata) { - delete y.metadata.managedFields; - delete y.metadata.resourceVersion; - } - return YAML.stringify(y); - }); - return cleanYmls.join('---\n'); - } catch (e) { - return yml; - } - } - - copyYAML() { - this.clipboard.copyText(this.data); - $('#copyNotificationYAML').show().fadeOut(2500); - } - - toggleYAMLInspectorExpansion() { - this.expanded = !this.expanded; - } - - $onInit() { - this.data = this.cleanYamlUnwantedFields(this.data); - this.limitedFeature = FeatureId.K8S_EDIT_YAML; - } -} - -export default KubernetesYamlInspectorController; -angular.module('portainer.kubernetes').controller('KubernetesYamlInspectorController', KubernetesYamlInspectorController); diff --git a/app/kubernetes/react/components/index.ts b/app/kubernetes/react/components/index.ts index 1ee99dd0c..f745f280c 100644 --- a/app/kubernetes/react/components/index.ts +++ b/app/kubernetes/react/components/index.ts @@ -21,6 +21,7 @@ import { ApplicationContainersDatatable } from '@/react/kubernetes/applications/ import { withFormValidation } from '@/react-tools/withFormValidation'; import { withCurrentUser } from '@/react-tools/withCurrentUser'; import { PlacementsDatatable } from '@/react/kubernetes/applications/ItemView/PlacementsDatatable'; +import { YAMLInspector } from '@/react/kubernetes/components/YAMLInspector'; export const ngModule = angular .module('portainer.kubernetes.react.components', []) @@ -96,6 +97,13 @@ export const ngModule = angular 'supportGlobalDeployment', ]) ) + .component( + 'kubeYamlInspector', + r2a(withUIRouter(withReactQuery(withCurrentUser(YAMLInspector))), [ + 'identifier', + 'data', + ]) + ) .component( 'applicationSummaryWidget', r2a( diff --git a/app/kubernetes/views/applications/edit/application.html b/app/kubernetes/views/applications/edit/application.html index f14be606d..daf140a83 100644 --- a/app/kubernetes/views/applications/edit/application.html +++ b/app/kubernetes/views/applications/edit/application.html @@ -62,7 +62,7 @@ YAML
- +
diff --git a/app/kubernetes/views/cluster/node/node.html b/app/kubernetes/views/cluster/node/node.html index 8a2e34e19..ab5bc6d9f 100644 --- a/app/kubernetes/views/cluster/node/node.html +++ b/app/kubernetes/views/cluster/node/node.html @@ -247,7 +247,7 @@
YAML
- +
diff --git a/app/kubernetes/views/configurations/configmap/edit/configMap.html b/app/kubernetes/views/configurations/configmap/edit/configMap.html index 63197417b..ab47c209d 100644 --- a/app/kubernetes/views/configurations/configmap/edit/configMap.html +++ b/app/kubernetes/views/configurations/configmap/edit/configMap.html @@ -75,7 +75,7 @@ YAML
- +
diff --git a/app/kubernetes/views/configurations/secret/edit/secret.html b/app/kubernetes/views/configurations/secret/edit/secret.html index b4103f3b2..0834393be 100644 --- a/app/kubernetes/views/configurations/secret/edit/secret.html +++ b/app/kubernetes/views/configurations/secret/edit/secret.html @@ -82,7 +82,7 @@ YAML
- +
diff --git a/app/kubernetes/views/resource-pools/edit/resourcePool.html b/app/kubernetes/views/resource-pools/edit/resourcePool.html index af7ca5e4d..86ab683ad 100644 --- a/app/kubernetes/views/resource-pools/edit/resourcePool.html +++ b/app/kubernetes/views/resource-pools/edit/resourcePool.html @@ -305,7 +305,7 @@ YAML
- +
diff --git a/app/kubernetes/views/volumes/edit/volume.html b/app/kubernetes/views/volumes/edit/volume.html index 9f3eb7df4..43570ba0f 100644 --- a/app/kubernetes/views/volumes/edit/volume.html +++ b/app/kubernetes/views/volumes/edit/volume.html @@ -164,7 +164,7 @@ YAML
- +
diff --git a/app/react/components/CodeEditor.tsx b/app/react/components/CodeEditor.tsx index 7fb36746c..03f17ed62 100644 --- a/app/react/components/CodeEditor.tsx +++ b/app/react/components/CodeEditor.tsx @@ -84,23 +84,19 @@ export function CodeEditor({ return ( <> -
-
-
- {!!placeholder && {placeholder}} -
- -
- - Copy to clipboard - -
+
+
+ {!!placeholder && {placeholder}}
+ + + Copy to clipboard +
) { return (
@@ -98,6 +100,7 @@ export function WebEditorForm({ yaml={yaml} value={value} onChange={onChange} + height={height} />
diff --git a/app/react/kubernetes/applications/DetailsView/ApplicationDetailsWidget/ApplicationServicesTable.tsx b/app/react/kubernetes/applications/DetailsView/ApplicationDetailsWidget/ApplicationServicesTable.tsx index 8fe49d507..1b7b053fc 100644 --- a/app/react/kubernetes/applications/DetailsView/ApplicationDetailsWidget/ApplicationServicesTable.tsx +++ b/app/react/kubernetes/applications/DetailsView/ApplicationDetailsWidget/ApplicationServicesTable.tsx @@ -82,12 +82,12 @@ export function ApplicationServicesTable({ )} {service.spec?.ports?.map((port) => ( -
{port.targetPort}
+
{port.targetPort}
))} {service.spec?.ports?.map((port) => ( -
+
{environment?.PublicURL && port.nodePort && ( cleanYamlUnwantedFields(data), [data]); + + return ( +
+ {}} // all kube yaml inspectors in CE are read only + /> +
+ + +
+
+ ); +} + +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; + } +}