Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Upgrade Angular, Node.js, and related dependencies #1243

Merged
merged 43 commits into from
Jul 17, 2019

Conversation

maurizi
Copy link
Contributor

@maurizi maurizi commented Jul 12, 2019

Overview

The main effort in this PR is to upgrade Angular from version 4 to 8.

As a consequence of that effort, the following other changes were also made:

  • Node.js upgraded from 6 to 10
  • ngx-bootstrap updated to the latest version, instead of using our forked version
  • Bootstrap updated from version 3 to 4
  • The climate-change-components repository was copied into this repository, instead of remaining a separate dependency, due to difficulties in upgrading and integrating with the new Angular CLI support for library projects
  • The difflib dependency (used by the password validation popup) was copied into this project with minor fixes, due to an error which was not fatal in our old CLI toolchain but became so in the newer toolchain.

Demo

N/A

Everything should continue to work as it did before, with no changes in behavior or styling.

Testing Instructions

  • scripts/update
  • scripts/server
  • Test everything in the front-end application (you should be able to skip the Django Admin site). Make a small change and verify that live reload works.
  • Access the production build at localhost:8000 by stopping scripts/server and running docker-compose up django nginx
  • Test everything in the application again using the production build.
  • Is the CHANGELOG.md updated with any relevant additions, changes, fixes or removals following the format of keepachangelog?

Closes #1202
Closes #263
Closes #876

flibbertigibbet and others added 30 commits July 12, 2019 10:12
http module moved into core.
See: angular/angular-cli#14553 (comment)

Fixes build error "TS2554: Expected 2 arguments, but got 1."
Both are in compiler instead.
Still on 2.x
FIXME: remove when upgrade complete.
This allows the temperate Angular app to successfully compile.

PlanItApiHttp was removed in favor of plain old HttpClient.
PlanItApiHttp was causing cryptic errors when requests were
made, such as:
'XMLHttpRequest failed to open with scheme: HTTP://LOCALHOST:8081/API/USER/'
Why caps? And why is that a scheme?

Now we just get normal 401 authorized failures because we need
to implement an HTTP Interceptor to add the token to all API requests.
- Adds token to API requests
- Redirects to home page in case of auth failure
So that we match the old Azavea ngx-bootstrap
typeaheadMinLength=0 behavior.
…etc)

The token interceptor was trying to add an authorization token even when
there was no logged in user, causing requests to be rejected.
The newer version Angular we're upgrading to strips whitespace.
In the few places where we were depending on whitespace to add padding to
inline elements, I've explicitly added non-breaking spaces to accommodate.
Without also setting [typeaheadSelectFirstItem]="false", tabbing out of
the input won't work with [typeaheadIsFirstItemActive]="false" set.
This library was failing in AoT mode, due to attempting to assign to the
'.name' property of an anonymous function.

It is unclear to me why this was not an issue before, but is now.

Regardless, since the library was last updated 7 years ago and has several
similarly old unmerged pull requests, it seemed like the best solution was
to copy it into our project and fix it there rather than attempting to
fork it and submit a fix.
to fork it and submit a pull
@maurizi maurizi mentioned this pull request Jul 12, 2019
1 task
Copy link
Contributor Author

@maurizi maurizi left a comment

Choose a reason for hiding this comment

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

I'm on the fence on if it's worth it to reformat the indentation in the copied-over components code - that mostly used 4-space indentation, while Temperate uses 2-space indentation.

If folks have strong opinions, please leave a 👍 or 👎

Copy link
Contributor

@ddohler ddohler left a comment

Choose a reason for hiding this comment

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

I successfully compiled the app and logged in, and I tested as much functionality as I could. I found one unrelated bug, and one thing that didn't seem to function as it should: on the indicator graphs, changing the Scenario, Dataset, and Model wasn't causing the graph to update for me. I also confirmed that live reload worked.

@@ -3,7 +3,7 @@ import { ActivatedRoute, Params, Router } from '@angular/router';

import { AlertModule } from 'ngx-bootstrap';

import { Observable } from 'rxjs/Rx';
import { Observable } from 'rxjs';
Copy link
Contributor

Choose a reason for hiding this comment

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

🎊

@@ -21,7 +21,9 @@ <h3 class="step-title">Details</h3>
autocomplete="off"
formControlName="action_type"
[typeahead]="actionTypes"
[typeaheadMinLength]="0">
[typeaheadMinLength]="0"
[typeaheadIsFirstItemActive]="false"
Copy link
Contributor

Choose a reason for hiding this comment

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

👏


import { environment } from '../../../environments/environment';


@Injectable()
export class CityProfileService {

constructor(private apiHttp: PlanItApiHttp) {}
constructor(private http: HttpClient) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Just for my own understanding, what changed to make the subclass unnecessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We added these HTTP interceptors 3eb24a3 (a new feature introduced in Angular 5), which take the place of the custom code we had added to the subclass.

A new lint was added since Angular 4 that enforces this naming scheme
These had already been renamed in the components repo before it was folded
into this repository
@maurizi
Copy link
Contributor Author

maurizi commented Jul 16, 2019

@ddohler I fixed the issue with the indicator charts in 7e5916b, and also fixed running the tests, and cleaned up some formatting and whitespace (including the mixed indentation of the climate-api module).

Copy link
Contributor

@ddohler ddohler left a comment

Choose a reason for hiding this comment

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

I think it'd be good for someone else (probably @flibbertigibbet ) to take a second look at this before it goes in, given how large it is, but everything seems to be working pretty smoothly for me!

Copy link
Contributor

@flibbertigibbet flibbertigibbet left a comment

Choose a reason for hiding this comment

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

The code looks good to me. I haven't been able to test it yet.

I ran into an unrelated error while attempting to build the containers:
image


@Injectable()
export class ActionTypeService {

constructor(private apiHttp: PlanItApiHttp,
constructor(private http: HttpClient,
Copy link
Contributor

Choose a reason for hiding this comment

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

🎊

return new User(user);
return this.http.get(url).pipe(map(response => {
if (response) {
return new User(response);
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

}

listOptions(): Observable<{[key: string]: CityProfileOption[]}> {
const url = `${environment.apiUrl}/api/city-profile-options/`;
return this.apiHttp.get(url).map(response => response.json());
return this.http.get<{[key: string]: CityProfileOption[]}>(url);
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

// Parse string to array of arrays
const csvData = papa.parse(resp['_body'], { newline: '\r\n' });
const csvData = papa.parse(resp, { newline: '\r\n' });
Copy link
Contributor

Choose a reason for hiding this comment

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

🎊

@maurizi
Copy link
Contributor Author

maurizi commented Jul 17, 2019

image

I think if you run scripts/update again it will succeed this time. This is a similar issue to #1195 that was introduced by the Area indicators work being pulled into this repository.

@maurizi maurizi merged commit 122cd08 into develop Jul 17, 2019
@maurizi maurizi deleted the feature/mvm/upgrade-angular branch July 17, 2019 15:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update Node.js version Switch back to upstream ngx-bootstrap package Upgrade to latest Angular
4 participants