mcgilman commented on code in PR #8433: URL: https://github.com/apache/nifi/pull/8433#discussion_r1508124139
########## nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-frontend/src/main/nifi/src/app/pages/flow-designer/ui/manage-remote-ports/manage-remote-ports.component.ts: ########## @@ -0,0 +1,358 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Component, OnDestroy, OnInit } from '@angular/core'; +import { Store } from '@ngrx/store'; +import { filter, switchMap, take, tap } from 'rxjs'; +import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; +import { + selectRemotePortsState, + selectPort, + selectPortIdFromRoute, + selectPorts, + selectRpg, + selectRpgIdFromRoute, + selectSingleEditedPort +} from '../../state/manage-remote-ports/manage-remote-ports.selectors'; +import { RemotePortsState, PortSummary } from '../../state/manage-remote-ports'; +import { + loadRemotePorts, + navigateToEditPort, + openConfigureRemotePortDialog, + resetRemotePortsState, + selectRemotePort, + startRemotePortTransmission, + stopRemotePortTransmission +} from '../../state/manage-remote-ports/manage-remote-ports.actions'; +import { initialState } from '../../state/manage-remote-ports/manage-remote-ports.reducer'; +import { isDefinedAndNotNull, TextTipInput } from '../../../../state/shared'; +import { selectCurrentUser } from '../../../../state/current-user/current-user.selectors'; +import { NiFiState } from '../../../../state'; +import { NiFiCommon } from '../../../../service/nifi-common.service'; +import { MatTableDataSource } from '@angular/material/table'; +import { Sort } from '@angular/material/sort'; +import { TextTip } from '../../../../ui/common/tooltips/text-tip/text-tip.component'; +import { concatLatestFrom } from '@ngrx/effects'; +import { loadFlowConfiguration } from '../../../../state/flow-configuration/flow-configuration.actions'; +import { + selectFlowConfiguration, + selectTimeOffset +} from '../../../../state/flow-configuration/flow-configuration.selectors'; +import { selectAbout } from '../../../../state/about/about.selectors'; +import { loadAbout } from '../../../../state/about/about.actions'; + +@Component({ + templateUrl: './manage-remote-ports.component.html', + styleUrls: ['./manage-remote-ports.component.scss'] +}) +export class ManageRemotePorts implements OnInit, OnDestroy { + initialSortColumn: 'name' | 'type' | 'tasks' | 'count' | 'size' | 'duration' | 'compression' | 'actions' = 'name'; + initialSortDirection: 'asc' | 'desc' = 'asc'; + activeSort: Sort = { + active: this.initialSortColumn, + direction: this.initialSortDirection + }; + portsState$ = this.store.select(selectRemotePortsState); + selectedRpgId$ = this.store.select(selectRpgIdFromRoute); + selectedPortId!: string; + currentUser$ = this.store.select(selectCurrentUser); + flowConfiguration$ = this.store.select(selectFlowConfiguration).pipe(isDefinedAndNotNull()); + displayedColumns: string[] = [ + 'moreDetails', + 'name', + 'type', + 'tasks', + 'count', + 'size', + 'duration', + 'compression', + 'actions' + ]; + dataSource: MatTableDataSource<PortSummary> = new MatTableDataSource<PortSummary>([]); + protected readonly TextTip = TextTip; + + private currentRpgId!: string; + protected currentRpg: any | null = null; + + constructor( + private store: Store<NiFiState>, + private nifiCommon: NiFiCommon + ) { + // load the ports after the flow configuration `timeOffset` and about `timezone` are loaded into the store + this.store + .select(selectTimeOffset) + .pipe( + isDefinedAndNotNull(), + switchMap(() => this.store.select(selectAbout)), + isDefinedAndNotNull(), + switchMap(() => this.store.select(selectRpgIdFromRoute)), + tap((rpgId) => (this.currentRpgId = rpgId)), + takeUntilDestroyed() + ) + .subscribe((rpgId) => { + this.store.dispatch( + loadRemotePorts({ + request: { + rpgId + } + }) + ); + }); + + // track selection using the port id from the route + this.store + .select(selectPortIdFromRoute) + .pipe(isDefinedAndNotNull(), takeUntilDestroyed()) + .subscribe((portId) => { + this.selectedPortId = portId; + }); + + // data for table + this.store + .select(selectPorts) + .pipe(isDefinedAndNotNull(), takeUntilDestroyed()) + .subscribe((ports) => { + this.dataSource = new MatTableDataSource<PortSummary>(this.sortEntities(ports, this.activeSort)); + }); + + // the current RPG Entity + this.store + .select(selectRpg) + .pipe( + isDefinedAndNotNull(), + tap((rpg) => (this.currentRpg = rpg)), + takeUntilDestroyed() + ) + .subscribe(); + + // handle editing remote port deep link + this.store + .select(selectSingleEditedPort) + .pipe( + isDefinedAndNotNull(), + switchMap((id: string) => + this.store.select(selectPort(id)).pipe( + filter((entity) => entity != null), + take(1) + ) + ), + concatLatestFrom(() => [this.store.select(selectRpg).pipe(isDefinedAndNotNull())]), + takeUntilDestroyed() + ) + .subscribe(([entity, rpg]) => { + if (entity) { + this.store.dispatch( + openConfigureRemotePortDialog({ + request: { + id: entity.id, + port: entity, + rpg + } + }) + ); + } + }); + } + + ngOnInit(): void { + this.store.dispatch(loadFlowConfiguration()); + this.store.dispatch(loadAbout()); + } + + isInitialLoading(state: RemotePortsState): boolean { + // using the current timestamp to detect the initial load event + return state.loadedTimestamp == initialState.loadedTimestamp; + } + + refreshManageRemotePortsListing(): void { + this.store.dispatch( + loadRemotePorts({ + request: { + rpgId: this.currentRpgId + } + }) + ); + } + + formatName(entity: PortSummary): string { + return entity.name; + } + + formatTasks(entity: PortSummary): string { + return entity.concurrentlySchedulableTaskCount ? `${entity.concurrentlySchedulableTaskCount}` : 'No value set'; + } + + formatCount(entity: PortSummary): string { + if (!this.isCountBlank(entity)) { + return `${entity.batchSettings.count}`; + } + return 'No value set'; + } + + isCountBlank(entity: PortSummary): boolean { + return this.nifiCommon.isUndefined(entity.batchSettings.count); + } + + formatSize(entity: PortSummary): string { + if (!this.isSizeBlank(entity)) { + return `${entity.batchSettings.size}`; + } + return 'No value set'; + } + + isSizeBlank(entity: PortSummary): boolean { + return this.nifiCommon.isBlank(entity.batchSettings.size); + } + + formatDuration(entity: PortSummary): string { + if (!this.isSizeBlank(entity)) { Review Comment: ```suggestion if (!this.isDurationBlank(entity)) { ``` -- 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]
