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