2023-06-06 22:34:53 +02:00
|
|
|
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
2022-11-23 23:26:57 +01:00
|
|
|
import { DeepJsonify } from "@bitwarden/common/types/deep-jsonify";
|
2023-11-27 21:59:44 +01:00
|
|
|
import { CipherType } from "@bitwarden/common/vault/enums";
|
2023-01-31 22:08:37 +01:00
|
|
|
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
2023-06-14 14:38:24 +02:00
|
|
|
import { CollectionView } from "@bitwarden/common/vault/models/view/collection.view";
|
2023-01-31 22:08:37 +01:00
|
|
|
import { FolderView } from "@bitwarden/common/vault/models/view/folder.view";
|
2022-02-24 18:14:04 +01:00
|
|
|
|
2022-01-27 22:22:51 +01:00
|
|
|
import { BrowserComponentState } from "./browserComponentState";
|
|
|
|
|
|
|
|
export class BrowserGroupingsComponentState extends BrowserComponentState {
|
|
|
|
favoriteCiphers: CipherView[];
|
|
|
|
noFolderCiphers: CipherView[];
|
|
|
|
ciphers: CipherView[];
|
|
|
|
collectionCounts: Map<string, number>;
|
|
|
|
folderCounts: Map<string, number>;
|
|
|
|
typeCounts: Map<CipherType, number>;
|
|
|
|
folders: FolderView[];
|
|
|
|
collections: CollectionView[];
|
|
|
|
deletedCount: number;
|
2022-11-23 23:26:57 +01:00
|
|
|
|
|
|
|
toJSON() {
|
|
|
|
return Utils.merge(this, {
|
|
|
|
collectionCounts: Utils.mapToRecord(this.collectionCounts),
|
|
|
|
folderCounts: Utils.mapToRecord(this.folderCounts),
|
|
|
|
typeCounts: Utils.mapToRecord(this.typeCounts),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
static fromJSON(json: DeepJsonify<BrowserGroupingsComponentState>) {
|
|
|
|
if (json == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Object.assign(new BrowserGroupingsComponentState(), json, {
|
|
|
|
favoriteCiphers: json.favoriteCiphers?.map((c) => CipherView.fromJSON(c)),
|
|
|
|
noFolderCiphers: json.noFolderCiphers?.map((c) => CipherView.fromJSON(c)),
|
|
|
|
ciphers: json.ciphers?.map((c) => CipherView.fromJSON(c)),
|
|
|
|
collectionCounts: Utils.recordToMap(json.collectionCounts),
|
|
|
|
folderCounts: Utils.recordToMap(json.folderCounts),
|
|
|
|
typeCounts: Utils.recordToMap(json.typeCounts),
|
|
|
|
folders: json.folders?.map((f) => FolderView.fromJSON(f)),
|
|
|
|
});
|
|
|
|
}
|
2022-01-27 22:22:51 +01:00
|
|
|
}
|