[PM-7352] - Browser Send Type Groupings Fix (#8727)

* Removed type counts and just calculated counts off the sends

* Fixing key spec test case
This commit is contained in:
Tom 2024-04-17 10:39:15 -04:00 committed by GitHub
parent 1cde2dbaef
commit 3179867310
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 7 additions and 36 deletions

View File

@ -1,5 +1,3 @@
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { SendType } from "@bitwarden/common/tools/send/enums/send-type";
import { SendView } from "@bitwarden/common/tools/send/models/view/send.view"; import { SendView } from "@bitwarden/common/tools/send/models/view/send.view";
import { DeepJsonify } from "@bitwarden/common/types/deep-jsonify"; import { DeepJsonify } from "@bitwarden/common/types/deep-jsonify";
@ -7,13 +5,6 @@ import { BrowserComponentState } from "./browserComponentState";
export class BrowserSendComponentState extends BrowserComponentState { export class BrowserSendComponentState extends BrowserComponentState {
sends: SendView[]; sends: SendView[];
typeCounts: Map<SendType, number>;
toJSON() {
return Utils.merge(this, {
typeCounts: Utils.mapToRecord(this.typeCounts),
});
}
static fromJSON(json: DeepJsonify<BrowserSendComponentState>) { static fromJSON(json: DeepJsonify<BrowserSendComponentState>) {
if (json == null) { if (json == null) {
@ -22,7 +13,6 @@ export class BrowserSendComponentState extends BrowserComponentState {
return Object.assign(new BrowserSendComponentState(), json, { return Object.assign(new BrowserSendComponentState(), json, {
sends: json.sends?.map((s) => SendView.fromJSON(s)), sends: json.sends?.map((s) => SendView.fromJSON(s)),
typeCounts: Utils.recordToMap(json.typeCounts),
}); });
} }
} }

View File

@ -61,7 +61,7 @@
<div class="icon"><i class="bwi bwi-fw bwi-lg bwi-file-text"></i></div> <div class="icon"><i class="bwi bwi-fw bwi-lg bwi-file-text"></i></div>
<span class="text">{{ "sendTypeText" | i18n }}</span> <span class="text">{{ "sendTypeText" | i18n }}</span>
</div> </div>
<span class="row-sub-label">{{ typeCounts.get(sendType.Text) || 0 }}</span> <span class="row-sub-label">{{ getSendCount(sends, sendType.Text) }}</span>
<span><i class="bwi bwi-angle-right bwi-lg row-sub-icon"></i></span> <span><i class="bwi bwi-angle-right bwi-lg row-sub-icon"></i></span>
</button> </button>
<button <button
@ -74,7 +74,7 @@
<div class="icon"><i class="bwi bwi-fw bwi-lg bwi-file"></i></div> <div class="icon"><i class="bwi bwi-fw bwi-lg bwi-file"></i></div>
<span class="text">{{ "sendTypeFile" | i18n }}</span> <span class="text">{{ "sendTypeFile" | i18n }}</span>
</div> </div>
<span class="row-sub-label">{{ typeCounts.get(sendType.File) || 0 }}</span> <span class="row-sub-label">{{ getSendCount(sends, sendType.File) }}</span>
<span><i class="bwi bwi-angle-right bwi-lg row-sub-icon"></i></span> <span><i class="bwi bwi-angle-right bwi-lg row-sub-icon"></i></span>
</button> </button>
</div> </div>

View File

@ -29,8 +29,6 @@ const ComponentId = "SendComponent";
export class SendGroupingsComponent extends BaseSendComponent { export class SendGroupingsComponent extends BaseSendComponent {
// Header // Header
showLeftHeader = true; showLeftHeader = true;
// Send Type Calculations
typeCounts = new Map<SendType, number>();
// State Handling // State Handling
state: BrowserSendComponentState; state: BrowserSendComponentState;
private loadedTimeout: number; private loadedTimeout: number;
@ -65,7 +63,6 @@ export class SendGroupingsComponent extends BaseSendComponent {
dialogService, dialogService,
); );
super.onSuccessfulLoad = async () => { super.onSuccessfulLoad = async () => {
this.calculateTypeCounts();
this.selectAll(); this.selectAll();
}; };
} }
@ -174,17 +171,8 @@ export class SendGroupingsComponent extends BaseSendComponent {
return this.hasSearched || (!this.searchPending && this.isSearchable); return this.hasSearched || (!this.searchPending && this.isSearchable);
} }
private calculateTypeCounts() { getSendCount(sends: SendView[], type: SendType): number {
// Create type counts return sends.filter((s) => s.type === type).length;
const typeCounts = new Map<SendType, number>();
this.sends.forEach((s) => {
if (typeCounts.has(s.type)) {
typeCounts.set(s.type, typeCounts.get(s.type) + 1);
} else {
typeCounts.set(s.type, 1);
}
});
this.typeCounts = typeCounts;
} }
private async saveState() { private async saveState() {
@ -192,7 +180,6 @@ export class SendGroupingsComponent extends BaseSendComponent {
scrollY: BrowserPopupUtils.getContentScrollY(window), scrollY: BrowserPopupUtils.getContentScrollY(window),
searchText: this.searchText, searchText: this.searchText,
sends: this.sends, sends: this.sends,
typeCounts: this.typeCounts,
}); });
await this.stateService.setBrowserSendComponentState(this.state); await this.stateService.setBrowserSendComponentState(this.state);
} }
@ -206,9 +193,6 @@ export class SendGroupingsComponent extends BaseSendComponent {
if (this.state.sends != null) { if (this.state.sends != null) {
this.sends = this.state.sends; this.sends = this.state.sends;
} }
if (this.state.typeCounts != null) {
this.typeCounts = this.state.typeCounts;
}
return true; return true;
} }

View File

@ -6,7 +6,6 @@ import { FakeStateProvider } from "@bitwarden/common/../spec/fake-state-provider
import { awaitAsync } from "@bitwarden/common/../spec/utils"; import { awaitAsync } from "@bitwarden/common/../spec/utils";
import { Utils } from "@bitwarden/common/platform/misc/utils"; import { Utils } from "@bitwarden/common/platform/misc/utils";
import { SendType } from "@bitwarden/common/tools/send/enums/send-type";
import { UserId } from "@bitwarden/common/types/guid"; import { UserId } from "@bitwarden/common/types/guid";
import { BrowserComponentState } from "../../../models/browserComponentState"; import { BrowserComponentState } from "../../../models/browserComponentState";
@ -33,7 +32,6 @@ describe("Browser Send State Service", () => {
const state = new BrowserSendComponentState(); const state = new BrowserSendComponentState();
state.scrollY = 0; state.scrollY = 0;
state.searchText = "test"; state.searchText = "test";
state.typeCounts = new Map<SendType, number>().set(SendType.File, 1);
await stateService.setBrowserSendComponentState(state); await stateService.setBrowserSendComponentState(state);

View File

@ -42,7 +42,7 @@ export class BrowserSendStateService {
} }
/** Set the active user's browser send component state /** Set the active user's browser send component state
* @param { BrowserSendComponentState } value sets the sends and type counts along with the scroll position and search text for * @param { BrowserSendComponentState } value sets the sends along with the scroll position and search text for
* the send component on the browser * the send component on the browser
*/ */
async setBrowserSendComponentState(value: BrowserSendComponentState): Promise<void> { async setBrowserSendComponentState(value: BrowserSendComponentState): Promise<void> {

View File

@ -1,7 +1,5 @@
import { Jsonify } from "type-fest"; import { Jsonify } from "type-fest";
import { SendType } from "@bitwarden/common/tools/send/enums/send-type";
import { BrowserSendComponentState } from "../../../models/browserSendComponentState"; import { BrowserSendComponentState } from "../../../models/browserSendComponentState";
import { BROWSER_SEND_COMPONENT, BROWSER_SEND_TYPE_COMPONENT } from "./key-definitions"; import { BROWSER_SEND_COMPONENT, BROWSER_SEND_TYPE_COMPONENT } from "./key-definitions";
@ -12,7 +10,8 @@ describe("Key definitions", () => {
const keyDef = BROWSER_SEND_COMPONENT; const keyDef = BROWSER_SEND_COMPONENT;
const expectedState = { const expectedState = {
typeCounts: new Map<SendType, number>(), scrollY: 0,
searchText: "test",
}; };
const result = keyDef.deserializer( const result = keyDef.deserializer(