mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-04-15 14:17:29 +01:00
Initial implementation of saving split value to local storage
This commit is contained in:
parent
7002da0b51
commit
1ee79881ef
@ -18,6 +18,11 @@ import { EditorReact } from "Explorer/Controls/Editor/EditorReact";
|
|||||||
import Explorer from "Explorer/Explorer";
|
import Explorer from "Explorer/Explorer";
|
||||||
import { useCommandBar } from "Explorer/Menus/CommandBar/CommandBarComponentAdapter";
|
import { useCommandBar } from "Explorer/Menus/CommandBar/CommandBarComponentAdapter";
|
||||||
import { querySampleDocuments, readSampleDocument } from "Explorer/QueryCopilot/QueryCopilotUtilities";
|
import { querySampleDocuments, readSampleDocument } from "Explorer/QueryCopilot/QueryCopilotUtilities";
|
||||||
|
import {
|
||||||
|
DocumentsTabPrefs,
|
||||||
|
readDocumentsTabPrefs,
|
||||||
|
saveDocumentsTabPrefs,
|
||||||
|
} from "Explorer/Tabs/DocumentsTabV2/documentsTabPrefs";
|
||||||
import { getPlatformTheme } from "Explorer/Theme/ThemeUtil";
|
import { getPlatformTheme } from "Explorer/Theme/ThemeUtil";
|
||||||
import { useSelectedNode } from "Explorer/useSelectedNode";
|
import { useSelectedNode } from "Explorer/useSelectedNode";
|
||||||
import { KeyboardAction, KeyboardActionGroup, useKeyboardActionGroup } from "KeyboardShortcuts";
|
import { KeyboardAction, KeyboardActionGroup, useKeyboardActionGroup } from "KeyboardShortcuts";
|
||||||
@ -474,6 +479,9 @@ export const DocumentsTabComponent: React.FunctionComponent<IDocumentsTabCompone
|
|||||||
ViewModels.DocumentExplorerState.noDocumentSelected,
|
ViewModels.DocumentExplorerState.noDocumentSelected,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Preferences
|
||||||
|
const [prefs, setPrefs] = useState<DocumentsTabPrefs>(readDocumentsTabPrefs());
|
||||||
|
|
||||||
const isQueryCopilotSampleContainer =
|
const isQueryCopilotSampleContainer =
|
||||||
_collection?.isSampleCollection &&
|
_collection?.isSampleCollection &&
|
||||||
_collection?.databaseId === QueryCopilotSampleDatabaseId &&
|
_collection?.databaseId === QueryCopilotSampleDatabaseId &&
|
||||||
@ -1742,9 +1750,20 @@ export const DocumentsTabComponent: React.FunctionComponent<IDocumentsTabCompone
|
|||||||
)}
|
)}
|
||||||
{/* <Split> doesn't like to be a flex child */}
|
{/* <Split> doesn't like to be a flex child */}
|
||||||
<div style={{ overflow: "hidden", height: "100%" }}>
|
<div style={{ overflow: "hidden", height: "100%" }}>
|
||||||
<Split>
|
<Split
|
||||||
|
onDragEnd={(preSize: number) => {
|
||||||
|
prefs.leftPaneWidthPercent = Math.min(100, Math.max(0, Math.round(100 * preSize) / 100));
|
||||||
|
saveDocumentsTabPrefs(prefs);
|
||||||
|
setPrefs({ ...prefs });
|
||||||
|
}}
|
||||||
|
>
|
||||||
<div
|
<div
|
||||||
style={{ minWidth: 120, width: "35%", overflow: "hidden", position: "relative" }}
|
style={{
|
||||||
|
minWidth: 60,
|
||||||
|
width: `${prefs.leftPaneWidthPercent}%`,
|
||||||
|
overflow: "hidden",
|
||||||
|
position: "relative",
|
||||||
|
}}
|
||||||
ref={tableContainerRef}
|
ref={tableContainerRef}
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
@ -1796,7 +1815,7 @@ export const DocumentsTabComponent: React.FunctionComponent<IDocumentsTabCompone
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style={{ minWidth: "20%", width: "100%" }}>
|
<div style={{ minWidth: 60, width: `${100 - prefs.leftPaneWidthPercent}%` }}>
|
||||||
{isTabActive && selectedDocumentContent && selectedRows.size <= 1 && (
|
{isTabActive && selectedDocumentContent && selectedRows.size <= 1 && (
|
||||||
<EditorReact
|
<EditorReact
|
||||||
language={"json"}
|
language={"json"}
|
||||||
|
21
src/Explorer/Tabs/DocumentsTabV2/documentsTabPrefs.ts
Normal file
21
src/Explorer/Tabs/DocumentsTabV2/documentsTabPrefs.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// Utility functions to manage DocumentsTab preferences
|
||||||
|
|
||||||
|
import { LocalStorageUtility, StorageKey } from "Shared/StorageUtility";
|
||||||
|
|
||||||
|
export interface DocumentsTabPrefs {
|
||||||
|
leftPaneWidthPercent: number;
|
||||||
|
columnWidths?: number[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultPrefs: DocumentsTabPrefs = {
|
||||||
|
leftPaneWidthPercent: 50,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const readDocumentsTabPrefs = (): DocumentsTabPrefs => {
|
||||||
|
const prefs = LocalStorageUtility.getEntryObject<DocumentsTabPrefs>(StorageKey.DocumentsTabPrefs);
|
||||||
|
return prefs || defaultPrefs;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const saveDocumentsTabPrefs = (prefs: DocumentsTabPrefs): void => {
|
||||||
|
LocalStorageUtility.setEntryObject(StorageKey.DocumentsTabPrefs, prefs);
|
||||||
|
};
|
@ -20,3 +20,15 @@ export const setEntryNumber = (key: StorageKey, value: number): void =>
|
|||||||
|
|
||||||
export const setEntryBoolean = (key: StorageKey, value: boolean): void =>
|
export const setEntryBoolean = (key: StorageKey, value: boolean): void =>
|
||||||
localStorage.setItem(StorageKey[key], value.toString());
|
localStorage.setItem(StorageKey[key], value.toString());
|
||||||
|
|
||||||
|
export const setEntryObject = (key: StorageKey, value: unknown): void => {
|
||||||
|
localStorage.setItem(StorageKey[key], JSON.stringify(value));
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getEntryObject = <T>(key: StorageKey): T | null => {
|
||||||
|
const item = localStorage.getItem(StorageKey[key]);
|
||||||
|
if (item) {
|
||||||
|
return JSON.parse(item) as T;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
@ -27,6 +27,7 @@ export enum StorageKey {
|
|||||||
GalleryCalloutDismissed,
|
GalleryCalloutDismissed,
|
||||||
VisitedAccounts,
|
VisitedAccounts,
|
||||||
PriorityLevel,
|
PriorityLevel,
|
||||||
|
DocumentsTabPrefs,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const hasRUThresholdBeenConfigured = (): boolean => {
|
export const hasRUThresholdBeenConfigured = (): boolean => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user