Skip to content

Commit

Permalink
save file object to context
Browse files Browse the repository at this point in the history
  • Loading branch information
CurryYangxx committed Dec 17, 2024
1 parent 0a23ad9 commit 1e7e3b3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/insomnia/src/ui/context/app/runner-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ interface RunnerState {
delay: number;
uploadData: UploadDataType[];
advancedConfig: Record<string, boolean>;
file: File | null;
}

type RunnerStateMap = Record<string, RunnerState>;
type RunnerStateMap = Record<string, Partial<RunnerState> | undefined>;
interface ContextProps {
runnerStateMap: RunnerStateMap;
updateRunnerState: (runnerId: string, patch: Partial<RunnerState>) => void;
Expand Down
11 changes: 7 additions & 4 deletions packages/insomnia/src/ui/routes/runner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ export interface RequestRow {
parentId: string;
};

const defaultAdvancedConfig = {
bail: true,
};

export const Runner: FC<{}> = () => {
const [searchParams] = useSearchParams();
const [errorMsg, setErrorMsg] = useState<null | string>(null);
Expand All @@ -122,7 +126,6 @@ export const Runner: FC<{}> = () => {
workspaceId: string;
direction: 'vertical' | 'horizontal';
};
const [file, setFile] = useState<File | null>(null);
const [isRunning, setIsRunning] = useState(false);

const runnerId = targetFolderId ? targetFolderId : workspaceId;
Expand All @@ -133,7 +136,7 @@ export const Runner: FC<{}> = () => {
const [direction, setDirection] = useState<'horizontal' | 'vertical'>(settings.forceVerticalLayout ? 'vertical' : 'horizontal');

const { runnerStateMap, updateRunnerState } = useRunnerContext();
const { iterationCount = 1, delay = 0, selectedKeys, advancedConfig, uploadData = [] } = runnerStateMap[runnerId] || {};
const { iterationCount = 1, delay = 0, selectedKeys, advancedConfig = defaultAdvancedConfig, uploadData = [], file } = runnerStateMap[runnerId] || {};
invariant(iterationCount, 'iterationCount should not be null');

const { reqList, requestRows, entityMap } = useRunnerRequestList(workspaceId, targetFolderId);
Expand Down Expand Up @@ -248,7 +251,7 @@ export const Runner: FC<{}> = () => {
iterationCount,
userUploadEnvs,
delay,
bail: advancedConfig?.bail || true,
bail: advancedConfig?.bail,
targetFolderId: targetFolderId || '',
};
submit(
Expand Down Expand Up @@ -685,9 +688,9 @@ export const Runner: FC<{}> = () => {
{showUploadModal && (
<UploadDataModal
onUploadFile={(file, uploadData) => {
setFile(file);
updateRunnerState(runnerId, {
uploadData,
file,
iterationCount: uploadData.length >= 1 ? uploadData.length : iterationCount,
});
}}
Expand Down

0 comments on commit 1e7e3b3

Please sign in to comment.