Skip to content

Commit

Permalink
feat: Allow markdown title and description in KeyValueEditor
Browse files Browse the repository at this point in the history
Signed-off-by: panicboat <[email protected]>
  • Loading branch information
panicboat committed Nov 25, 2024
1 parent db6206a commit 095d686
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
8 changes: 8 additions & 0 deletions ui/src/shared/components/editors/key-value-editor.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@import 'node_modules/argo-ui/src/styles/config';

.markdown-rows-name {
line-height: 1.5em;
display: inline-block;
vertical-align: middle;
white-space: pre-line;
}
17 changes: 15 additions & 2 deletions ui/src/shared/components/editors/key-value-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@ import * as React from 'react';
import {useState} from 'react';

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

require('./key-value-editor.scss');

interface KeyValues {
[key: string]: string;
}

export function KeyValueEditor({onChange, keyValues = {}, hide}: {keyValues: KeyValues; onChange: (value: KeyValues) => void; hide?: (key: string) => boolean}) {
interface KeyValueEditorProps {
keyValues: KeyValues;
onChange: (value: KeyValues) => void;
hide?: (key: string) => boolean;
source?: string;
}

export function KeyValueEditor({onChange, keyValues = {}, hide, source }: KeyValueEditorProps) {
const [name, setName] = useState('');
const [value, setValue] = useState('');

Expand All @@ -32,7 +43,9 @@ export function KeyValueEditor({onChange, keyValues = {}, hide}: {keyValues: Key
.map(([k, v]) => (
<div className='row white-box__details-row' key={k}>
<div className='columns small-4'>{k}</div>
<div className='columns small-6'>{v}</div>
<div className='columns small-6 markdown-rows-name'>
{source == 'annotations' && [ANNOTATION_DESCRIPTION, ANNOTATION_TITLE].indexOf(k) !== -1 ? <SuspenseReactMarkdownGfm markdown={v} /> : v}
</div>
<div className='columns small-2'>
<button onClick={() => deleteItem(k)}>
<i className='fa fa-times-circle' />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ export function LabelsAndAnnotationsEditor({value, onChange}: {value: kubernetes
<>
<div className='white-box'>
<h5>Labels</h5>
<KeyValueEditor keyValues={value && value.labels} onChange={labels => onChange({...value, labels})} />
<KeyValueEditor keyValues={value && value.labels} onChange={labels => onChange({...value, labels})} source={'labels'} />
</div>
<div className='white-box'>
<h5>Annotations</h5>
<KeyValueEditor
keyValues={value && value.annotations}
onChange={annotations => onChange({...value, annotations})}
hide={key => key === 'kubectl.kubernetes.io/last-applied-configuration'}
source={'annotations'}
/>
</div>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function WorkflowParametersEditor<T extends WorkflowSpec>(props: {value:
);
props.onChange(props.value);
}}
source={'parameters'}
/>
</div>
</>
Expand Down

0 comments on commit 095d686

Please sign in to comment.