From e2b50a813e5e864975105c8be5a21dbbadaa4d32 Mon Sep 17 00:00:00 2001 From: Bangarraju-Microsoft Date: Fri, 11 Apr 2025 16:29:23 +0530 Subject: [PATCH 1/2] UI - User story (#16865) changes --- .../components/uploadButton/uploadButton.tsx | 219 ++++++++++-------- App/frontend-app/src/vite-env.d.ts | 1 + Deployment/appconfig/frontapp/.env.template | 3 +- 3 files changed, 121 insertions(+), 102 deletions(-) diff --git a/App/frontend-app/src/components/uploadButton/uploadButton.tsx b/App/frontend-app/src/components/uploadButton/uploadButton.tsx index 96cee722..e46ca62c 100644 --- a/App/frontend-app/src/components/uploadButton/uploadButton.tsx +++ b/App/frontend-app/src/components/uploadButton/uploadButton.tsx @@ -1,4 +1,4 @@ -import React, { useState, useCallback } from "react"; +import React, { useState, useCallback, useEffect } from "react"; import { useDropzone } from "react-dropzone"; import { Button, @@ -24,9 +24,22 @@ import { getFileTypeIconProps } from "@fluentui/react-file-type-icons"; const UploadDocumentsDialog = () => { const [isOpen, setIsOpen] = useState(false); const [uploadingFiles, setUploadingFiles] = useState< - { name: string; progress: number; status: string; errorMsg:string }[] + { name: string; progress: number; status: string; errorMsg: string }[] >([]); const [isUploading, setIsUploading] = useState(false); + const [isUploadBtnVisible, setIsUploadBtnVisible] = useState(false); + + + function toBoolean(value: unknown): boolean { + return String(value).toLowerCase() === "true"; + } + + useEffect(() => { + if (import.meta.env.VITE_ENABLE_UPLOAD_BUTTON != undefined){ + const flag = import.meta.env.VITE_ENABLE_UPLOAD_BUTTON; + setIsUploadBtnVisible(toBoolean(flag)) + } + }, [import.meta.env.VITE_ENABLE_UPLOAD_BUTTON]) // Handle file drop and simulate upload const onDrop = useCallback(async (acceptedFiles: any[]) => { @@ -35,7 +48,7 @@ const UploadDocumentsDialog = () => { name: file.name, progress: 0, status: "uploading", - errorMsg : "" + errorMsg: "" })); setUploadingFiles((prev) => [...prev, ...newFiles]); @@ -57,7 +70,7 @@ const UploadDocumentsDialog = () => { : f ) ); - } catch (error:any) { + } catch (error: any) { const errorMessage = error.message.replace(/^Error:\s*/, ""); // Remove "Error: " prefix const parsedError = JSON.parse(errorMessage); @@ -65,7 +78,7 @@ const UploadDocumentsDialog = () => { setUploadingFiles((prev) => prev.map((f, index) => index === prev.length - acceptedFiles.length + i - ? { ...f, progress: 100, status: "error", errorMsg: parsedError.summary} + ? { ...f, progress: 100, status: "error", errorMsg: parsedError.summary } : f ) ); @@ -80,63 +93,63 @@ const UploadDocumentsDialog = () => { noKeyboard: true, }); - return ( - setIsOpen(data.open)}> - - - - - - - - Upload Documents - + + + + + Upload Documents + - - )} + > + + +

Drag and drop files

+

or

+ + + )} - {/* Upload link section */} - {/*
+ {/* Upload link section */} + {/*

Upload link

{
*/} - {/* File progress display */} - {uploadingFiles.map((file, index) => ( -
+ {/* File progress display */} + {uploadingFiles.map((file, index) => (
-
- - {file.name} +
+
+ + {file.name} +
+ {file.status === "success" && ( + + )} + {file.status === "error" && ( + + )}
- {file.status === "success" && ( - - )} - {file.status === "error" && ( - - )} + + + {file.status === "uploading" + ? "Uploading..." + : file.status === "success" + ? "Upload complete" + : file.errorMsg} + + { }
- - - {file.status === "uploading" - ? "Uploading..." - : file.status === "success" - ? "Upload complete" - : file.errorMsg} - - {} -
- ))} - - - -
- ); + ))} + + + + : <> + } + + ) + + }; export default UploadDocumentsDialog; diff --git a/App/frontend-app/src/vite-env.d.ts b/App/frontend-app/src/vite-env.d.ts index 42d9da0c..d908d676 100644 --- a/App/frontend-app/src/vite-env.d.ts +++ b/App/frontend-app/src/vite-env.d.ts @@ -2,6 +2,7 @@ interface ImportMetaEnv { VITE_API_ENDPOINT: string + VITE_ENABLE_UPLOAD_BUTTON : string // Add other environment variables here } diff --git a/Deployment/appconfig/frontapp/.env.template b/Deployment/appconfig/frontapp/.env.template index 362bd3a1..99969f6e 100644 --- a/Deployment/appconfig/frontapp/.env.template +++ b/Deployment/appconfig/frontapp/.env.template @@ -1,2 +1,3 @@ VITE_API_ENDPOINT={{ backend-fqdn }} -DISABLE_AUTH=true \ No newline at end of file +DISABLE_AUTH=true +VITE_ENABLE_UPLOAD_BUTTON = false \ No newline at end of file From e42153e432d2123a2b02e1613640427ebc3f91e3 Mon Sep 17 00:00:00 2001 From: Prajwal D C Date: Fri, 11 Apr 2025 23:01:08 +0530 Subject: [PATCH 2/2] feat: Added the flag for Upload button --- Deployment/appconfig/frontapp/.env.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Deployment/appconfig/frontapp/.env.template b/Deployment/appconfig/frontapp/.env.template index 99969f6e..29c851e4 100644 --- a/Deployment/appconfig/frontapp/.env.template +++ b/Deployment/appconfig/frontapp/.env.template @@ -1,3 +1,3 @@ VITE_API_ENDPOINT={{ backend-fqdn }} DISABLE_AUTH=true -VITE_ENABLE_UPLOAD_BUTTON = false \ No newline at end of file +VITE_ENABLE_UPLOAD_BUTTON=false \ No newline at end of file