mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-29 05:41:40 +00:00
69 lines
1.9 KiB
TypeScript
69 lines
1.9 KiB
TypeScript
// Definitions of State data
|
|
|
|
import { loadState, saveState, saveStateDebounced } from "Shared/AppStatePersistenceUtility";
|
|
import { userContext } from "UserContext";
|
|
import * as ViewModels from "../../../Contracts/ViewModels";
|
|
|
|
// Component states
|
|
export interface DocumentsTabStateData {
|
|
leftPaneWidthPercent: number;
|
|
}
|
|
|
|
const defaultState: DocumentsTabStateData = {
|
|
leftPaneWidthPercent: 35,
|
|
};
|
|
|
|
const ComponentName = "DocumentsTab";
|
|
|
|
export const readDocumentsTabState = (): DocumentsTabStateData => {
|
|
const state = loadState({ componentName: ComponentName });
|
|
return (state as DocumentsTabStateData) || defaultState;
|
|
};
|
|
|
|
export const saveDocumentsTabState = (state: DocumentsTabStateData): void => {
|
|
saveStateDebounced({ componentName: ComponentName }, state);
|
|
};
|
|
|
|
export type ColumnSizesMap = { [columnId: string]: WidthDefinition };
|
|
export type WidthDefinition = { idealWidth?: number; minWidth?: number };
|
|
|
|
export const readSubComponentState = <T>(
|
|
subComponentName: "ColumnSizes" | "FilterHistory",
|
|
collection: ViewModels.CollectionBase,
|
|
defaultValue: T,
|
|
): T => {
|
|
const globalAccountName = userContext.databaseAccount?.name;
|
|
// TODO what if databaseAccount doesn't exist?
|
|
|
|
const state = loadState({
|
|
componentName: ComponentName,
|
|
subComponentName,
|
|
globalAccountName,
|
|
databaseName: collection.databaseId,
|
|
containerName: collection.id(),
|
|
}) as T;
|
|
|
|
return state || defaultValue;
|
|
};
|
|
|
|
export const saveSubComponentState = <T>(
|
|
subComponentName: "ColumnSizes" | "FilterHistory",
|
|
collection: ViewModels.CollectionBase,
|
|
state: T,
|
|
debounce?: boolean,
|
|
): void => {
|
|
const globalAccountName = userContext.databaseAccount?.name;
|
|
// TODO what if databaseAccount doesn't exist?
|
|
|
|
(debounce ? saveStateDebounced : saveState)(
|
|
{
|
|
componentName: ComponentName,
|
|
subComponentName,
|
|
globalAccountName,
|
|
databaseName: collection.databaseId,
|
|
containerName: collection.id(),
|
|
},
|
|
state,
|
|
);
|
|
};
|