chore: lint
This commit is contained in:
@@ -15,17 +15,17 @@ interface AddWhatCondModalProps {
|
|||||||
index: number;
|
index: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AddWhatCondModal = ({isOpen, onClose, pair, index}: AddWhatCondModalProps) => {
|
export const AddWhatCondModal = ({ isOpen, onClose, pair, index }: AddWhatCondModalProps) => {
|
||||||
const [action, setAction] = React.useState<string>('');
|
const [action, setAction] = React.useState<string>('');
|
||||||
const [objectIndex, setObjectIndex] = React.useState<number>(0);
|
const [objectIndex, setObjectIndex] = React.useState<number>(0);
|
||||||
const [args, setArgs] = React.useState<({type: string, value: (string|number|object|unknown)})[]>([]);
|
const [args, setArgs] = React.useState<({ type: string, value: (string | number | object | unknown) })[]>([]);
|
||||||
|
|
||||||
const objectRefs = useRef<({getObject: () => object}|unknown)[]>([]);
|
const objectRefs = useRef<({ getObject: () => object } | unknown)[]>([]);
|
||||||
|
|
||||||
const {socket} = useSocketStore();
|
const { socket } = useSocketStore();
|
||||||
|
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
const argsArray: (string|number|object|unknown)[] = [];
|
const argsArray: (string | number | object | unknown)[] = [];
|
||||||
args.map((arg, index) => {
|
args.map((arg, index) => {
|
||||||
switch (arg.type) {
|
switch (arg.type) {
|
||||||
case 'string':
|
case 'string':
|
||||||
@@ -44,7 +44,7 @@ export const AddWhatCondModal = ({isOpen, onClose, pair, index}: AddWhatCondModa
|
|||||||
action,
|
action,
|
||||||
args: argsArray,
|
args: argsArray,
|
||||||
})
|
})
|
||||||
socket?.emit('updatePair', {index: index-1, pair: pair});
|
socket?.emit('updatePair', { index: index - 1, pair: pair });
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -53,8 +53,8 @@ export const AddWhatCondModal = ({isOpen, onClose, pair, index}: AddWhatCondModa
|
|||||||
onClose();
|
onClose();
|
||||||
}} modalStyle={modalStyle}>
|
}} modalStyle={modalStyle}>
|
||||||
<div>
|
<div>
|
||||||
<Typography sx={{margin: '20px 0px'}}>Add what condition:</Typography>
|
<Typography sx={{ margin: '20px 0px' }}>Add what condition:</Typography>
|
||||||
<div style={{margin:'8px'}}>
|
<div style={{ margin: '8px' }}>
|
||||||
<Typography>Action:</Typography>
|
<Typography>Action:</Typography>
|
||||||
<TextField
|
<TextField
|
||||||
size='small'
|
size='small'
|
||||||
@@ -64,56 +64,57 @@ export const AddWhatCondModal = ({isOpen, onClose, pair, index}: AddWhatCondModa
|
|||||||
label='action'
|
label='action'
|
||||||
/>
|
/>
|
||||||
<div>
|
<div>
|
||||||
<Typography>Add new argument of type:</Typography>
|
<Typography>Add new argument of type:</Typography>
|
||||||
<Button onClick={() => setArgs([...args,{type: 'string', value: null}]) }>string</Button>
|
<Button onClick={() => setArgs([...args, { type: 'string', value: null }])}>string</Button>
|
||||||
<Button onClick={() => setArgs([...args,{type: 'number', value: null}]) }>number</Button>
|
<Button onClick={() => setArgs([...args, { type: 'number', value: null }])}>number</Button>
|
||||||
<Button onClick={() => {
|
<Button onClick={() => {
|
||||||
setArgs([...args,{type: 'object', value: objectIndex}])
|
setArgs([...args, { type: 'object', value: objectIndex }])
|
||||||
setObjectIndex(objectIndex+1);
|
setObjectIndex(objectIndex + 1);
|
||||||
} }>object</Button>
|
}}>object</Button>
|
||||||
</div>
|
</div>
|
||||||
<Typography>args:</Typography>
|
<Typography>args:</Typography>
|
||||||
{args.map((arg, index) => {
|
{args.map((arg, index) => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return (
|
return (
|
||||||
<div style={{border:'solid 1px gray', padding: '10px', display:'flex', flexDirection:'row', alignItems:'center' }}
|
<div style={{ border: 'solid 1px gray', padding: '10px', display: 'flex', flexDirection: 'row', alignItems: 'center' }}
|
||||||
key={`wrapper-for-${arg.type}-${index}`}>
|
key={`wrapper-for-${arg.type}-${index}`}>
|
||||||
<ClearButton handleClick={() => {
|
<ClearButton handleClick={() => {
|
||||||
args.splice(index,1);
|
args.splice(index, 1);
|
||||||
setArgs([...args]);
|
setArgs([...args]);
|
||||||
}}/>
|
}} />
|
||||||
<Typography sx={{margin: '5px'}} key={`number-argument-${arg.type}-${index}`}>{index}: </Typography>
|
<Typography sx={{ margin: '5px' }} key={`number-argument-${arg.type}-${index}`}>{index}: </Typography>
|
||||||
{arg.type === 'string' ?
|
{arg.type === 'string' ?
|
||||||
<TextField
|
|
||||||
size='small'
|
|
||||||
type="string"
|
|
||||||
onChange={(e) => setArgs([
|
|
||||||
...args.slice(0, index),
|
|
||||||
{type: arg.type, value: e.target.value},
|
|
||||||
...args.slice(index + 1)
|
|
||||||
])}
|
|
||||||
value={args[index].value || ''}
|
|
||||||
label="string"
|
|
||||||
key={`arg-${arg.type}-${index}`}
|
|
||||||
/> : arg.type === 'number' ?
|
|
||||||
<TextField
|
<TextField
|
||||||
key={`arg-${arg.type}-${index}`}
|
|
||||||
size='small'
|
size='small'
|
||||||
type="number"
|
type="string"
|
||||||
onChange={(e) => setArgs([
|
onChange={(e) => setArgs([
|
||||||
...args.slice(0, index),
|
...args.slice(0, index),
|
||||||
{type: arg.type, value: Number(e.target.value)},
|
{ type: arg.type, value: e.target.value },
|
||||||
...args.slice(index + 1)
|
...args.slice(index + 1)
|
||||||
])}
|
])}
|
||||||
value={args[index].value || ''}
|
value={args[index].value || ''}
|
||||||
label="number"
|
label="string"
|
||||||
/> :
|
key={`arg-${arg.type}-${index}`}
|
||||||
<KeyValueForm ref={el =>
|
/> : arg.type === 'number' ?
|
||||||
//@ts-ignore
|
<TextField
|
||||||
objectRefs.current[arg.value] = el} key={`arg-${arg.type}-${index}`}/>
|
key={`arg-${arg.type}-${index}`}
|
||||||
}
|
size='small'
|
||||||
</div>
|
type="number"
|
||||||
)})}
|
onChange={(e) => setArgs([
|
||||||
|
...args.slice(0, index),
|
||||||
|
{ type: arg.type, value: Number(e.target.value) },
|
||||||
|
...args.slice(index + 1)
|
||||||
|
])}
|
||||||
|
value={args[index].value || ''}
|
||||||
|
label="number"
|
||||||
|
/> :
|
||||||
|
<KeyValueForm ref={el =>
|
||||||
|
//@ts-ignore
|
||||||
|
objectRefs.current[arg.value] = el} key={`arg-${arg.type}-${index}`} />
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
})}
|
||||||
<Button
|
<Button
|
||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
@@ -127,7 +128,7 @@ export const AddWhatCondModal = ({isOpen, onClose, pair, index}: AddWhatCondModa
|
|||||||
{"Add Condition"}
|
{"Add Condition"}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</GenericModal>
|
</GenericModal>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user