Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/components/recorder/RightSidePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { WorkflowFile } from "maxun-core";
import Typography from "@mui/material/Typography";
import { useGlobalInfoStore } from "../../context/globalInfo";
import { PaginationType, useActionContext, LimitType } from '../../context/browserActions';
import { useBrowserSteps } from '../../context/browserSteps';
import { BrowserStep, useBrowserSteps } from '../../context/browserSteps';
import { useSocketStore } from '../../context/socket';
import { ScreenshotSettings } from '../../shared/types';
import InputAdornment from '@mui/material/InputAdornment';
Expand Down Expand Up @@ -69,7 +69,7 @@ export const RightSidePanel: React.FC<RightSidePanelProps> = ({ onFinishCapture
startAction, finishAction
} = useActionContext();

const { browserSteps, updateBrowserTextStepLabel, deleteBrowserStep, addScreenshotStep, updateListTextFieldLabel, removeListTextField } = useBrowserSteps();
const { browserSteps, updateBrowserTextStepLabel, deleteBrowserStep, addScreenshotStep, updateListTextFieldLabel, removeListTextField, updateListStepLimit } = useBrowserSteps();
const { id, socket } = useSocketStore();
const { t } = useTranslation();

Expand Down Expand Up @@ -349,6 +349,13 @@ export const RightSidePanel: React.FC<RightSidePanelProps> = ({ onFinishCapture
)
);

const getLatestListStep = (steps: BrowserStep[]) => {
const listSteps = steps.filter(step => step.type === 'list');
if (listSteps.length === 0) return null;

return listSteps.sort((a, b) => b.id - a.id)[0];
};

const handleConfirmListCapture = useCallback(() => {
switch (captureStage) {
case 'initial':
Expand Down Expand Up @@ -385,6 +392,12 @@ export const RightSidePanel: React.FC<RightSidePanelProps> = ({ onFinishCapture
notify('error', t('right_panel.errors.invalid_limit'));
return;
}

const latestListStep = getLatestListStep(browserSteps);
if (latestListStep) {
updateListStepLimit(latestListStep.id, limit);
}

Comment on lines +395 to +400
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix the switch case declaration scope issue.

The static analysis tool correctly identifies a potential issue with the declaration scope in the switch statement. Variables declared in a switch case without a block are accessible in other cases, which could lead to unintended behavior.

Apply this fix:

      case 'limit':
        if (!limitType || (limitType === 'custom' && !customLimit)) {
          notify('error', t('right_panel.errors.select_limit'));
          return;
        }
        const limit = limitType === 'custom' ? parseInt(customLimit) : parseInt(limitType);
        if (isNaN(limit) || limit <= 0) {
          notify('error', t('right_panel.errors.invalid_limit'));
          return;
        }

+       {
          const latestListStep = getLatestListStep(browserSteps);
          if (latestListStep) {
            updateListStepLimit(latestListStep.id, limit);
          }
+       }

        stopLimitMode();
        setShowLimitOptions(false);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const latestListStep = getLatestListStep(browserSteps);
if (latestListStep) {
updateListStepLimit(latestListStep.id, limit);
}
{
const latestListStep = getLatestListStep(browserSteps);
if (latestListStep) {
updateListStepLimit(latestListStep.id, limit);
}
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 396-396: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Unsafe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)

stopLimitMode();
setShowLimitOptions(false);
setIsCaptureListConfirmed(true);
Expand Down
18 changes: 17 additions & 1 deletion src/context/browserSteps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface ListStep {
limit?: number;
}

type BrowserStep = TextStep | ScreenshotStep | ListStep;
export type BrowserStep = TextStep | ScreenshotStep | ListStep;

export interface SelectorObject {
selector: string;
Expand All @@ -44,6 +44,7 @@ interface BrowserStepsContextType {
deleteBrowserStep: (id: number) => void;
updateBrowserTextStepLabel: (id: number, newLabel: string) => void;
updateListTextFieldLabel: (listId: number, fieldKey: string, newLabel: string) => void;
updateListStepLimit: (listId: number, limit: number) => void;
removeListTextField: (listId: number, fieldKey: string) => void;
}

Expand Down Expand Up @@ -142,6 +143,20 @@ export const BrowserStepsProvider: React.FC<{ children: React.ReactNode }> = ({
);
};

const updateListStepLimit = (listId: number, limit: number) => {
setBrowserSteps(prevSteps =>
prevSteps.map(step => {
if (step.type === 'list' && step.id === listId) {
return {
...step,
limit: limit
};
}
return step;
})
);
};

const removeListTextField = (listId: number, fieldKey: string) => {
setBrowserSteps(prevSteps =>
prevSteps.map(step => {
Expand All @@ -166,6 +181,7 @@ export const BrowserStepsProvider: React.FC<{ children: React.ReactNode }> = ({
deleteBrowserStep,
updateBrowserTextStepLabel,
updateListTextFieldLabel,
updateListStepLimit,
removeListTextField,
}}>
{children}
Expand Down