Skip to content
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

13577 Cleanup before upgrade #443

Merged
merged 1 commit into from
Sep 14, 2022
Merged

Conversation

severinbeauvais
Copy link
Collaborator

Issue #: bcgov/entity#13577

Description of changes:

  • pre-upgrade (lint and other misc cleanup)
  • app version = 4.2.1

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the bcrs-entities-create-ui license (Apache 2.0).

"version": "7.2.5",
"resolved": "https://registry.npmjs.org/vue-class-component/-/vue-class-component-7.2.5.tgz",
"integrity": "sha512-0CSftHY0bDTD+4FbYkuFf6+iKDjZ4h2in2YYJDRMk5daZIjrgT9LjFHvP7Rzqy9/s1pij3zDtTSLRUjsPWMwqg==",
"version": "7.2.6",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a normal patch upgrade, seen here because I totally rebuild this package lock file. It should have no effect.

@@ -444,7 +446,7 @@ export default class App extends Mixins(
}

/** Called when component is created. */
async created (): Promise<void> {
protected async created (): Promise<void> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created() should not be public.

@@ -498,7 +500,7 @@ export default class App extends Mixins(
}

/** Called when component is destroyed. */
private destroyed (): void {
protected beforeDestroy (): void {
Copy link
Collaborator Author

@severinbeauvais severinbeauvais Sep 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the new lifecycle event name in Vue3 but it's backward-compatible with Vue2.

@@ -161,12 +161,12 @@ export default class AssociationDetails extends Mixins(CommonMixin, EnumMixin, D
}

/** Whether the address object is empty. */
private isEmptyAddress (address: AddressIF): boolean {
protected isEmptyAddress (address: AddressIF): boolean {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isEmptyAddress() needs to be protected so the template (HTML) can call it. (This is not yet enforced by the framework but this is correct and the previous code was incorrect.)

@Prop({ default: false }) readonly showErrors!: boolean

// Global getter
@Getter getCooperativeType!: CoopTypes

// Local properties
private readonly items: Array<any> = [
readonly items: Array<any> = [
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is safe without being private because external code still can't change it.


// Date Time Selectors
private hours: Array<string> = [...Array(12).keys()]
readonly hours: Array<string> = [...Array(12).keys()]
.map(num => (++num).toLocaleString('en-US'))
Copy link
Collaborator Author

@severinbeauvais severinbeauvais Sep 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a "constant" (but needs to be declared as readonly because it's a class member).

These variables don't change. One more way of saying it is: they are static.

@@ -152,21 +154,21 @@ export default class IncorporationDateTime extends Mixins(DateMixin) {
}

/** The array of validations rules for effective date hours field. */
private get hourRules (): Array<Function> {
get hourRules (): Array<Function> {
return [
v => this.dateText !== '' && (/^([1-9]|1[012])$/.test(v) || '')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cannot be a readonly array because it uses a variable in its code. So it's a getter instead.

const date = new Date(this.getCurrentJsDate) // make a copy
date.setDate(date.getDate() + 10)
return this.dateToYyyyMmDd(date)
}

/** The minimum time that can be entered (now + 3 minutes). */
private minTime (): string {
protected minTime (): string {
const date = this.getCurrentJsDate
return new Date(date.getTime() + 180000)
.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', hour12: true })
}
Copy link
Collaborator Author

@severinbeauvais severinbeauvais Sep 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could probably be a getter instead of a function but changing it is really out of scope for this cleanup.

@@ -53,14 +53,14 @@ export default class BusinessTypeConfirm extends Vue {
protected checked = false
protected label = 'General Partnership'
protected labelSP = 'BC Sole Proprietorship / Doing Business As (DBA) Registration'
protected text = `I acknowledge that a General Partnership cannot be \
changed into a Sole Proprietorship (including DBA). If this is \
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest ES Lint tried to reformat this in a way that's incompatible with our current framework so I manually reformatted this into something ES Lint likes.

@@ -113,8 +113,8 @@ export default class BusinessContactInfo extends Mixins(CommonMixin) {
// Rules for template
readonly Rules = Rules

private contact: ContactPointIF = this.initialValue
private formValid: boolean = false
protected contact = this.initialValue
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contact gets its type from initialValue.

@@ -104,7 +104,7 @@
class="pt-0 mt-0"
v-model="hasNameTranslation"
id="name-translation-checkbox"
@click.native="confirmNameTranslation()"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not supported in Vue3 but I tested this and this code works correctly without it.

// State of the checkbox for determining whether the Record address is the same as the Registered address
private inheritRegisteredAddress: boolean = true
/** State of the checkbox for determining whether the Record address is the same as the Registered address. */
private inheritRegisteredAddress = true
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment in JS Doc format allows VS Code to display the comment when hovering over the variable.

@@ -43,17 +44,17 @@ async function start () {
// must come first as inits below depend on config
await fetchConfig()

if (window['sentryEnable'] === 'true') {
if ((window as any).sentryEnable === 'true') {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ES Lint wanted to change this to window.sentryEnable but the window object doesn't have that property and this caused an error.

The correct to fix this is to extend the window object to declare any additional properties ... I'm calling that out of scope for this cleanup.

@@ -5,10 +5,9 @@ import { CorpTypeCd, DissolutionStatementTypes } from '@/enums'
import { DissolutionResources } from '@/resources'

// Input field selectors to test changes to the DOM elements.
const typeSelector: string = '#dissolution-statement-'
const summaryErrorSelector: string = '.invalid-section'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't used.

details: {},
applicant: {},
details: {} as NameRequestDetailsIF,
applicant: {} as NameRequestApplicantIF,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should probably be null and handled accordingly in code but that's out of scope for this cleanup.

What I did here is remove the {} union type from details to pre-empt an error where details.approvedName was not recognized as valid.

As far as I can tell, the code runs normally atm.

@@ -368,7 +369,7 @@ export default class FilingTemplateMixin extends Mixins(DateMixin) {
: {}
},
nameRequest: {
legalName: this.getNameRequest.details['approvedName'],
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a sloppy way to work around a type issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using (myObject as any).myProperty is also not ideal, but lint can flag variables used as any so we could find and fix these in the future. Plus there aren't a lot of places where "as any" is used 😅

}
await Vue.nextTick()
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this to its own TS file so it can be imported in a couple of test suites (instead of duplicated).

@severinbeauvais
Copy link
Collaborator Author

@seeker25 @vysakh-menon-aot @cameron-freshworks @lekshmimallika-aot

Please note the updates made by the next version of ES Lint, which I fixed here pre-emptively. Please follow this code style from now on (to prevent future cleanup).

Copy link
Contributor

@lewischenstudio lewischenstudio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a lot of cleanups. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants