shamrickus commented on code in PR #7585:
URL: https://github.com/apache/trafficcontrol/pull/7585#discussion_r1272284458


##########
experimental/traffic-portal/src/app/app.component.ts:
##########
@@ -31,7 +34,19 @@ export class AppComponent implements OnInit {
        /** The currently logged-in user */
        public currentUser: ResponseCurrentUser | null = null;
 
-       constructor(private readonly router: Router, private readonly auth: 
CurrentUserService) {
+       constructor(private readonly router: Router, private readonly auth: 
CurrentUserService,
+               @Inject(PLATFORM_ID) private readonly platformId: object,
+               @Optional() @Inject("TP_V1_URL") public tpv1url: string,
+               private readonly transferState: TransferState) {
+               const storeKey = makeStateKey<string>("messageKey");
+
+               // get data from transferState if browser side
+               if (isPlatformBrowser(this.platformId)) {
+                       this.tpv1url = this.transferState.get(storeKey, 
"defaultMessageValue");
+                       localStorage.setItem(LOCAL_TPV1_URL, this.tpv1url);

Review Comment:
   Should be `window.localStorage`.



##########
experimental/traffic-portal/src/app/shared/navigation/navigation.service.ts:
##########
@@ -60,8 +61,12 @@ export class NavigationService {
 
        private readonly horizontalNavs: Map<string, HeaderNavigation>;
        private readonly verticalNavs: Map<string, HeaderNavigation>;
+       private readonly tpv1Url: string | null = "http:localhost:433";
 
-       constructor(private readonly auth: CurrentUserService, private readonly 
api: UserService) {
+       constructor(
+               private readonly auth: CurrentUserService,
+               private readonly api: UserService) {
+               this.tpv1Url = localStorage.getItem(LOCAL_TPV1_URL) ? 
localStorage.getItem(LOCAL_TPV1_URL) : this.tpv1Url;

Review Comment:
   This needs to be `window.localStorage`.
   
   Since tpv1Url doesn't need to be nullable I'd just call `...getItem(...) ?? 
"";` instead.
   
   Finally, this code will error out when the server tries to execute this 
component (because window is undefined). To solve this you'll need to inject 
`PLATFORM_ID` like you did in `app.component.ts` and check if we are 
`isPlatformBrowser` and otherwise set to blank string.



##########
experimental/traffic-portal/server.config.ts:
##########
@@ -372,6 +388,10 @@ export function getConfig(args: Args, ver: ServerVersion): 
ServerConfig {
                }
        }
 
+       if (args.tpv1Url) {

Review Comment:
   This argument needs to be added to the `parser` in the `run()` function.



##########
experimental/traffic-portal/src/app/shared/navigation/navigation.service.ts:
##########
@@ -60,8 +61,12 @@ export class NavigationService {
 
        private readonly horizontalNavs: Map<string, HeaderNavigation>;
        private readonly verticalNavs: Map<string, HeaderNavigation>;
+       private readonly tpv1Url: string | null = "http:localhost:433";

Review Comment:
   This doesn't need to be nullable.



##########
experimental/traffic-portal/server.ts:
##########
@@ -192,7 +192,10 @@ export function app(serverConfig: ServerConfig): 
express.Express {
 
        // All regular routes use the Universal engine
        server.get("*", (req, res) => {
-               res.render(indexHtml, {providers: [{provide: APP_BASE_HREF, 
useValue: req.baseUrl}], req});
+               res.render(indexHtml, {providers: [
+                       {provide: APP_BASE_HREF, useValue: req.baseUrl},
+                       {provide: 'TP_V1_URL', useValue: serverConfig.tpv1Url}

Review Comment:
   Lint error, needs to be surrounded by double quotes instead.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to