mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-19 08:51:24 +00:00
fix: Clean file input after uploading files (#2189)
* fix: Clean file input after uploading files - Enhance file upload component to trigger re-renders on state changes * fix: Clean file input after uploading files - Enhance file upload component to trigger re-renders on state changes
This commit is contained in:
@@ -13,7 +13,7 @@ import {
|
||||
import { Upload } from "Common/Upload/Upload";
|
||||
import { UploadDetailsRecord } from "Contracts/ViewModels";
|
||||
import { logConsoleError } from "Utils/NotificationConsoleUtils";
|
||||
import React, { ChangeEvent, FunctionComponent, useState } from "react";
|
||||
import React, { ChangeEvent, FunctionComponent, useReducer, useState } from "react";
|
||||
import { getErrorMessage } from "../../Tables/Utilities";
|
||||
import { useSelectedNode } from "../../useSelectedNode";
|
||||
import { RightPaneForm, RightPaneFormProps } from "../RightPaneForm/RightPaneForm";
|
||||
@@ -57,6 +57,7 @@ export const UploadItemsPane: FunctionComponent<UploadItemsPaneProps> = ({ onUpl
|
||||
const [uploadFileData, setUploadFileData] = useState<UploadDetailsRecord[]>([]);
|
||||
const [formError, setFormError] = useState<string>("");
|
||||
const [isExecuting, setIsExecuting] = useState<boolean>();
|
||||
const [reducer, setReducer] = useReducer((x) => x + 1, 1);
|
||||
|
||||
const onSubmit = () => {
|
||||
setFormError("");
|
||||
@@ -75,6 +76,7 @@ export const UploadItemsPane: FunctionComponent<UploadItemsPaneProps> = ({ onUpl
|
||||
(uploadDetails) => {
|
||||
setUploadFileData(uploadDetails.data);
|
||||
setFiles(undefined);
|
||||
setReducer(); // Trigger a re-render to update the UI with new upload details
|
||||
// Emit the upload details to the parent component
|
||||
onUpload && onUpload(uploadDetails.data);
|
||||
},
|
||||
@@ -95,6 +97,7 @@ export const UploadItemsPane: FunctionComponent<UploadItemsPaneProps> = ({ onUpl
|
||||
const props: RightPaneFormProps = {
|
||||
formError,
|
||||
isExecuting: isExecuting,
|
||||
isSubmitButtonDisabled: !files || files.length === 0,
|
||||
submitButtonText: "Upload",
|
||||
onSubmit,
|
||||
};
|
||||
@@ -192,6 +195,7 @@ export const UploadItemsPane: FunctionComponent<UploadItemsPaneProps> = ({ onUpl
|
||||
<RightPaneForm {...props}>
|
||||
<div className="paneMainContent">
|
||||
<Upload
|
||||
key={reducer} // Force re-render on state change
|
||||
label="Select JSON Files"
|
||||
onUpload={updateSelectedFiles}
|
||||
accept="application/json"
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
exports[`Upload Items Pane should render Default properly 1`] = `
|
||||
<RightPaneForm
|
||||
formError=""
|
||||
isSubmitButtonDisabled={true}
|
||||
onSubmit={[Function]}
|
||||
submitButtonText="Upload"
|
||||
>
|
||||
@@ -11,6 +12,7 @@ exports[`Upload Items Pane should render Default properly 1`] = `
|
||||
>
|
||||
<Upload
|
||||
accept="application/json"
|
||||
key="1"
|
||||
label="Select JSON Files"
|
||||
multiple={true}
|
||||
onUpload={[Function]}
|
||||
|
||||
Reference in New Issue
Block a user