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

Jamie/4699 frontend update deps #4835

Merged
merged 36 commits into from
Mar 25, 2021
Merged

Conversation

SEAjamieD
Copy link
Contributor

@SEAjamieD SEAjamieD commented Mar 17, 2021

🔩 Description: What code changed, and why?

As the dependencies we utilize and rely on within our codebase are updated and improved, its important that we continue to stay ahead of deprecations, breaking changes, and best security. We periodically examine where our dependencies are falling behind and update as necessary.

We are currently outdated in a number of packages: see image in description of #4699

after update from this branch, running npm outdated will list the following exceptions documented in README.md

Package Current Wanted Latest Location
immutable 3.8.2 3.8.2 4.0.0-rc.12 automate-ui
jasmine-core 3.6.0 3.6.0 3.7.0 automate-ui
rrule 2.4.1 2.4.1 2.6.8 automate-ui
typescript 4.0.7 4.2.3 4.2.3 automate-ui

⛓️ Related Resources

Adresses #4699

👍 Definition of Done

running ng build returns no errors
running make lint returns no errors with exception listed below
running make unit returns no errors

All automate-ui frontend dependencies are as up to date as possible with the exception of those documented in README.md.

👟 How to Build and Test the Change

option 1: - Delete your node files and perform a new installation
cd into automate-ui folder
rm -rf node_modules && npm install
please remember to run this again after switching back to whatever branch you are working on

option 2 - Save your node modules elsewhere to reuse after
cd into automate-ui folder
mv node_modules /location/to/save/your/old/node_modules
npm install

After the new install
ng build
make unit
make serve -> this will return a warning for baseHref which is being handled in #4865
All should return no errors
running npm install should report 0 vulnerabilities

It is also highly appreciated if each tester would spend some time clicking around the application, keeping an eye out for any new console errors that my expose themselves. Thankfully, almost all of the dependency updates are of a minor version so I don't expect anything much to pop up.

Note regarding TSLint Deprecation warnings

TSLint Deprecation warnings will be handled in #4700

Note for those using WallabyJS

Wallaby is currently picking up two errors in jwt.ts. It appears that these are false positives as our signin is still working as expected. I am reaching out to the Wallaby team for assistance in resolving.

✅ Checklist

📷 Screenshots, if applicable

@netlify
Copy link

netlify bot commented Mar 17, 2021

Deploy preview for chef-automate processing.

Building with commit ed3b4a8

https://app.netlify.com/sites/chef-automate/deploys/605c01fe6d047d000960c2c9

@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { HttpErrorResponse } from '@angular/common/http';
import { Actions, Effect, ofType } from '@ngrx/effects';
import { Actions, createEffect, ofType } from '@ngrx/effects';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the @Effect decorator has been deprecated in favor of a more "React hooks" style of composition.
Deprecation notice: https://ngrx.io/api/effects/Effect
Usage notes for createEffect: https://ngrx.io/api/effects/createEffect#usage-notes

Comment on lines 42 to 49
getAllTokens$ = createEffect(() => {
return this.actions$.pipe(ofType<GetAllTokens>(ApiTokenActionTypes.GET_ALL),
mergeMap((_action) =>
this.requests.getAll().pipe(
map(resp => new GetAllTokensSuccess(resp)),
catchError((error: HttpErrorResponse) => of(new GetAllTokensFailure(error))))
));
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

You'll see this new format used throughout all our effects files moving forward and its how we should continue to compose effects.

@SEAjamieD SEAjamieD self-assigned this Mar 18, 2021
@SEAjamieD SEAjamieD force-pushed the jamie/4699-frontend-update-deps branch from 34b19e7 to c9f39a7 Compare March 19, 2021 18:58
@@ -151,7 +151,7 @@ export class ServiceGroupsRequests {
}, searchParam, filters);
}

public deleteServicesById(listOfIds: number[]): any {
public deleteServicesById(listOfIds: number[]): Observable<any> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks to @msorens for helping realize the error in this related effect was coming from the lack of an Observable signature. The should be updated to be more specific as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking into this more, I'm going to investigate the proper type in a new branch so as not to hold up these dependencies.

@SEAjamieD SEAjamieD linked an issue Mar 19, 2021 that may be closed by this pull request
@@ -32,6 +32,7 @@ describe('ClientDetailsComponent', () => {
MockComponent({ selector: 'chef-tr' }),
MockComponent({ selector: 'chef-th' }),
MockComponent({ selector: 'chef-td' }),
MockComponent({ selector: 'chef-snippet', inputs: ['code'] }),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some cleanup of missing mock-selectors. I'm actually surprised these made it through bulidkite.

@@ -46,7 +47,8 @@ describe('DataBagsListComponent', () => {
ReactiveFormsModule,
RouterTestingModule,
StoreModule.forRoot(ngrxReducers, { runtimeChecks })
]
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
Copy link
Contributor Author

@SEAjamieD SEAjamieD Mar 19, 2021

Choose a reason for hiding this comment

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

Several test files were missing the CUSTOM_ELEMENTS_SCHEMA required for our custom components and as a result were throwing linting errors.

@SEAjamieD SEAjamieD marked this pull request as ready for review March 19, 2021 21:02
Copy link
Contributor

@msorens msorens left a comment

Choose a reason for hiding this comment

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

Nice work!

  1. Should add to your "done" criteria the fact that npm install should report "found 0 vulnerabilities" -- that is not always the case and should be celebrated!!

  2. Should mention in the PR preamble that wallaby is reporting 2 errors and if there are plans to resolve those.

  3. Should mention that the TSLint deprecation warnings will be dealt with in a separate issue.

  4. Should also mention that make serve should display no errors or warnings. Currently, it does have one (I would add this as a new issue to the Bringing dependencies up-to-date epic.)

Option "baseHref" is deprecated: Use the "baseHref" option in the browser builder instead.

Comment on lines 33 to 39
latestOptions$ = createEffect(() =>
observableInterval(1000 * this.POLLING_INTERVAL_IN_SECONDS).pipe(
mergeMap(this.loadOptionsAction$())));

// Fast-initialize project filter just from local storage
@Effect()
initOptions$ = this.actions$.pipe(
initOptions$ = createEffect(() => {
return this.actions$.pipe(
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's be consistent: as you have it here, there are two equivalent syntaxes for writing the createEffect expression. I want to urge the more concise format (L33). No need to introduce a separate block of code (L38-39) when there is just a single return. (Apologies that that does make a lot of editing for you. 😁 )

ofType<SaveOptions>(ProjectsFilterActionTypes.SAVE_OPTIONS),
tap(({ payload }) => this.projectsFilter.storeOptions(payload))
);
), { dispatch: false });
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this dispatch added? What does it do?

Copy link
Contributor Author

@SEAjamieD SEAjamieD Mar 22, 2021

Choose a reason for hiding this comment

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

We need to use {dispatch: false} whenever our effect isn't returning an action so that we don't cause an infinite loop.

Non-dispatching Effects
Sometimes you don't want effects to dispatch an action, for example when you only want to log or navigate based on an incoming action. But when an effect does not dispatch another action, the browser will crash because the effect is both 'subscribing' to and 'dispatching' the exact same action, causing an infinite loop. To prevent this, add { dispatch: false } to the createEffect function as the second argument.

In this case, dispatch wasn't added here, it already existed but it now looks a little different in the new style of writing effects.

In the old format it was composed as

@Effect( {dispatch: false} )

in the new style

createEffect( () => some code, {dispatch: false})

@@ -55,17 +55,9 @@ Certain packages in package.json are constrained for the reasons detailed here.
At any future moment though, the reasons for constraint here could be invalidated, so this should be updated as needed when package.json is updated.
While it is problematic to document this information due to the maintenance burden, the value of having this in one place outweighs that burden.

### Packages @ngrx/* =10.1.0
### Package typescript: ^4.0.7
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice--thanks for keeping these docs current!

@@ -57,7 +57,7 @@ export class Jwt {
static parseLicenseToken(token: string): LicenseToken | null {
let tok: LicenseToken;
try {
tok = jwtDecode(token);
tok = jwt_decode(token);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this change still causing errors to be reported by Wallaby?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah it is, I meant to send them a note last week but didn't. I'll get one out to them today.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The wallaby errors have since disappeared 🤷

@SEAjamieD SEAjamieD force-pushed the jamie/4699-frontend-update-deps branch from 80cb092 to 215b42b Compare March 22, 2021 21:23
@SEAjamieD SEAjamieD requested a review from kalroy March 23, 2021 19:19

@Effect()
resetKeyClient$ = this.actions$.pipe(
resetKeyClient$ = createEffect(() => this.actions$.pipe(
Copy link
Contributor

Choose a reason for hiding this comment

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

[nitpick] Of the 364 effects, there are just 14 (like this one) that do not have a line break after the =>. 😉

@SEAjamieD SEAjamieD force-pushed the jamie/4699-frontend-update-deps branch from 215b42b to a5dac92 Compare March 24, 2021 17:06
seajamied added 9 commits March 24, 2021 20:18
Signed-off-by: seajamied <jdegnan@chef.io>
Signed-off-by: seajamied <jdegnan@chef.io>
Signed-off-by: seajamied <jdegnan@chef.io>
Signed-off-by: seajamied <jdegnan@chef.io>
Unfortunately unable to use auto migrater, hitting an exception error

Signed-off-by: seajamied <jdegnan@chef.io>
Signed-off-by: seajamied <jdegnan@chef.io>
Signed-off-by: seajamied <jdegnan@chef.io>
Signed-off-by: seajamied <jdegnan@chef.io>
seajamied added 26 commits March 24, 2021 20:18
Signed-off-by: seajamied <jdegnan@chef.io>
Signed-off-by: seajamied <jdegnan@chef.io>
Signed-off-by: seajamied <jdegnan@chef.io>
Thanks to new createEffect and Typescript, a should be
non dispatching effect was found and updated.

Signed-off-by: seajamied <jdegnan@chef.io>
dispatch false was the wrong approach - obvious by the fact
that we needed to dispatch an action.  However it appears we
did not have a need to use mergeMap and instead should simply
be merging.

Signed-off-by: seajamied <jdegnan@chef.io>
Signed-off-by: seajamied <jdegnan@chef.io>
Signed-off-by: seajamied <jdegnan@chef.io>
This is the latest available to these packages

Signed-off-by: seajamied <jdegnan@chef.io>
Signed-off-by: seajamied <jdegnan@chef.io>
Per documentation https://www.npmjs.com/package/zone.js\?activeTab\=readme
a breaking change was introduced after v0.11.1, we are safe to upgrade
by importing as 'zone.js/dist/zone' which we are doing in polyfills.ts

Signed-off-by: seajamied <jdegnan@chef.io>
Signed-off-by: seajamied <jdegnan@chef.io>
Initially I tought the package upgrade was causing errors
but after making the required changes, I think what is actually
happening is that it helped expose some bad tests or function
in signin.component.ts.  Interestingly enough, running 'make unit'
shows that all tests are passing

Signed-off-by: seajamied <jdegnan@chef.io>
Signed-off-by: seajamied <jdegnan@chef.io>
The error is not infact fixed here, mergeMap seems to be required
however there is a Type error that needs more investigation.  The 'old'
way works but the new way throws a type error

Signed-off-by: seajamied <jdegnan@chef.io>
This fixed the effect error - thanks to Michael Sorens.  This should be updated
from an 'any' response as well.

Signed-off-by: seajamied <jdegnan@chef.io>
Signed-off-by: seajamied <jdegnan@chef.io>
Signed-off-by: seajamied <jdegnan@chef.io>
Signed-off-by: seajamied <jdegnan@chef.io>
Signed-off-by: seajamied <jdegnan@chef.io>
Signed-off-by: seajamied <jdegnan@chef.io>
Signed-off-by: seajamied <jdegnan@chef.io>
Signed-off-by: seajamied <jdegnan@chef.io>
Signed-off-by: seajamied <jdegnan@chef.io>
Signed-off-by: seajamied <jdegnan@chef.io>
Signed-off-by: seajamied <jdegnan@chef.io>
Signed-off-by: seajamied <jdegnan@chef.io>
@SEAjamieD SEAjamieD force-pushed the jamie/4699-frontend-update-deps branch from 6c08fe6 to ed3b4a8 Compare March 25, 2021 03:22
@SEAjamieD SEAjamieD merged commit 92e4183 into master Mar 25, 2021
@SEAjamieD SEAjamieD deleted the jamie/4699-frontend-update-deps branch March 25, 2021 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dependencies need updating (front-end)
3 participants