diff --git a/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap b/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap index f69b1afa2..794d2beaf 100644 --- a/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap +++ b/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap @@ -962,13 +962,6 @@ exports[`SettingsComponent renders 1`] = ` "visible": [Function], }, "memoryUsageInfo": [Function], - "mostRecentActivity": MostRecentActivity { - "container": [Circular], - "storedData": Object { - "itemsMap": Object {}, - "schemaVersion": "1", - }, - }, "newVertexPane": NewVertexPane { "buildString": [Function], "container": [Circular], @@ -2178,13 +2171,6 @@ exports[`SettingsComponent renders 1`] = ` "visible": [Function], }, "memoryUsageInfo": [Function], - "mostRecentActivity": MostRecentActivity { - "container": [Circular], - "storedData": Object { - "itemsMap": Object {}, - "schemaVersion": "1", - }, - }, "newVertexPane": NewVertexPane { "buildString": [Function], "container": [Circular], @@ -3407,13 +3393,6 @@ exports[`SettingsComponent renders 1`] = ` "visible": [Function], }, "memoryUsageInfo": [Function], - "mostRecentActivity": MostRecentActivity { - "container": [Circular], - "storedData": Object { - "itemsMap": Object {}, - "schemaVersion": "1", - }, - }, "newVertexPane": NewVertexPane { "buildString": [Function], "container": [Circular], @@ -4623,13 +4602,6 @@ exports[`SettingsComponent renders 1`] = ` "visible": [Function], }, "memoryUsageInfo": [Function], - "mostRecentActivity": MostRecentActivity { - "container": [Circular], - "storedData": Object { - "itemsMap": Object {}, - "schemaVersion": "1", - }, - }, "newVertexPane": NewVertexPane { "buildString": [Function], "container": [Circular], diff --git a/src/Explorer/Explorer.tsx b/src/Explorer/Explorer.tsx index 8254ddf42..d9edf2b87 100644 --- a/src/Explorer/Explorer.tsx +++ b/src/Explorer/Explorer.tsx @@ -3,7 +3,6 @@ import * as ComponentRegisterer from "./ComponentRegisterer"; import * as Constants from "../Common/Constants"; import * as DataModels from "../Contracts/DataModels"; import * as ko from "knockout"; -import * as MostRecentActivity from "./MostRecentActivity/MostRecentActivity"; import * as path from "path"; import * as SharedConstants from "../Shared/Constants"; import * as ViewModels from "../Contracts/ViewModels"; @@ -140,7 +139,6 @@ export default class Explorer { public queriesClient: QueriesClient; public tableDataClient: TableDataClient; public splitter: Splitter; - public mostRecentActivity: MostRecentActivity.MostRecentActivity; // Notification Console private setIsNotificationConsoleExpanded: (isExpanded: boolean) => void; @@ -924,8 +922,6 @@ export default class Explorer { featureSubcription.dispose(); }); - - this.mostRecentActivity = new MostRecentActivity.MostRecentActivity(this); } public openEnableSynapseLinkDialog(): void { diff --git a/src/Explorer/MostRecentActivity/MostRecentActivity.ts b/src/Explorer/MostRecentActivity/MostRecentActivity.ts index 800cf1117..11f0c21a5 100644 --- a/src/Explorer/MostRecentActivity/MostRecentActivity.ts +++ b/src/Explorer/MostRecentActivity/MostRecentActivity.ts @@ -1,10 +1,5 @@ -import * as ViewModels from "../../Contracts/ViewModels"; import { StorageKey, LocalStorageUtility } from "../../Shared/StorageUtility"; -import CollectionIcon from "../../../images/tree-collection.svg"; -import NotebookIcon from "../../../images/notebook/Notebook-resource.svg"; -import Explorer from "../Explorer"; - export enum Type { OpenCollection, OpenNotebook, @@ -36,11 +31,11 @@ interface StoredData { /** * Stores most recent activity */ -export class MostRecentActivity { +class MostRecentActivity { private static readonly schemaVersion: string = "1"; private static itemsMaxNumber: number = 5; private storedData: StoredData; - constructor(private container: Explorer) { + constructor() { // Retrieve from local storage if (LocalStorageUtility.hasItem(StorageKey.MostRecentActivity)) { const rawData = LocalStorageUtility.getEntryString(StorageKey.MostRecentActivity); @@ -121,42 +116,6 @@ export class MostRecentActivity { this.saveToLocalStorage(); } - public onItemClicked(item: Item) { - switch (item.type) { - case Type.OpenCollection: { - const openCollectionitem = item.data as OpenCollectionItem; - const collection = this.container.findCollection( - openCollectionitem.databaseId, - openCollectionitem.collectionId - ); - if (collection) { - collection.openTab(); - } - break; - } - case Type.OpenNotebook: { - const openNotebookItem = item.data as OpenNotebookItem; - const notebookItem = this.container.createNotebookContentItemFile(openNotebookItem.name, openNotebookItem.path); - notebookItem && this.container.openNotebook(notebookItem); - break; - } - default: - console.error("Unknown item type", item); - break; - } - } - - public static getItemIcon(item: Item): string { - switch (item.type) { - case Type.OpenCollection: - return CollectionIcon; - case Type.OpenNotebook: - return NotebookIcon; - default: - return null; - } - } - /** * Find items by doing strict comparison and remove from array if duplicate is found * @param item @@ -203,3 +162,5 @@ export class MostRecentActivity { } } } + +export const mostRecentActivity = new MostRecentActivity(); diff --git a/src/Explorer/SplashScreen/SplashScreen.tsx b/src/Explorer/SplashScreen/SplashScreen.tsx index aab72c6c2..c6e55c7c7 100644 --- a/src/Explorer/SplashScreen/SplashScreen.tsx +++ b/src/Explorer/SplashScreen/SplashScreen.tsx @@ -18,6 +18,8 @@ import { DataSamplesUtil } from "../DataSamples/DataSamplesUtil"; import Explorer from "../Explorer"; import { userContext } from "../../UserContext"; import { FeaturePanelLauncher } from "../Controls/FeaturePanel/FeaturePanelLauncher"; +import CollectionIcon from "../../../images/tree-collection.svg"; +import NotebookIcon from "../../../images/notebook/Notebook-resource.svg"; export interface SplashScreenItem { iconSrc: string; @@ -53,7 +55,7 @@ export class SplashScreen extends React.Component { } private clearMostRecent = (): void => { - this.container.mostRecentActivity.clear(userContext.databaseAccount?.id); + MostRecentActivity.mostRecentActivity.clear(userContext.databaseAccount?.id); this.setState({}); }; @@ -202,6 +204,42 @@ export class SplashScreen extends React.Component { return heroes; } + private getItemIcon(item: MostRecentActivity.Item): string { + switch (item.type) { + case MostRecentActivity.Type.OpenCollection: + return CollectionIcon; + case MostRecentActivity.Type.OpenNotebook: + return NotebookIcon; + default: + return null; + } + } + + private onItemClicked(item: MostRecentActivity.Item) { + switch (item.type) { + case MostRecentActivity.Type.OpenCollection: { + const openCollectionitem = item.data as MostRecentActivity.OpenCollectionItem; + const collection = this.container.findCollection( + openCollectionitem.databaseId, + openCollectionitem.collectionId + ); + if (collection) { + collection.openTab(); + } + break; + } + case MostRecentActivity.Type.OpenNotebook: { + const openNotebookItem = item.data as MostRecentActivity.OpenNotebookItem; + const notebookItem = this.container.createNotebookContentItemFile(openNotebookItem.name, openNotebookItem.path); + notebookItem && this.container.openNotebook(notebookItem); + break; + } + default: + console.error("Unknown item type", item); + break; + } + } + private createCommonTaskItems(): SplashScreenItem[] { const items: SplashScreenItem[] = []; @@ -292,12 +330,12 @@ export class SplashScreen extends React.Component { } private createRecentItems(): SplashScreenItem[] { - return this.container.mostRecentActivity.getItems(userContext.databaseAccount?.id).map((item) => ({ - iconSrc: MostRecentActivity.MostRecentActivity.getItemIcon(item), + return MostRecentActivity.mostRecentActivity.getItems(userContext.databaseAccount?.id).map((item) => ({ + iconSrc: this.getItemIcon(item), title: item.title, description: item.description, info: SplashScreen.getInfo(item), - onClick: () => this.container.mostRecentActivity.onItemClicked(item), + onClick: () => this.onItemClicked(item), })); } diff --git a/src/Explorer/Tree/ResourceTreeAdapter.tsx b/src/Explorer/Tree/ResourceTreeAdapter.tsx index ad86c4d78..46831c9de 100644 --- a/src/Explorer/Tree/ResourceTreeAdapter.tsx +++ b/src/Explorer/Tree/ResourceTreeAdapter.tsx @@ -264,7 +264,7 @@ export class ResourceTreeAdapter implements ReactAdapter { onClick: () => { collection.openTab(); // push to most recent - this.container.mostRecentActivity.addItem(userContext.databaseAccount?.id, { + MostRecentActivity.mostRecentActivity.addItem(userContext.databaseAccount?.id, { type: MostRecentActivity.Type.OpenCollection, title: collection.id(), description: "Data", @@ -625,7 +625,7 @@ export class ResourceTreeAdapter implements ReactAdapter { } private pushItemToMostRecent(item: NotebookContentItem) { - this.container.mostRecentActivity.addItem(userContext.databaseAccount?.id, { + MostRecentActivity.mostRecentActivity.addItem(userContext.databaseAccount?.id, { type: MostRecentActivity.Type.OpenNotebook, title: item.name, description: "Notebook", diff --git a/src/Explorer/Tree/ResourceTreeAdapterForResourceToken.test.tsx b/src/Explorer/Tree/ResourceTreeAdapterForResourceToken.test.tsx index c5dbe9986..9398747fa 100644 --- a/src/Explorer/Tree/ResourceTreeAdapterForResourceToken.test.tsx +++ b/src/Explorer/Tree/ResourceTreeAdapterForResourceToken.test.tsx @@ -13,7 +13,6 @@ const createMockContainer = (): Explorer => { let mockContainer = {} as Explorer; mockContainer.resourceTokenCollection = createMockCollection(mockContainer); mockContainer.selectedNode = ko.observable(); - mockContainer.mostRecentActivity = new MostRecentActivity.MostRecentActivity(mockContainer); mockContainer.onUpdateTabsButtons = () => {}; return mockContainer; diff --git a/src/Explorer/Tree/ResourceTreeAdapterForResourceToken.tsx b/src/Explorer/Tree/ResourceTreeAdapterForResourceToken.tsx index b7bc32c08..ca971a1a1 100644 --- a/src/Explorer/Tree/ResourceTreeAdapterForResourceToken.tsx +++ b/src/Explorer/Tree/ResourceTreeAdapterForResourceToken.tsx @@ -44,7 +44,7 @@ export class ResourceTreeAdapterForResourceToken implements ReactAdapter { onClick: () => { collection.onDocumentDBDocumentsClick(); // push to most recent - this.container.mostRecentActivity.addItem(userContext.databaseAccount?.id, { + MostRecentActivity.mostRecentActivity.addItem(userContext.databaseAccount?.id, { type: MostRecentActivity.Type.OpenCollection, title: collection.id(), description: "Data",