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:
Laurent Nguyen
2024-09-13 12:01:14 +02:00
committed by GitHub
parent d7647b2ecf
commit 91649d2f52
11 changed files with 207 additions and 70 deletions

View File

@@ -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);
});
});

View File

@@ -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;