Skip to content

Commit

Permalink
Merge pull request #288 from getmaxun/labreset-fix
Browse files Browse the repository at this point in the history
fix: preserve previous labels steps before adding list step
  • Loading branch information
amhsirak authored Dec 23, 2024
2 parents 4f151f0 + e017148 commit e4ab1c3
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/context/browserSteps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,35 @@ export const BrowserStepsProvider: React.FC<{ children: React.ReactNode }> = ({
const addListStep = (listSelector: string, newFields: { [key: string]: TextStep }, listId: number, pagination?: { type: string; selector: string }, limit?: number) => {
setBrowserSteps(prevSteps => {
const existingListStepIndex = prevSteps.findIndex(step => step.type === 'list' && step.id === listId);

if (existingListStepIndex !== -1) {
const updatedSteps = [...prevSteps];
const existingListStep = updatedSteps[existingListStepIndex] as ListStep;

const filteredNewFields = Object.entries(newFields).reduce((acc, [key, value]) => {

// Preserve existing labels for fields
const mergedFields = Object.entries(newFields).reduce((acc, [key, field]) => {
if (!discardedFields.has(`${listId}-${key}`)) {
acc[key] = value;
// If field exists, preserve its label
if (existingListStep.fields[key]) {
acc[key] = {
...field,
label: existingListStep.fields[key].label
};
} else {
acc[key] = field;
}
}
return acc;
}, {} as { [key: string]: TextStep });

updatedSteps[existingListStepIndex] = {
...existingListStep,
fields: { ...existingListStep.fields, ...filteredNewFields },
pagination: pagination,
limit: limit,
fields: mergedFields,
pagination: pagination || existingListStep.pagination,
limit: limit
};
return updatedSteps;
} else {
// Create a new ListStep
return [
...prevSteps,
{ id: listId, type: 'list', listSelector, fields: newFields, pagination, limit }
Expand Down

0 comments on commit e4ab1c3

Please sign in to comment.