Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enhance Config Maps #3300

Merged
merged 5 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/resources/ConfigMaps/ConfigMapDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ export function ConfigMapDetails(props) {
));
};

const ConfigMapBinaryDataEditor = resource => {
const { binaryData } = resource;
return Object.keys(binaryData || {}).map(key => (
<ReadonlyEditorPanel
title={key}
value={binaryData[key]}
key={key + JSON.stringify(binaryData[key])}
isBase64={true}
/>
));
};

const customColumns = [
{
header: t('common.headers.owner'),
Expand All @@ -35,7 +47,7 @@ export function ConfigMapDetails(props) {

return (
<ResourceDetails
customComponents={[ConfigMapEditor]}
customComponents={[ConfigMapEditor, ConfigMapBinaryDataEditor]}
customColumns={customColumns}
description={ResourceDescription}
createResourceForm={ConfigMapCreate}
Expand Down
7 changes: 7 additions & 0 deletions src/shared/components/MonacoEditorESM/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ export function Editor({
}
}, [value, editorInstance, error]);

useEffect(() => {
if (prevValueRef.current !== value && readOnly) {
editorInstance.setValue(value);
prevValueRef.current = value;
}
}, [value, editorInstance, readOnly]);

useUpdateValueOnParentChange({
updateValueOnParentChange,
editorInstance,
Expand Down
56 changes: 49 additions & 7 deletions src/shared/components/ReadonlyEditorPanel.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,71 @@
import React from 'react';

import { EditorActions } from 'shared/contexts/YamlEditorContext/EditorActions';
import { Editor } from 'shared/components/MonacoEditorESM/Editor';
import { UI5Panel } from './UI5Panel/UI5Panel';
import { useTranslation } from 'react-i18next';
import { useState } from 'react';
import { Button } from '@ui5/webcomponents-react';
import { base64Decode } from 'shared/helpers';

export function ReadonlyEditorPanel({ title, value, editorProps, actions }) {
const [editor, setEditor] = React.useState(null);
export function ReadonlyEditorPanel({
title,
value,
editorProps,
actions,
isBase64 = false,
}) {
const { t } = useTranslation();
const [editor, setEditor] = useState(null);
const [isEncoded, setEncoded] = useState(true);
const [valueState, setValueState] = useState(value);

const decode = () => {
setEncoded(true);
setValueState(value);
};
const encode = () => {
setEncoded(false);
setValueState(base64Decode(value));
};

const options = {
minimap: {
enabled: false,
},
};

const headerActions =
actions ||
(isBase64 && (
<>
{actions && actions}
{isBase64 && (
<Button
design="Transparent"
icon={isEncoded ? 'show' : 'hide'}
disabled={!value}
onClick={() => {
return isEncoded ? encode() : decode();
}}
>
{isEncoded
? t('secrets.buttons.decode')
: t('secrets.buttons.encode')}
</Button>
)}
</>
));

return (
<UI5Panel title={title} headerActions={actions}>
<UI5Panel title={title} headerActions={headerActions}>
<EditorActions
val={value}
val={valueState}
editor={editor}
title={title}
saveDisabled={true}
/>
<Editor
height="20em"
value={value}
value={valueState}
options={options}
onMount={setEditor}
autocompletionDisabled
Expand Down
Loading