Merge pull request #30 from amhsirak/develop

feat: list step new field addition & bulk discard
This commit is contained in:
Karishma Shukla
2024-09-14 08:39:06 +05:30
committed by GitHub
3 changed files with 40 additions and 14 deletions

View File

@@ -216,7 +216,7 @@ export const BrowserWindow = () => {
const newField: TextStep = { const newField: TextStep = {
id: Date.now(), id: Date.now(),
type: 'text', type: 'text',
label: ``, label: `Label ${Object.keys(fields).length + 1}`,
data: data, data: data,
selectorObj: { selectorObj: {
selector: highlighterData.selector, selector: highlighterData.selector,
@@ -228,14 +228,14 @@ export const BrowserWindow = () => {
setFields(prevFields => { setFields(prevFields => {
const updatedFields = { const updatedFields = {
...prevFields, ...prevFields,
[newField.label]: newField [newField.id]: newField
}; };
console.log(updatedFields) console.log(updatedFields)
return updatedFields; return updatedFields;
}); });
if (listSelector) { if (listSelector) {
addListStep(listSelector, { ...fields, [newField.label]: newField }, currentListId, { type: '', selector: paginationSelector }); addListStep(listSelector, { ...fields, [newField.id]: newField }, currentListId, { type: '', selector: paginationSelector });
} }
} else { } else {
@@ -276,7 +276,7 @@ export const BrowserWindow = () => {
const newField: TextStep = { const newField: TextStep = {
id: Date.now(), id: Date.now(),
type: 'text', type: 'text',
label: ``, label: `Label ${Object.keys(fields).length + 1}`,
data: data, data: data,
selectorObj: { selectorObj: {
selector: selectedElement.selector, selector: selectedElement.selector,
@@ -288,17 +288,14 @@ export const BrowserWindow = () => {
setFields(prevFields => { setFields(prevFields => {
const updatedFields = { const updatedFields = {
...prevFields, ...prevFields,
[newField.label]: newField [newField.id]: newField
}; };
console.log(updatedFields)
return updatedFields; return updatedFields;
}); });
if (listSelector) { if (listSelector) {
addListStep(listSelector, { ...fields, [newField.label]: newField }, currentListId, { type: '', selector: paginationSelector }); addListStep(listSelector, { ...fields, [newField.id]: newField }, currentListId, { type: '', selector: paginationSelector });
} }
} }
} }
} }

View File

@@ -41,6 +41,10 @@ export const RightSidePanel: React.FC<RightSidePanelProps> = ({ onFinishCapture
const handleTextLabelChange = (id: number, label: string, listId?: number, fieldKey?: string) => { const handleTextLabelChange = (id: number, label: string, listId?: number, fieldKey?: string) => {
if (listId !== undefined && fieldKey !== undefined) { if (listId !== undefined && fieldKey !== undefined) {
// Prevent editing if the field is confirmed
if (confirmedListTextFields[listId]?.[fieldKey]) {
return;
}
// This is a text field within a list step // This is a text field within a list step
updateListTextFieldLabel(listId, fieldKey, label); updateListTextFieldLabel(listId, fieldKey, label);
} else { } else {
@@ -162,7 +166,7 @@ export const RightSidePanel: React.FC<RightSidePanelProps> = ({ onFinishCapture
return settings; return settings;
}, [browserSteps, paginationType, limitType, customLimit]); }, [browserSteps, paginationType, limitType, customLimit]);
const resetListState = useCallback(() => { const resetListState = useCallback(() => {
setShowPaginationOptions(false); setShowPaginationOptions(false);
@@ -238,10 +242,33 @@ export const RightSidePanel: React.FC<RightSidePanelProps> = ({ onFinishCapture
const handlePaginationSettingSelect = (option: PaginationType) => { const handlePaginationSettingSelect = (option: PaginationType) => {
updatePaginationType(option); updatePaginationType(option);
if (['clickNext', 'clickLoadMore'].includes(option)) {
}
}; };
const discardGetText = useCallback(() => {
stopGetText();
browserSteps.forEach(step => {
if (step.type === 'text') {
deleteBrowserStep(step.id);
}
});
setTextLabels({});
setErrors({});
setConfirmedTextSteps({});
notify('info', 'Capture Text steps discarded');
}, [browserSteps, stopGetText, deleteBrowserStep]);
const discardGetList = useCallback(() => {
stopGetList();
browserSteps.forEach(step => {
if (step.type === 'list') {
deleteBrowserStep(step.id);
}
});
resetListState();
notify('info', 'Capture List steps discarded');
}, [browserSteps, stopGetList, deleteBrowserStep, resetListState]);
const captureScreenshot = (fullPage: boolean) => { const captureScreenshot = (fullPage: boolean) => {
const screenshotSettings: ScreenshotSettings = { const screenshotSettings: ScreenshotSettings = {
fullPage, fullPage,
@@ -272,7 +299,7 @@ export const RightSidePanel: React.FC<RightSidePanelProps> = ({ onFinishCapture
captureStage === 'pagination' ? 'Confirm Pagination' : captureStage === 'pagination' ? 'Confirm Pagination' :
captureStage === 'limit' ? 'Confirm Limit' : 'Finish Capture'} captureStage === 'limit' ? 'Confirm Limit' : 'Finish Capture'}
</Button> </Button>
<Button variant="outlined" color="error" onClick={handleStopGetList}>Discard</Button> <Button variant="outlined" color="error" onClick={discardGetList}>Discard</Button>
</Box> </Box>
</> </>
)} )}
@@ -327,7 +354,7 @@ export const RightSidePanel: React.FC<RightSidePanelProps> = ({ onFinishCapture
<> <>
<Box display="flex" justifyContent="space-between" gap={2} style={{ margin: '15px' }}> <Box display="flex" justifyContent="space-between" gap={2} style={{ margin: '15px' }}>
<Button variant="outlined" onClick={stopCaptureAndEmitGetTextSettings} >Confirm</Button> <Button variant="outlined" onClick={stopCaptureAndEmitGetTextSettings} >Confirm</Button>
<Button variant="outlined" color="error" onClick={stopGetText} >Discard</Button> <Button variant="outlined" color="error" onClick={discardGetText} >Discard</Button>
</Box> </Box>
</> </>
} }
@@ -405,6 +432,7 @@ export const RightSidePanel: React.FC<RightSidePanelProps> = ({ onFinishCapture
fullWidth fullWidth
margin="normal" margin="normal"
InputProps={{ InputProps={{
readOnly: confirmedListTextFields[field.id]?.[key],
startAdornment: ( startAdornment: (
<InputAdornment position="start"> <InputAdornment position="start">
<EditIcon /> <EditIcon />

View File

@@ -91,6 +91,7 @@ export const BrowserStepsProvider: React.FC<{ children: React.ReactNode }> = ({
} }
}); });
}; };
const addScreenshotStep = (fullPage: boolean) => { const addScreenshotStep = (fullPage: boolean) => {
setBrowserSteps(prevSteps => [ setBrowserSteps(prevSteps => [
...prevSteps, ...prevSteps,