Skip to content

Commit ef41f83

Browse files
authored
feat: Allow markdown title and description in KeyValueEditor (#13935)
Signed-off-by: panicboat <panicboat@gmail.com>
1 parent 14dedc8 commit ef41f83

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@import 'node_modules/argo-ui/src/styles/config';
2+
3+
.markdown-rows-name {
4+
line-height: 1.5em;
5+
display: inline-block;
6+
vertical-align: middle;
7+
white-space: pre-line;
8+
}

ui/src/shared/components/editors/key-value-editor.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
import * as React from 'react';
22
import {useState} from 'react';
33

4+
import {ANNOTATION_DESCRIPTION, ANNOTATION_TITLE} from '../../annotations';
5+
import {SuspenseReactMarkdownGfm} from '../suspense-react-markdown-gfm';
46
import {TextInput} from '../text-input';
57

8+
require('./key-value-editor.scss');
9+
610
interface KeyValues {
711
[key: string]: string;
812
}
913

10-
export function KeyValueEditor({onChange, keyValues = {}, hide}: {keyValues: KeyValues; onChange: (value: KeyValues) => void; hide?: (key: string) => boolean}) {
14+
interface KeyValueEditorProps {
15+
keyValues: KeyValues;
16+
onChange: (value: KeyValues) => void;
17+
hide?: (key: string) => boolean;
18+
source?: string;
19+
}
20+
21+
export function KeyValueEditor({onChange, keyValues = {}, hide, source}: KeyValueEditorProps) {
1122
const [name, setName] = useState('');
1223
const [value, setValue] = useState('');
1324

@@ -32,7 +43,9 @@ export function KeyValueEditor({onChange, keyValues = {}, hide}: {keyValues: Key
3243
.map(([k, v]) => (
3344
<div className='row white-box__details-row' key={k}>
3445
<div className='columns small-4'>{k}</div>
35-
<div className='columns small-6'>{v}</div>
46+
<div className='columns small-6 markdown-rows-name'>
47+
{source == 'annotations' && [ANNOTATION_DESCRIPTION, ANNOTATION_TITLE].indexOf(k) !== -1 ? <SuspenseReactMarkdownGfm markdown={v} /> : v}
48+
</div>
3649
<div className='columns small-2'>
3750
<button onClick={() => deleteItem(k)}>
3851
<i className='fa fa-times-circle' />

ui/src/shared/components/editors/labels-and-annotations-editor.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ export function LabelsAndAnnotationsEditor({value, onChange}: {value: kubernetes
88
<>
99
<div className='white-box'>
1010
<h5>Labels</h5>
11-
<KeyValueEditor keyValues={value && value.labels} onChange={labels => onChange({...value, labels})} />
11+
<KeyValueEditor keyValues={value && value.labels} onChange={labels => onChange({...value, labels})} source={'labels'} />
1212
</div>
1313
<div className='white-box'>
1414
<h5>Annotations</h5>
1515
<KeyValueEditor
1616
keyValues={value && value.annotations}
1717
onChange={annotations => onChange({...value, annotations})}
1818
hide={key => key === 'kubectl.kubernetes.io/last-applied-configuration'}
19+
source={'annotations'}
1920
/>
2021
</div>
2122
</>

ui/src/shared/components/editors/workflow-parameters-editor.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export function WorkflowParametersEditor<T extends WorkflowSpec>(props: {value:
3737
);
3838
props.onChange(props.value);
3939
}}
40+
source={'parameters'}
4041
/>
4142
</div>
4243
</>

0 commit comments

Comments
 (0)