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 [currentStep, setCurrentStep] = useState<number | null>(null);
|
||||
const [uploadedFilename, setUploadedFilename] = useState<string | null>(null);
|
||||
const [uploadedTaskId, setUploadedTaskId] = useState<string | null>(null);
|
||||
const [shouldCreateFilter, setShouldCreateFilter] = 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
|
||||
useEffect(() => {
|
||||
if (currentStep === null || !tasks) {
|
||||
if (currentStep === null || !tasks || !uploadedTaskId) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if there are any active tasks (pending, running, or processing)
|
||||
const activeTasks = tasks.find(
|
||||
(task) =>
|
||||
task.status === "pending" ||
|
||||
task.status === "running" ||
|
||||
task.status === "processing",
|
||||
);
|
||||
// Find the task by task ID from the upload response
|
||||
const matchingTask = tasks.find((task) => task.task_id === uploadedTaskId);
|
||||
|
||||
// If no active tasks and we have more than 1 task (initial + new upload), complete it
|
||||
if (
|
||||
(!activeTasks || (activeTasks.processed_files ?? 0) > 0) &&
|
||||
tasks.length > 1
|
||||
) {
|
||||
// If no matching task found, wait for it to appear
|
||||
if (!matchingTask) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 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"
|
||||
setCurrentStep(STEP_LIST.length);
|
||||
|
||||
|
|
@ -125,7 +129,17 @@ const OnboardingUpload = ({ onComplete }: OnboardingUploadProps) => {
|
|||
onComplete();
|
||||
}, 1000);
|
||||
}
|
||||
}, [tasks, currentStep, onComplete, refetchNudges, shouldCreateFilter, uploadedFilename]);
|
||||
}, [
|
||||
tasks,
|
||||
currentStep,
|
||||
onComplete,
|
||||
refetchNudges,
|
||||
shouldCreateFilter,
|
||||
uploadedFilename,
|
||||
uploadedTaskId,
|
||||
createFilterMutation,
|
||||
isCreatingFilter,
|
||||
]);
|
||||
|
||||
const resetFileInput = () => {
|
||||
if (fileInputRef.current) {
|
||||
|
|
@ -144,6 +158,11 @@ const OnboardingUpload = ({ onComplete }: OnboardingUploadProps) => {
|
|||
const result = await uploadFile(file, true, true); // Pass createFilter=true
|
||||
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
|
||||
if (result.createFilter && result.filename) {
|
||||
setUploadedFilename(result.filename);
|
||||
|
|
@ -176,6 +195,7 @@ const OnboardingUpload = ({ onComplete }: OnboardingUploadProps) => {
|
|||
|
||||
// Reset on error
|
||||
setCurrentStep(null);
|
||||
setUploadedTaskId(null);
|
||||
} finally {
|
||||
setIsUploading(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ export interface UploadFileResult {
|
|||
raw: unknown;
|
||||
createFilter?: boolean;
|
||||
filename?: string;
|
||||
taskId?: string;
|
||||
}
|
||||
|
||||
export async function duplicateCheck(
|
||||
|
|
@ -158,6 +159,7 @@ export async function uploadFile(
|
|||
(uploadIngestJson as { upload?: { id?: string } }).upload?.id ||
|
||||
(uploadIngestJson as { id?: string }).id ||
|
||||
(uploadIngestJson as { task_id?: string }).task_id;
|
||||
const taskId = (uploadIngestJson as { task_id?: string }).task_id;
|
||||
const filePath =
|
||||
(uploadIngestJson as { upload?: { path?: string } }).upload?.path ||
|
||||
(uploadIngestJson as { path?: string }).path ||
|
||||
|
|
@ -197,6 +199,7 @@ export async function uploadFile(
|
|||
raw: uploadIngestJson,
|
||||
createFilter: shouldCreateFilter,
|
||||
filename,
|
||||
taskId,
|
||||
};
|
||||
|
||||
return result;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue