-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[PM-11901] Refactoring self-hosting license file uploader #11083
[PM-11901] Refactoring self-hosting license file uploader #11083
Conversation
Codecov ReportAttention: Patch coverage is
✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## main #11083 +/- ##
==========================================
+ Coverage 35.07% 35.15% +0.08%
==========================================
Files 2718 2722 +4
Lines 84841 85033 +192
Branches 16134 16180 +46
==========================================
+ Hits 29757 29893 +136
- Misses 54106 54147 +41
- Partials 978 993 +15 ☔ View full report in Codecov by Sentry. |
No New Or Fixed Issues Found |
…e-from-organization-plans-change-plan-dialog-components
…sting-license-from-organization-plans-change-plan-dialog-components' into PM-11901-Refactor-Upload-self-hosting-license-from-organization-plans-change-plan-dialog-components
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great first pass! Please fix up the comments marked with ❌ and let me know what you think about the ⛏️ s.
@@ -0,0 +1,3 @@ | |||
export class LicenseUploadedEvent { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ Since this only encapsulates an organizationId, I'd argue could probably just do away with it to reduce our file count. The naming of the event emitter itself already clarifies what event your listening for in the parent component.
// Uploader .ts
@Output() onLicenseFileUploaded = new EventEmitter<string>();
// Parent .ts
protected onLicenseFileUploaded = async (organizationId: string) => {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally like the verbosity, so if the code needs to be extended it would be easier, or simply easier to read if you want to know what the string is for, but I will remove it.
apps/web/src/app/billing/shared/self-hosting-license-uploader/license-uploader-form-model.ts
Show resolved
Hide resolved
...ing/shared/self-hosting-license-uploader/abstract-self-hosting-license-uploader.component.ts
Show resolved
Hide resolved
* Shared implementation for processing license file uploads. | ||
* @remarks Requires self-hosting. | ||
*/ | ||
export abstract class AbstractSelfHostingLicenseUploaderComponent { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ I'll let you ultimately decide this because it's only a matter of style, but a more functional approach would be to combine all 3 of the license uploading components and then pass in what you need as inputs.
For example:
export class SelfHostLicenseUploaderComponent {
@Input({ required: true }) private description: string;
@Input({ required: true }) private hintFileName: string;
@Input({ required: true }) private onSubmit: File => Promise<void>;
}
The onSubmit
input can be passed in from the parent to tell the license uploader what specifically we want to do with the File
if the existing validation passes.
submit = async () => {
this.form.markAllAsTouched();
if (this.form.invalid) {
return this.toastService.showToast({
variant: "error",
title: this.i18nService.t("errorOccurred"),
message: this.i18nService.t("selectFile"),
});
}
const emailVerified = await this.tokenService.getEmailVerified();
if (!emailVerified) {
return this.toastService.showToast({
variant: "error",
title: this.i18nService.t("errorOccurred"),
message: this.i18nService.t("verifyEmailFirst"),
});
}
await this.onSubmit(this.form.value.file);
// You can either include the necessary post-processing in the `onSubmit` or emit an event to handle it in the parent.
}
Example of this approach in the manage-tax-information.component.
apps/web/src/app/billing/organizations/organization-plans.component.ts
Outdated
Show resolved
Hide resolved
apps/web/src/app/billing/individual/premium/premium-v2.component.ts
Outdated
Show resolved
Hide resolved
…e-from-organization-plans-change-plan-dialog-components
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good. Up to you on the remaining nitpicks, though it does look like you have a conflict at apps\web\src\app\billing\organizations\organization-plans.component.html
apps/web/src/app/billing/shared/self-hosting-license-uploader/license-uploader-form-model.ts
Show resolved
Hide resolved
…e-from-organization-plans-change-plan-dialog-components # Conflicts: # apps/web/src/app/billing/organizations/organization-plans.component.html
…e-from-organization-plans-change-plan-dialog-components # Conflicts: # apps/web/src/app/billing/organizations/organization-plans.component.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one change on the premium component template, otherwise looks good.
</ng-container> | ||
<individual-self-hosting-license-uploader | ||
*ngIf="useLicenseUploaderComponent$ | async" | ||
(onLicenseFileUploaded)="(onLicenseFileSelectedChanged)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amorask-bitwarden The warning is gone once I added the brackets.
🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-11901
📔 Objective
Deduplicate the code where self-hosting licenses are being uploaded for organizations. Some additional work was done for individual licenses.
📸 Screenshots
⏰ Reminders before review
🦮 Reviewer guidelines
:+1:
) or similar for great changes:memo:
) or ℹ️ (:information_source:
) for notes or general info:question:
) for questions:thinking:
) or 💭 (:thought_balloon:
) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion:art:
) for suggestions / improvements:x:
) or:warning:
) for more significant problems or concerns needing attention:seedling:
) or ♻️ (:recycle:
) for future improvements or indications of technical debt:pick:
) for minor or nitpick changes