fixed onboarding upload to be linked to the task id
This commit is contained in:
parent
e413ff98f9
commit
3ffa405ae9
2 changed files with 37 additions and 14 deletions
|
|
@ -21,6 +21,7 @@ const OnboardingUpload = ({ onComplete }: OnboardingUploadProps) => {
|
||||||
const [isUploading, setIsUploading] = useState(false);
|
const [isUploading, setIsUploading] = useState(false);
|
||||||
const [currentStep, setCurrentStep] = useState<number | null>(null);
|
const [currentStep, setCurrentStep] = useState<number | null>(null);
|
||||||
const [uploadedFilename, setUploadedFilename] = useState<string | null>(null);
|
const [uploadedFilename, setUploadedFilename] = useState<string | null>(null);
|
||||||
|
const [uploadedTaskId, setUploadedTaskId] = useState<string | null>(null);
|
||||||
const [shouldCreateFilter, setShouldCreateFilter] = useState(false);
|
const [shouldCreateFilter, setShouldCreateFilter] = useState(false);
|
||||||
const [isCreatingFilter, setIsCreatingFilter] = useState(false);
|
const [isCreatingFilter, setIsCreatingFilter] = useState(false);
|
||||||
|
|
||||||
|
|
@ -43,23 +44,26 @@ const OnboardingUpload = ({ onComplete }: OnboardingUploadProps) => {
|
||||||
|
|
||||||
// Monitor tasks and call onComplete when file processing is done
|
// Monitor tasks and call onComplete when file processing is done
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (currentStep === null || !tasks) {
|
if (currentStep === null || !tasks || !uploadedTaskId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if there are any active tasks (pending, running, or processing)
|
// Find the task by task ID from the upload response
|
||||||
const activeTasks = tasks.find(
|
const matchingTask = tasks.find((task) => task.task_id === uploadedTaskId);
|
||||||
(task) =>
|
|
||||||
task.status === "pending" ||
|
|
||||||
task.status === "running" ||
|
|
||||||
task.status === "processing",
|
|
||||||
);
|
|
||||||
|
|
||||||
// If no active tasks and we have more than 1 task (initial + new upload), complete it
|
// If no matching task found, wait for it to appear
|
||||||
if (
|
if (!matchingTask) {
|
||||||
(!activeTasks || (activeTasks.processed_files ?? 0) > 0) &&
|
return;
|
||||||
tasks.length > 1
|
}
|
||||||
) {
|
|
||||||
|
// Check if the matching task is still active (pending, running, or processing)
|
||||||
|
const isTaskActive =
|
||||||
|
matchingTask.status === "pending" ||
|
||||||
|
matchingTask.status === "running" ||
|
||||||
|
matchingTask.status === "processing";
|
||||||
|
|
||||||
|
// If task is completed or has processed files, complete the onboarding step
|
||||||
|
if (!isTaskActive || (matchingTask.processed_files ?? 0) > 0) {
|
||||||
// Set to final step to show "Done"
|
// Set to final step to show "Done"
|
||||||
setCurrentStep(STEP_LIST.length);
|
setCurrentStep(STEP_LIST.length);
|
||||||
|
|
||||||
|
|
@ -125,7 +129,17 @@ const OnboardingUpload = ({ onComplete }: OnboardingUploadProps) => {
|
||||||
onComplete();
|
onComplete();
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
}, [tasks, currentStep, onComplete, refetchNudges, shouldCreateFilter, uploadedFilename]);
|
}, [
|
||||||
|
tasks,
|
||||||
|
currentStep,
|
||||||
|
onComplete,
|
||||||
|
refetchNudges,
|
||||||
|
shouldCreateFilter,
|
||||||
|
uploadedFilename,
|
||||||
|
uploadedTaskId,
|
||||||
|
createFilterMutation,
|
||||||
|
isCreatingFilter,
|
||||||
|
]);
|
||||||
|
|
||||||
const resetFileInput = () => {
|
const resetFileInput = () => {
|
||||||
if (fileInputRef.current) {
|
if (fileInputRef.current) {
|
||||||
|
|
@ -144,6 +158,11 @@ const OnboardingUpload = ({ onComplete }: OnboardingUploadProps) => {
|
||||||
const result = await uploadFile(file, true, true); // Pass createFilter=true
|
const result = await uploadFile(file, true, true); // Pass createFilter=true
|
||||||
console.log("Document upload task started successfully");
|
console.log("Document upload task started successfully");
|
||||||
|
|
||||||
|
// Store task ID to track the specific upload task
|
||||||
|
if (result.taskId) {
|
||||||
|
setUploadedTaskId(result.taskId);
|
||||||
|
}
|
||||||
|
|
||||||
// Store filename and createFilter flag in state to create filter after ingestion succeeds
|
// Store filename and createFilter flag in state to create filter after ingestion succeeds
|
||||||
if (result.createFilter && result.filename) {
|
if (result.createFilter && result.filename) {
|
||||||
setUploadedFilename(result.filename);
|
setUploadedFilename(result.filename);
|
||||||
|
|
@ -176,6 +195,7 @@ const OnboardingUpload = ({ onComplete }: OnboardingUploadProps) => {
|
||||||
|
|
||||||
// Reset on error
|
// Reset on error
|
||||||
setCurrentStep(null);
|
setCurrentStep(null);
|
||||||
|
setUploadedTaskId(null);
|
||||||
} finally {
|
} finally {
|
||||||
setIsUploading(false);
|
setIsUploading(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ export interface UploadFileResult {
|
||||||
raw: unknown;
|
raw: unknown;
|
||||||
createFilter?: boolean;
|
createFilter?: boolean;
|
||||||
filename?: string;
|
filename?: string;
|
||||||
|
taskId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function duplicateCheck(
|
export async function duplicateCheck(
|
||||||
|
|
@ -158,6 +159,7 @@ export async function uploadFile(
|
||||||
(uploadIngestJson as { upload?: { id?: string } }).upload?.id ||
|
(uploadIngestJson as { upload?: { id?: string } }).upload?.id ||
|
||||||
(uploadIngestJson as { id?: string }).id ||
|
(uploadIngestJson as { id?: string }).id ||
|
||||||
(uploadIngestJson as { task_id?: string }).task_id;
|
(uploadIngestJson as { task_id?: string }).task_id;
|
||||||
|
const taskId = (uploadIngestJson as { task_id?: string }).task_id;
|
||||||
const filePath =
|
const filePath =
|
||||||
(uploadIngestJson as { upload?: { path?: string } }).upload?.path ||
|
(uploadIngestJson as { upload?: { path?: string } }).upload?.path ||
|
||||||
(uploadIngestJson as { path?: string }).path ||
|
(uploadIngestJson as { path?: string }).path ||
|
||||||
|
|
@ -197,6 +199,7 @@ export async function uploadFile(
|
||||||
raw: uploadIngestJson,
|
raw: uploadIngestJson,
|
||||||
createFilter: shouldCreateFilter,
|
createFilter: shouldCreateFilter,
|
||||||
filename,
|
filename,
|
||||||
|
taskId,
|
||||||
};
|
};
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue