mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-22 02:11:29 +00:00
Migrate Copilot local persistence (toggle and prompt history) to new local storage infrastructure (#1948)
* Migrate copilot persistence to AppState * Migrate persistence of toggle and history to new infra * Save toggle value as boolean * Fix compile bug * Fix unit tests
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
AppStateComponentNames,
|
||||
createKeyFromPath,
|
||||
deleteState,
|
||||
loadState,
|
||||
@@ -20,7 +21,7 @@ jest.mock("Shared/StorageUtility", () => ({
|
||||
|
||||
describe("AppStatePersistenceUtility", () => {
|
||||
const storePath = {
|
||||
componentName: "a",
|
||||
componentName: AppStateComponentNames.DocumentsTab,
|
||||
subComponentName: "b",
|
||||
globalAccountName: "c",
|
||||
databaseName: "d",
|
||||
@@ -176,10 +177,10 @@ describe("AppStatePersistenceUtility", () => {
|
||||
|
||||
it("should handle components that include special characters", () => {
|
||||
const storePath = {
|
||||
componentName: "a/b/c",
|
||||
componentName: AppStateComponentNames.DocumentsTab,
|
||||
subComponentName: 'd"e"f',
|
||||
globalAccountName: "g:h",
|
||||
databaseName: "i{j",
|
||||
globalAccountName: "g:hi{j",
|
||||
databaseName: "a/b/c",
|
||||
containerName: "https://blahblah.document.azure.com:443/",
|
||||
};
|
||||
const key = createKeyFromPath(storePath);
|
||||
@@ -190,10 +191,9 @@ describe("AppStatePersistenceUtility", () => {
|
||||
const expectSubstringsInValue = (value: string, subStrings: string[]): boolean =>
|
||||
subStrings.every((subString) => value.includes(subString));
|
||||
|
||||
expect(expectSubstringsInValue(segments[1], ["a", "b", "c"])).toBe(true);
|
||||
expect(expectSubstringsInValue(segments[2], ["d", "e", "f"])).toBe(true);
|
||||
expect(expectSubstringsInValue(segments[3], ["g", "h"])).toBe(true);
|
||||
expect(expectSubstringsInValue(segments[4], ["i", "j"])).toBe(true);
|
||||
expect(expectSubstringsInValue(segments[3], ["g", "hi", "j"])).toBe(true);
|
||||
expect(expectSubstringsInValue(segments[4], ["a", "b", "c"])).toBe(true);
|
||||
expect(expectSubstringsInValue(segments[5], ["https", "blahblah", "document", "com", "443"])).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { LocalStorageUtility, StorageKey } from "Shared/StorageUtility";
|
||||
|
||||
// The component name whose state is being saved. Component name must not include special characters.
|
||||
export type ComponentName = "DocumentsTab";
|
||||
export enum AppStateComponentNames {
|
||||
DocumentsTab = "DocumentsTab",
|
||||
QueryCopilot = "QueryCopilot",
|
||||
}
|
||||
|
||||
export const PATH_SEPARATOR = "/"; // export for testing purposes
|
||||
const SCHEMA_VERSION = 1;
|
||||
|
||||
@@ -14,8 +18,9 @@ export interface StateData {
|
||||
data: unknown;
|
||||
}
|
||||
|
||||
type StorePath = {
|
||||
componentName: string;
|
||||
// Export for testing purposes
|
||||
export type StorePath = {
|
||||
componentName: AppStateComponentNames;
|
||||
subComponentName?: string;
|
||||
globalAccountName?: string;
|
||||
databaseName?: string;
|
||||
|
||||
Reference in New Issue
Block a user