chore: lint
This commit is contained in:
@@ -18,15 +18,15 @@ interface AddWhereCondModalProps {
|
|||||||
index: number;
|
index: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AddWhereCondModal = ({isOpen, onClose, pair, index}: AddWhereCondModalProps) => {
|
export const AddWhereCondModal = ({ isOpen, onClose, pair, index }: AddWhereCondModalProps) => {
|
||||||
const [whereProp, setWhereProp] = React.useState<string>('');
|
const [whereProp, setWhereProp] = React.useState<string>('');
|
||||||
const [additionalSettings, setAdditionalSettings] = React.useState<string>('');
|
const [additionalSettings, setAdditionalSettings] = React.useState<string>('');
|
||||||
const [newValue, setNewValue] = React.useState<any>('');
|
const [newValue, setNewValue] = React.useState<any>('');
|
||||||
const [checked, setChecked] = React.useState<boolean[]>(new Array(Object.keys(pair.where).length).fill(false));
|
const [checked, setChecked] = React.useState<boolean[]>(new Array(Object.keys(pair.where).length).fill(false));
|
||||||
|
|
||||||
const keyValueFormRef = useRef<{getObject: () => object}>(null);
|
const keyValueFormRef = useRef<{ getObject: () => object }>(null);
|
||||||
|
|
||||||
const {socket} = useSocketStore();
|
const { socket } = useSocketStore();
|
||||||
|
|
||||||
const handlePropSelect = (event: SelectChangeEvent<string>) => {
|
const handlePropSelect = (event: SelectChangeEvent<string>) => {
|
||||||
setWhereProp(event.target.value);
|
setWhereProp(event.target.value);
|
||||||
@@ -38,55 +38,56 @@ export const AddWhereCondModal = ({isOpen, onClose, pair, index}: AddWhereCondMo
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
switch (whereProp) {
|
switch (whereProp) {
|
||||||
case 'url':
|
case 'url':
|
||||||
if (additionalSettings === 'string'){
|
if (additionalSettings === 'string') {
|
||||||
pair.where.url = newValue;
|
pair.where.url = newValue;
|
||||||
} else {
|
} else {
|
||||||
pair.where.url = { $regex: newValue };
|
pair.where.url = { $regex: newValue };
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'selectors':
|
case 'selectors':
|
||||||
pair.where.selectors = newValue;
|
pair.where.selectors = newValue;
|
||||||
break;
|
break;
|
||||||
case 'cookies':
|
case 'cookies':
|
||||||
pair.where.cookies = keyValueFormRef.current?.getObject() as Record<string,string>
|
pair.where.cookies = keyValueFormRef.current?.getObject() as Record<string, string>
|
||||||
break;
|
break;
|
||||||
case 'before':
|
case 'before':
|
||||||
pair.where.$before = newValue;
|
pair.where.$before = newValue;
|
||||||
break;
|
break;
|
||||||
case 'after':
|
case 'after':
|
||||||
pair.where.$after = newValue;
|
pair.where.$after = newValue;
|
||||||
break;
|
break;
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
const booleanArr = [];
|
const booleanArr = [];
|
||||||
const deleteKeys: string[] = [];
|
const deleteKeys: string[] = [];
|
||||||
for (let i = 0; i < checked.length; i++) {
|
for (let i = 0; i < checked.length; i++) {
|
||||||
if (checked[i]) {
|
if (checked[i]) {
|
||||||
if (Object.keys(pair.where)[i]) {
|
if (Object.keys(pair.where)[i]) {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
if (pair.where[Object.keys(pair.where)[i]]) {
|
if (pair.where[Object.keys(pair.where)[i]]) {
|
||||||
booleanArr.push({
|
booleanArr.push({
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
[Object.keys(pair.where)[i]]: pair.where[Object.keys(pair.where)[i]]});
|
[Object.keys(pair.where)[i]]: pair.where[Object.keys(pair.where)[i]]
|
||||||
}
|
});
|
||||||
deleteKeys.push(Object.keys(pair.where)[i]);
|
|
||||||
}
|
}
|
||||||
|
deleteKeys.push(Object.keys(pair.where)[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// @ts-ignore
|
}
|
||||||
deleteKeys.forEach((key: string) => delete pair.where[key]);
|
// @ts-ignore
|
||||||
//@ts-ignore
|
deleteKeys.forEach((key: string) => delete pair.where[key]);
|
||||||
pair.where[`$${additionalSettings}`] = booleanArr;
|
//@ts-ignore
|
||||||
break;
|
pair.where[`$${additionalSettings}`] = booleanArr;
|
||||||
default:
|
break;
|
||||||
return;
|
default:
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
onClose();
|
onClose();
|
||||||
setWhereProp('');
|
setWhereProp('');
|
||||||
setAdditionalSettings('');
|
setAdditionalSettings('');
|
||||||
setNewValue('');
|
setNewValue('');
|
||||||
socket?.emit('updatePair', {index: index-1, pair: pair});
|
socket?.emit('updatePair', { index: index - 1, pair: pair });
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -97,23 +98,23 @@ export const AddWhereCondModal = ({isOpen, onClose, pair, index}: AddWhereCondMo
|
|||||||
onClose();
|
onClose();
|
||||||
}} modalStyle={modalStyle}>
|
}} modalStyle={modalStyle}>
|
||||||
<div>
|
<div>
|
||||||
<Typography sx={{margin: '20px 0px'}}>Add where condition:</Typography>
|
<Typography sx={{ margin: '20px 0px' }}>Add where condition:</Typography>
|
||||||
<div style={{margin:'8px'}}>
|
<div style={{ margin: '8px' }}>
|
||||||
<MuiDropdown
|
<MuiDropdown
|
||||||
id="whereProp"
|
id="whereProp"
|
||||||
label="Condition"
|
label="Condition"
|
||||||
value={whereProp}
|
value={whereProp}
|
||||||
handleSelect={handlePropSelect}>
|
handleSelect={handlePropSelect}>
|
||||||
<MenuItem value="url">url</MenuItem>
|
<MenuItem value="url">url</MenuItem>
|
||||||
<MenuItem value="selectors">selectors</MenuItem>
|
<MenuItem value="selectors">selectors</MenuItem>
|
||||||
<MenuItem value="cookies">cookies</MenuItem>
|
<MenuItem value="cookies">cookies</MenuItem>
|
||||||
<MenuItem value="before">before</MenuItem>
|
<MenuItem value="before">before</MenuItem>
|
||||||
<MenuItem value="after">after</MenuItem>
|
<MenuItem value="after">after</MenuItem>
|
||||||
<MenuItem value="boolean">boolean logic</MenuItem>
|
<MenuItem value="boolean">boolean logic</MenuItem>
|
||||||
</MuiDropdown>
|
</MuiDropdown>
|
||||||
</div>
|
</div>
|
||||||
{whereProp ?
|
{whereProp ?
|
||||||
<div style={{margin: '8px'}}>
|
<div style={{ margin: '8px' }}>
|
||||||
<DisplayConditionSettings
|
<DisplayConditionSettings
|
||||||
whereProp={whereProp} additionalSettings={additionalSettings} setAdditionalSettings={setAdditionalSettings}
|
whereProp={whereProp} additionalSettings={additionalSettings} setAdditionalSettings={setAdditionalSettings}
|
||||||
newValue={newValue} setNewValue={setNewValue} checked={checked} setChecked={setChecked}
|
newValue={newValue} setNewValue={setNewValue} checked={checked} setChecked={setChecked}
|
||||||
@@ -145,7 +146,7 @@ export const modalStyle = {
|
|||||||
width: '30%',
|
width: '30%',
|
||||||
backgroundColor: 'background.paper',
|
backgroundColor: 'background.paper',
|
||||||
p: 4,
|
p: 4,
|
||||||
height:'fit-content',
|
height: 'fit-content',
|
||||||
display:'block',
|
display: 'block',
|
||||||
padding: '20px',
|
padding: '20px',
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user