-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from DrDroidLab/@feature/support-dd-query-ui
add dd support
- Loading branch information
Showing
11 changed files
with
698 additions
and
397 deletions.
There are no files selected for viewing
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,107 @@ | ||
import React from 'react'; | ||
import { useDispatch } from 'react-redux'; | ||
import { updateStep } from '../../../store/features/playbook/playbookSlice.ts'; | ||
import SelectComponent from '../../SelectComponent'; | ||
import ValueComponent from '../../ValueComponent'; | ||
import styles from './index.module.css'; | ||
|
||
export default function OptionRender({ data, removeErrors, task, stepIndex }) { | ||
const dispatch = useDispatch(); | ||
|
||
const handleChange = (...args) => { | ||
if (data.handleChange) { | ||
data.handleChange(...args); | ||
} else { | ||
dispatch(updateStep({ index: stepIndex, key: data.key, value: args[0] })); | ||
} | ||
|
||
removeErrors(data.key); | ||
}; | ||
|
||
const handleTextAreaChange = e => { | ||
const val = e.target.value; | ||
if (data.handleChange) { | ||
data.handleChange(e); | ||
} else { | ||
dispatch(updateStep({ index: stepIndex, key: data.key, value: val })); | ||
} | ||
|
||
removeErrors(data.key); | ||
}; | ||
|
||
const error = data.key ? task.showError && !data.selected && !task[`${data.key}`] : false; | ||
|
||
switch (data.type) { | ||
case 'options': | ||
if (!(data.options?.length > 0)) return; | ||
return ( | ||
<SelectComponent | ||
key={data.key} | ||
data={data.options} | ||
placeholder={`Select ${data.label}`} | ||
onSelectionChange={handleChange} | ||
selected={data.selected ?? task[`${data.key}`]} | ||
searchable={true} | ||
disabled={data.disabled} | ||
error={error} | ||
{...data.additionalProps} | ||
/> | ||
); | ||
case 'text-row': | ||
case 'text': | ||
return ( | ||
<div | ||
className={`flex ${ | ||
data.type === 'text' ? 'flex-col' : 'flex-row items-center justify-center gap-2' | ||
}`} | ||
> | ||
<p | ||
style={{ | ||
marginTop: data.type === 'text' ? '10px' : '', | ||
fontSize: '13px', | ||
color: '#676666' | ||
}} | ||
> | ||
<b>{data.label}</b> | ||
</p> | ||
<ValueComponent | ||
key={data.key} | ||
placeHolder={`Enter ${data?.label}`} | ||
valueType={'STRING'} | ||
onValueChange={handleChange} | ||
value={data.selected || task[`${data.key}`]} | ||
error={error} | ||
{...data.additionalProps} | ||
/> | ||
</div> | ||
); | ||
case 'multiline': | ||
return ( | ||
<div key={data.key} style={{ display: 'flex', flexDirection: 'column', width: '100%' }}> | ||
<p style={{ marginTop: '10px', fontSize: '13px', color: '#676666' }}> | ||
<b>{data.label}</b> | ||
</p> | ||
<textarea | ||
className={styles['notes']} | ||
rows={4} | ||
value={data.value ?? task[`${data.key}`]} | ||
onChange={handleTextAreaChange} | ||
disabled={data.disabled} | ||
style={error ? { borderColor: 'red' } : {}} | ||
/> | ||
</div> | ||
); | ||
|
||
case 'button': | ||
return ( | ||
<button | ||
className="p-1 border-2 w-fit border-purple-500 hover:bg-purple-500 text-purple-500 hover:text-white transition-all rounded cursor-pointer leading-none" | ||
onClick={data.handleClick} | ||
> | ||
{data.label} | ||
</button> | ||
); | ||
default: | ||
return; | ||
} | ||
} |
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
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,58 @@ | ||
import React from 'react'; | ||
import SelectComponent from '../../SelectComponent'; | ||
import styles from './index.module.css'; | ||
import { useDispatch } from 'react-redux'; | ||
import { setSelectedGrafanaOptions } from '../../../store/features/playbook/playbookSlice.ts'; | ||
import ValueComponent from '../../ValueComponent'; | ||
|
||
function VariablesBox({ task, stepIndex }) { | ||
const dispatch = useDispatch(); | ||
const handleVariableChange = (_, val) => { | ||
dispatch(setSelectedGrafanaOptions({ index: stepIndex, option: val })); | ||
}; | ||
|
||
return ( | ||
<div className={styles['variables-box']}> | ||
{task?.options && task?.options?.length > 0 && ( | ||
<div style={{ display: 'flex', gap: '5px', flexDirection: 'row' }}> | ||
<p style={{ fontSize: '12px', color: 'darkgray', marginTop: '5px' }}>Variables</p> | ||
{task?.options.map((option, i) => { | ||
return ( | ||
<div key={stepIndex} style={{ display: 'flex', gap: '5px' }}> | ||
{option?.values?.length > 0 ? ( | ||
<SelectComponent | ||
data={option?.values.map((e, i) => { | ||
return { | ||
id: e, | ||
label: e, | ||
option | ||
}; | ||
})} | ||
placeholder={`Select ${option?.label?.label}`} | ||
onSelectionChange={handleVariableChange} | ||
selected={task?.selectedOptions ? task?.selectedOptions[option?.variable] : ''} | ||
searchable={true} | ||
/> | ||
) : ( | ||
<ValueComponent | ||
placeHolder={`Enter ${option?.variable}`} | ||
valueType={'STRING'} | ||
onValueChange={val => | ||
handleVariableChange({ | ||
id: val, | ||
label: option.variable | ||
}) | ||
} | ||
value={task?.selectedOptions ? task?.selectedOptions[option?.variable] : ''} | ||
/> | ||
)} | ||
</div> | ||
); | ||
})} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
export default VariablesBox; |
Oops, something went wrong.