@backstage/plugin-kubernetes-react 0.6.1-next.0 → 0.6.1-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -2,11 +2,25 @@ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
|
2
2
|
import { CodeSnippet } from '@backstage/core-components';
|
|
3
3
|
import FormControlLabel from '@material-ui/core/FormControlLabel';
|
|
4
4
|
import Switch from '@material-ui/core/Switch';
|
|
5
|
-
import jsyaml from 'js-yaml';
|
|
5
|
+
import * as jsyaml from 'js-yaml';
|
|
6
6
|
import { useState } from 'react';
|
|
7
7
|
import { useTranslationRef } from '@backstage/core-plugin-api/alpha';
|
|
8
8
|
import { kubernetesReactTranslationRef } from '../../translation.esm.js';
|
|
9
9
|
|
|
10
|
+
function removeManagedFields(value) {
|
|
11
|
+
if (Array.isArray(value)) {
|
|
12
|
+
return value.map(removeManagedFields);
|
|
13
|
+
}
|
|
14
|
+
if (value && typeof value === "object") {
|
|
15
|
+
const prototype = Object.getPrototypeOf(value);
|
|
16
|
+
if (prototype === Object.prototype || prototype === null) {
|
|
17
|
+
return Object.fromEntries(
|
|
18
|
+
Object.entries(value).filter(([key]) => key !== "managedFields").map(([key, entry]) => [key, removeManagedFields(entry)])
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
10
24
|
const ManifestYaml = ({ object }) => {
|
|
11
25
|
const { t } = useTranslationRef(kubernetesReactTranslationRef);
|
|
12
26
|
const [managedFields, setManagedFields] = useState(false);
|
|
@@ -31,17 +45,7 @@ const ManifestYaml = ({ object }) => {
|
|
|
31
45
|
CodeSnippet,
|
|
32
46
|
{
|
|
33
47
|
language: "yaml",
|
|
34
|
-
text: jsyaml.dump(object
|
|
35
|
-
// NOTE: this will remove any field called `managedFields`
|
|
36
|
-
// not just the metadata one
|
|
37
|
-
// TODO: @mclarke make this only remove the `metadata.managedFields`
|
|
38
|
-
replacer: (key, value) => {
|
|
39
|
-
if (!managedFields) {
|
|
40
|
-
return key === "managedFields" ? void 0 : value;
|
|
41
|
-
}
|
|
42
|
-
return value;
|
|
43
|
-
}
|
|
44
|
-
})
|
|
48
|
+
text: jsyaml.dump(managedFields ? object : removeManagedFields(object))
|
|
45
49
|
}
|
|
46
50
|
)
|
|
47
51
|
] });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ManifestYaml.esm.js","sources":["../../../src/components/KubernetesDrawer/ManifestYaml.tsx"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { CodeSnippet } from '@backstage/core-components';\nimport FormControlLabel from '@material-ui/core/FormControlLabel';\nimport Switch from '@material-ui/core/Switch';\nimport jsyaml from 'js-yaml';\nimport { useState } from 'react';\nimport { useTranslationRef } from '@backstage/core-plugin-api/alpha';\nimport { kubernetesReactTranslationRef } from '../../translation';\n\n/**\n * Props of ManifestYaml\n *\n * @public\n */\nexport interface ManifestYamlProps {\n object: object;\n}\n\n/**\n * Renders a Kubernetes object as a YAML code snippet\n *\n * @public\n */\nexport const ManifestYaml = ({ object }: ManifestYamlProps) => {\n const { t } = useTranslationRef(kubernetesReactTranslationRef);\n // Toggle whether the Kubernetes resource managed fields should be shown in\n // the YAML display. This toggle is only available when the YAML is being\n // shown because managed fields are never visible in the structured display.\n const [managedFields, setManagedFields] = useState<boolean>(false);\n return (\n <>\n <FormControlLabel\n control={\n <Switch\n checked={managedFields}\n onChange={event => {\n setManagedFields(event.target.checked);\n }}\n name={t('kubernetesDrawer.managedFields')}\n />\n }\n label={t('kubernetesDrawer.managedFields')}\n />\n <CodeSnippet\n language=\"yaml\"\n text={jsyaml.dump(
|
|
1
|
+
{"version":3,"file":"ManifestYaml.esm.js","sources":["../../../src/components/KubernetesDrawer/ManifestYaml.tsx"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { CodeSnippet } from '@backstage/core-components';\nimport FormControlLabel from '@material-ui/core/FormControlLabel';\nimport Switch from '@material-ui/core/Switch';\nimport * as jsyaml from 'js-yaml';\nimport { useState } from 'react';\nimport { useTranslationRef } from '@backstage/core-plugin-api/alpha';\nimport { kubernetesReactTranslationRef } from '../../translation';\n\n/**\n * Props of ManifestYaml\n *\n * @public\n */\nexport interface ManifestYamlProps {\n object: object;\n}\n\nfunction removeManagedFields(value: unknown): unknown {\n if (Array.isArray(value)) {\n return value.map(removeManagedFields);\n }\n if (value && typeof value === 'object') {\n const prototype = Object.getPrototypeOf(value);\n if (prototype === Object.prototype || prototype === null) {\n return Object.fromEntries(\n Object.entries(value)\n .filter(([key]) => key !== 'managedFields')\n .map(([key, entry]) => [key, removeManagedFields(entry)]),\n );\n }\n }\n return value;\n}\n\n/**\n * Renders a Kubernetes object as a YAML code snippet, hiding managed fields by\n * default while allowing them to be shown with a toggle.\n *\n * @public\n */\nexport const ManifestYaml = ({ object }: ManifestYamlProps) => {\n const { t } = useTranslationRef(kubernetesReactTranslationRef);\n // Toggle whether the Kubernetes resource managed fields should be shown in\n // the YAML display. This toggle is only available when the YAML is being\n // shown because managed fields are never visible in the structured display.\n const [managedFields, setManagedFields] = useState<boolean>(false);\n return (\n <>\n <FormControlLabel\n control={\n <Switch\n checked={managedFields}\n onChange={event => {\n setManagedFields(event.target.checked);\n }}\n name={t('kubernetesDrawer.managedFields')}\n />\n }\n label={t('kubernetesDrawer.managedFields')}\n />\n <CodeSnippet\n language=\"yaml\"\n text={jsyaml.dump(managedFields ? object : removeManagedFields(object))}\n />\n </>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;AAgCA,SAAS,oBAAoB,KAAA,EAAyB;AACpD,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACxB,IAAA,OAAO,KAAA,CAAM,IAAI,mBAAmB,CAAA;AAAA,EACtC;AACA,EAAA,IAAI,KAAA,IAAS,OAAO,KAAA,KAAU,QAAA,EAAU;AACtC,IAAA,MAAM,SAAA,GAAY,MAAA,CAAO,cAAA,CAAe,KAAK,CAAA;AAC7C,IAAA,IAAI,SAAA,KAAc,MAAA,CAAO,SAAA,IAAa,SAAA,KAAc,IAAA,EAAM;AACxD,MAAA,OAAO,MAAA,CAAO,WAAA;AAAA,QACZ,MAAA,CAAO,QAAQ,KAAK,CAAA,CACjB,OAAO,CAAC,CAAC,GAAG,CAAA,KAAM,GAAA,KAAQ,eAAe,EACzC,GAAA,CAAI,CAAC,CAAC,GAAA,EAAK,KAAK,CAAA,KAAM,CAAC,GAAA,EAAK,mBAAA,CAAoB,KAAK,CAAC,CAAC;AAAA,OAC5D;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,KAAA;AACT;AAQO,MAAM,YAAA,GAAe,CAAC,EAAE,MAAA,EAAO,KAAyB;AAC7D,EAAA,MAAM,EAAE,CAAA,EAAE,GAAI,iBAAA,CAAkB,6BAA6B,CAAA;AAI7D,EAAA,MAAM,CAAC,aAAA,EAAe,gBAAgB,CAAA,GAAI,SAAkB,KAAK,CAAA;AACjE,EAAA,uBACE,IAAA,CAAA,QAAA,EAAA,EACE,QAAA,EAAA;AAAA,oBAAA,GAAA;AAAA,MAAC,gBAAA;AAAA,MAAA;AAAA,QACC,OAAA,kBACE,GAAA;AAAA,UAAC,MAAA;AAAA,UAAA;AAAA,YACC,OAAA,EAAS,aAAA;AAAA,YACT,UAAU,CAAA,KAAA,KAAS;AACjB,cAAA,gBAAA,CAAiB,KAAA,CAAM,OAAO,OAAO,CAAA;AAAA,YACvC,CAAA;AAAA,YACA,IAAA,EAAM,EAAE,gCAAgC;AAAA;AAAA,SAC1C;AAAA,QAEF,KAAA,EAAO,EAAE,gCAAgC;AAAA;AAAA,KAC3C;AAAA,oBACA,GAAA;AAAA,MAAC,WAAA;AAAA,MAAA;AAAA,QACC,QAAA,EAAS,MAAA;AAAA,QACT,MAAM,MAAA,CAAO,IAAA,CAAK,gBAAgB,MAAA,GAAS,mBAAA,CAAoB,MAAM,CAAC;AAAA;AAAA;AACxE,GAAA,EACF,CAAA;AAEJ;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -585,7 +585,8 @@ interface ManifestYamlProps {
|
|
|
585
585
|
object: object;
|
|
586
586
|
}
|
|
587
587
|
/**
|
|
588
|
-
* Renders a Kubernetes object as a YAML code snippet
|
|
588
|
+
* Renders a Kubernetes object as a YAML code snippet, hiding managed fields by
|
|
589
|
+
* default while allowing them to be shown with a toggle.
|
|
589
590
|
*
|
|
590
591
|
* @public
|
|
591
592
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-kubernetes-react",
|
|
3
|
-
"version": "0.6.1-next.
|
|
3
|
+
"version": "0.6.1-next.1",
|
|
4
4
|
"description": "Web library for the kubernetes-react plugin",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "web-library",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@backstage/catalog-model": "1.10.2-next.0",
|
|
66
|
-
"@backstage/core-components": "0.18.15-next.
|
|
66
|
+
"@backstage/core-components": "0.18.15-next.2",
|
|
67
67
|
"@backstage/core-plugin-api": "1.12.11-next.0",
|
|
68
68
|
"@backstage/errors": "1.3.2-next.0",
|
|
69
69
|
"@backstage/plugin-kubernetes-common": "0.9.14-next.0",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"@xterm/addon-fit": "^0.11.0",
|
|
79
79
|
"@xterm/xterm": "^5.5.0",
|
|
80
80
|
"cronstrue": "^2.32.0",
|
|
81
|
-
"js-yaml": "^
|
|
81
|
+
"js-yaml": "^5.0.0",
|
|
82
82
|
"kubernetes-models": "^4.3.1",
|
|
83
83
|
"lodash": "^4.17.21",
|
|
84
84
|
"luxon": "^3.0.0",
|