1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-24 03:32:51 +02:00
bitwarden-browser/apps/browser/src/models/browserGroupingsComponentState.ts
Oscar Hinton a5e3432f85
Assign ownership to many libs files (#6928)
Assign ownership to many of the remaining libs/common files.

Criteria for ownership:
* Files used by a single team, is now owned by that team.
* Files related to a domain owned by a team is now owned by that team.
* Where ownership is unclear the "lowest level" service takes ownership.
2023-11-27 20:59:44 +00:00

45 lines
1.7 KiB
TypeScript

import { Utils } from "@bitwarden/common/platform/misc/utils";
import { DeepJsonify } from "@bitwarden/common/types/deep-jsonify";
import { CipherType } from "@bitwarden/common/vault/enums";
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
import { CollectionView } from "@bitwarden/common/vault/models/view/collection.view";
import { FolderView } from "@bitwarden/common/vault/models/view/folder.view";
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;
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)),
});
}
}