forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…oproj#10145) Signed-off-by: krrrr38 <[email protected]> Signed-off-by: Isitha Subasinghe <[email protected]> Co-authored-by: krrrr38 <[email protected]> Co-authored-by: Alex Collins <[email protected]>
- Loading branch information
1 parent
d3eab6f
commit 7da30bd
Showing
2 changed files
with
132 additions
and
3 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
ui/src/app/workflows/components/workflow-logs-viewer/json-logs-field-selector.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import * as React from 'react'; | ||
import {TextInput} from '../../../shared/components/text-input'; | ||
|
||
export interface SelectedJsonFields { | ||
values: string[]; | ||
} | ||
|
||
export const JsonLogsFieldSelector = ({fields, onChange}: {fields: SelectedJsonFields; onChange: (v: string[]) => void}) => { | ||
const [inputFields, setInputFields] = React.useState(fields); | ||
const [key, setKey] = React.useState(''); | ||
const deleteItem = (k: string) => { | ||
const index = inputFields.values.indexOf(k, 0); | ||
if (index === -1) { | ||
return; | ||
} | ||
const values = inputFields.values.filter(v => v !== k); | ||
setInputFields({values}); | ||
onChange(values); | ||
}; | ||
const addItem = () => { | ||
if (!key || key.trim().length === 0) { | ||
return; | ||
} | ||
const index = inputFields.values.indexOf(key, 0); | ||
if (index !== -1) { | ||
return; | ||
} | ||
const values = [...inputFields.values, key]; | ||
setInputFields({values}); | ||
setKey(''); | ||
onChange(values); | ||
}; | ||
|
||
return ( | ||
<> | ||
{inputFields.values.map(k => ( | ||
<div className='row white-box__details-row' key={k}> | ||
<div className='columns small-10'>{k}</div> | ||
<div className='columns small-2'> | ||
<button onClick={() => deleteItem(k)}> | ||
<i className='fa fa-times-circle' /> | ||
</button> | ||
</div> | ||
</div> | ||
))} | ||
<div | ||
className='row white-box__details-row' | ||
onKeyPress={e => { | ||
if (e.key === 'Enter') { | ||
addItem(); | ||
} | ||
}}> | ||
<div className='columns small-10'> | ||
<TextInput value={key} onChange={setKey} placeholder='jsonPayload.message' /> | ||
</div> | ||
<div className='columns small-2'> | ||
<button onClick={() => addItem()}> | ||
<i className='fa fa-plus-circle' /> | ||
</button> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export const extractJsonValue = (obj: any, jsonpath: string): string | null => { | ||
const fields = jsonpath.split('.'); | ||
try { | ||
let target = obj; | ||
for (const field of fields) { | ||
target = target[field]; | ||
} | ||
return typeof target === 'string' ? target : JSON.stringify(target); | ||
} catch (e) { | ||
return null; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters