mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-01-31 13:16:43 +00:00
Remove Explorer.mostRecentActivity (#455)
This also moves the UI concerns of MostRecentActivity over to SplashScreen Co-authored-by: Steve Faulkner <stfaul@microsoft.com>
This commit is contained in:
parent
3cd2ec93f2
commit
7188e8d8c2
@ -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],
|
||||
|
@ -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 {
|
||||
|
@ -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();
|
||||
|
@ -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<SplashScreenProps> {
|
||||
}
|
||||
|
||||
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<SplashScreenProps> {
|
||||
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<SplashScreenProps> {
|
||||
}
|
||||
|
||||
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),
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -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",
|
||||
|
@ -13,7 +13,6 @@ const createMockContainer = (): Explorer => {
|
||||
let mockContainer = {} as Explorer;
|
||||
mockContainer.resourceTokenCollection = createMockCollection(mockContainer);
|
||||
mockContainer.selectedNode = ko.observable<ViewModels.TreeNode>();
|
||||
mockContainer.mostRecentActivity = new MostRecentActivity.MostRecentActivity(mockContainer);
|
||||
mockContainer.onUpdateTabsButtons = () => {};
|
||||
|
||||
return mockContainer;
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user