mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-30 06:11:38 +00:00
* First dark theme commits for command bar * Updated theme on sidebar * Updated tabs, sidebar, splash screen * settings theme changes * Dark theme applied to Monaco editor * Dark theme to stored procedures * Fixed sidebar scroll * Updated scroll issue in sidebar * Command bar items fixed * Fixed lint errors * fixed lint errors * settings side panel fixed * Second last iteration for css * Fixed all the issues of css * Updated the theme icon for now on DE to change the theme from portal/DE itself * Formatting issue resolved * Remove CloudShellTerminalComponent changes - revert to master version * Fixed test issue * Fixed formatting issue * Fix tests: update snapshots and revert xterm imports for compatibility * Fix xterm imports in CloudShellTerminalComponent to use @xterm packages * Fix Cloud Shell component imports for compatibility * Update test snapshots * Fix xterm package consistency across all CloudShell components * Fix TypeScript compilation errors in CloudShell components and query Documents - Standardized xterm package imports across CloudShell components to use legacy 'xterm' package - Fixed Terminal type compatibility issues in CommonUtils.tsx - Added type casting for enableQueryControl property in queryDocuments.ts to handle Azure Cosmos SDK interface limitations - Applied code formatting to ensure consistency * Update failing snapshot tests - Updated TreeNodeComponent snapshot tests for loading states - Updated ThroughputInputAutoPilotV3Component snapshots for number formatting changes (10,00,000 -> 1,000,000) - All snapshot tests now pass * Fixed test issue * Fixed test issue * Updated the buttons for theme * Updated the Theme changes based on portal theme changes * Updated review comments * Updated the duplicate code and fixed the fabric react error * Few places styling added and resolving few comments * Fixed errors * Fixed comments * Fixed comments * Fixed comments * Fixed full text policy issue for mongoru accounts * Resolved comments for class Name and few others * Added css for homepage in ru accounts * Final commit with all the feedback issues resolved * Lint error resolved * Updated the review comments and few Ui issues * Resolved review comments and changed header bg and active state color * Moved svg code to different file and imported * css fixed for the hpome page boxed for ru account * Lint errors * Fixed boxes issue in ru accounts * Handled the initial theme from the portal * Updated snap * Update snapshots for TreeNodeComponent and CreateCopyJobScreensProvider tests * Fix duplicate DataExplorerRoot test id causing Playwright strict mode violation * Fix locale-dependent number formatting in ThroughputInputAutoPilotV3Component --------- Co-authored-by: Sakshi Gupta <sakshig+microsoft@microsoft.com> Co-authored-by: Sakshi Gupta <sakshig@microsoft.com>
122 lines
4.4 KiB
TypeScript
122 lines
4.4 KiB
TypeScript
import { IImageProps, Image, ImageFit, Stack, TextField } from "@fluentui/react";
|
|
import { useBoolean } from "@fluentui/react-hooks";
|
|
import React, { FunctionComponent, useState } from "react";
|
|
import folderIcon from "../../../../images/folder_16x16.svg";
|
|
import { logError } from "../../../Common/Logger";
|
|
import { Collection } from "../../../Contracts/ViewModels";
|
|
import { useSidePanel } from "../../../hooks/useSidePanel";
|
|
import { userContext } from "../../../UserContext";
|
|
import { logConsoleError, logConsoleInfo, logConsoleProgress } from "../../../Utils/NotificationConsoleUtils";
|
|
import { useSelectedNode } from "../../useSelectedNode";
|
|
import { RightPaneForm, RightPaneFormProps } from "../RightPaneForm/RightPaneForm";
|
|
|
|
export const LoadQueryPane: FunctionComponent = (): JSX.Element => {
|
|
const closeSidePanel = useSidePanel((state) => state.closeSidePanel);
|
|
const [isLoading, { setTrue: setLoadingTrue, setFalse: setLoadingFalse }] = useBoolean(false);
|
|
const [formError, setFormError] = useState<string>("");
|
|
const [selectedFileName, setSelectedFileName] = useState<string>("");
|
|
const [selectedFiles, setSelectedFiles] = useState<FileList>();
|
|
|
|
const imageProps: Partial<IImageProps> = {
|
|
imageFit: ImageFit.centerCover,
|
|
width: 20,
|
|
height: 20,
|
|
className: "fileIcon",
|
|
};
|
|
|
|
const onFileSelected = (e: React.ChangeEvent<HTMLInputElement>): void => {
|
|
const { files } = e.target;
|
|
setSelectedFiles(files);
|
|
setSelectedFileName(files && files[0] && `"${files[0].name}"`);
|
|
};
|
|
|
|
const submit = async (): Promise<void> => {
|
|
setFormError("");
|
|
if (!selectedFiles || selectedFiles.length === 0) {
|
|
setFormError("No file specified");
|
|
logConsoleError("Could not load query -- No file specified. Please input a file.");
|
|
return;
|
|
}
|
|
|
|
const file: File = selectedFiles[0];
|
|
logConsoleProgress(`Loading query from file ${file.name}`);
|
|
setLoadingTrue();
|
|
try {
|
|
await loadQueryFromFile(file);
|
|
logConsoleInfo(`Successfully loaded query from file ${file.name}`);
|
|
closeSidePanel();
|
|
setLoadingFalse();
|
|
} catch (error) {
|
|
setLoadingFalse();
|
|
setFormError("Failed to load query");
|
|
logConsoleError(`Failed to load query from file ${file.name}: ${error}`);
|
|
}
|
|
};
|
|
|
|
const loadQueryFromFile = async (file: File): Promise<void> => {
|
|
const selectedCollection: Collection = useSelectedNode.getState().findSelectedCollection();
|
|
const reader = new FileReader();
|
|
let fileData: string;
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
reader.onload = (evt: any): void => {
|
|
fileData = evt.target.result;
|
|
|
|
if (!selectedCollection) {
|
|
logError("No collection was selected", "LoadQueryPane.loadQueryFromFile");
|
|
} else if (userContext.apiType === "Mongo") {
|
|
selectedCollection.onNewMongoQueryClick(selectedCollection, undefined);
|
|
} else {
|
|
selectedCollection.onNewQueryClick(selectedCollection, undefined, fileData);
|
|
}
|
|
};
|
|
|
|
reader.onerror = (): void => {
|
|
setFormError("Failed to load query");
|
|
logConsoleError(`Failed to load query from file ${file.name}`);
|
|
};
|
|
return reader.readAsText(file);
|
|
};
|
|
const props: RightPaneFormProps = {
|
|
formError: formError,
|
|
isExecuting: isLoading,
|
|
submitButtonText: "Load",
|
|
onSubmit: () => submit(),
|
|
};
|
|
|
|
return (
|
|
<RightPaneForm {...props}>
|
|
<div className="panelFormWrapper">
|
|
<div className="panelMainContent">
|
|
<Stack horizontal>
|
|
<TextField
|
|
id="confirmCollectionId"
|
|
label="Select a query document"
|
|
value={selectedFileName}
|
|
autoFocus
|
|
readOnly
|
|
styles={{
|
|
fieldGroup: { width: 300, color: "var(--colorNeutralForeground1)" },
|
|
subComponentStyles: {
|
|
label: {
|
|
root: { color: "var(--colorNeutralForeground1)" },
|
|
},
|
|
},
|
|
}}
|
|
/>
|
|
<label htmlFor="importQueryInputId" className="customFileUpload">
|
|
<Image {...imageProps} src={folderIcon} alt="upload files" />
|
|
<input
|
|
className="fileUpload"
|
|
type="file"
|
|
id="importQueryInputId"
|
|
accept="text/plain"
|
|
onChange={onFileSelected}
|
|
/>
|
|
</label>
|
|
</Stack>
|
|
</div>
|
|
</div>
|
|
</RightPaneForm>
|
|
);
|
|
};
|