-
Notifications
You must be signed in to change notification settings - Fork 1.5k
PM-22143 Refactor TS enums to be const objects (Send specific enums) #16399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
6937282
a1b316f
4e68f24
6828f69
bb89cd9
8fff591
0e94644
30fd988
dae7d41
949f6a5
adbbf6a
83c2b92
a2e1081
948c6e3
9ef9c32
970bc9f
38dbe74
196dcbe
19f5e10
0577917
e1875a9
0517e28
19d4a02
356ffb1
a911b08
30b430a
9b8b8aa
c0255ba
2314d44
542e2c3
b34f4ea
4f2461d
6e30700
8265b7c
8641595
380fad1
b1b5f2f
8614dcf
4da1fa1
6d58a91
a4e4a70
c97b17a
687ca14
1d52c7a
624109e
e6c16b7
7fc47f2
a78c779
63c3049
5884b00
95f07c6
af4da3e
2993d93
ee785f2
57a7ba6
992f11f
4345d72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,7 +37,7 @@ import { PopupHeaderComponent } from "../../../platform/popup/layout/popup-heade | |
| import { PopupPageComponent } from "../../../platform/popup/layout/popup-page.component"; | ||
| import { PopupRouterCacheService } from "../../../platform/popup/view-cache/popup-router-cache.service"; | ||
|
|
||
| import { SendV2Component, SendState } from "./send-v2.component"; | ||
| import { SendV2Component } from "./send-v2.component"; | ||
|
|
||
| describe("SendV2Component", () => { | ||
| let component: SendV2Component; | ||
|
|
@@ -142,12 +142,12 @@ describe("SendV2Component", () => { | |
| it("should set listState to Empty when emptyList$ emits true", () => { | ||
| sendItemsServiceEmptyList$.next(true); | ||
| fixture.detectChanges(); | ||
| expect(component["listState"]).toBe(SendState.Empty); | ||
| expect(component["listState"]).toBe(component["sendState"].Empty); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: Why are we modifying this? The |
||
| }); | ||
|
|
||
| it("should set listState to NoResults when noFilteredResults$ emits true", () => { | ||
| sendItemsServiceNoFilteredResults$.next(true); | ||
| fixture.detectChanges(); | ||
| expect(component["listState"]).toBe(SendState.NoResults); | ||
| expect(component["listState"]).toBe(component["sendState"].NoResults); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: Why are we modifying this? The |
||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,12 +30,12 @@ import { PopOutComponent } from "../../../platform/popup/components/pop-out.comp | |
| import { PopupHeaderComponent } from "../../../platform/popup/layout/popup-header.component"; | ||
| import { PopupPageComponent } from "../../../platform/popup/layout/popup-page.component"; | ||
|
|
||
| // FIXME: update to use a const object instead of a typescript enum | ||
| // eslint-disable-next-line @bitwarden/platform/no-enums | ||
| export enum SendState { | ||
| Empty, | ||
| NoResults, | ||
| } | ||
| export const SendState = Object.freeze({ | ||
| Empty: "Empty", | ||
| NoResults: "NoResults", | ||
| } as const); | ||
|
|
||
| export type SendState = (typeof SendState)[keyof typeof SendState]; | ||
audreyality marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Component({ | ||
| templateUrl: "send-v2.component.html", | ||
|
|
@@ -83,7 +83,7 @@ export class SendV2Component implements OnDestroy { | |
| .pipe(takeUntilDestroyed()) | ||
| .subscribe(([emptyList, noFilteredResults, currentFilter]) => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to add types for the args |
||
| if (currentFilter?.sendType !== null) { | ||
| this.title = `${this.sendType[currentFilter.sendType].toLowerCase()}Sends`; | ||
| this.title = `${currentFilter.sendType === SendType.File ? "file" : "text"}Sends`; | ||
| } else { | ||
| this.title = "allSends"; | ||
| } | ||
audreyality marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could be this to avoid nested if conditions if (currentFilter?.sendType != null) { this.title = titleMap[currentFilter.sendType] ?? 'allSends'; |
||
|
|
||
djsmith85 marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,19 +35,18 @@ import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.s | |
| import { SendService } from "@bitwarden/common/tools/send/services/send.service.abstraction"; | ||
| import { DialogService, ToastService } from "@bitwarden/components"; | ||
|
|
||
| // Value = hours | ||
| // FIXME: update to use a const object instead of a typescript enum | ||
| // eslint-disable-next-line @bitwarden/platform/no-enums | ||
| enum DatePreset { | ||
| OneHour = 1, | ||
| OneDay = 24, | ||
| TwoDays = 48, | ||
| ThreeDays = 72, | ||
| SevenDays = 168, | ||
| ThirtyDays = 720, | ||
| Custom = 0, | ||
| Never = null, | ||
| } | ||
| export const DatePreset = Object.freeze({ | ||
Hinton marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| OneHour: 1, | ||
| OneDay: 24, | ||
| TwoDays: 48, | ||
| ThreeDays: 72, | ||
| SevenDays: 168, | ||
| ThirtyDays: 720, | ||
| Custom: 0, | ||
| Never: -1, | ||
|
||
| } as const); | ||
|
|
||
| export type DatePreset = (typeof DatePreset)[keyof typeof DatePreset]; | ||
|
|
||
| interface DatePresetSelectOption { | ||
| name: string; | ||
|
|
@@ -114,7 +113,7 @@ export class AddEditComponent implements OnInit, OnDestroy { | |
| type: [], | ||
| defaultExpirationDateTime: [], | ||
| defaultDeletionDateTime: ["", Validators.required], | ||
| selectedDeletionDatePreset: [DatePreset.SevenDays, Validators.required], | ||
| selectedDeletionDatePreset: [DatePreset.SevenDays as DatePreset, Validators.required], | ||
audreyality marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| selectedExpirationDatePreset: [], | ||
| }); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| // FIXME: update to use a const object instead of a typescript enum | ||
| // eslint-disable-next-line @bitwarden/platform/no-enums | ||
| export enum SendType { | ||
| Text = 0, | ||
| File = 1, | ||
| } | ||
| export const SendType = Object.freeze({ | ||
| Text: 0, | ||
| File: 1, | ||
| } as const); | ||
|
|
||
| export type SendType = (typeof SendType)[keyof typeof SendType]; | ||
audreyality marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| // FIXME: update to use a const object instead of a typescript enum | ||
| // eslint-disable-next-line @bitwarden/platform/no-enums | ||
| export enum EncryptedExportType { | ||
| AccountEncrypted = 0, | ||
| FileEncrypted = 1, | ||
| } | ||
| export const EncryptedExportType = Object.freeze({ | ||
| AccountEncrypted: 0, | ||
| FileEncrypted: 1, | ||
| } as const); | ||
|
|
||
| export type EncryptedExportType = (typeof EncryptedExportType)[keyof typeof EncryptedExportType]; | ||
audreyality marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Uh oh!
There was an error while loading. Please reload this page.