scottyaslan commented on code in PR #8235: URL: https://github.com/apache/nifi/pull/8235#discussion_r1450545185
########## nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-frontend/src/main/nifi/src/app/pages/queue/state/queue-listing/queue-listing.effects.ts: ########## @@ -0,0 +1,325 @@ +/* + * 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 { Injectable } from '@angular/core'; +import { Actions, createEffect, ofType } from '@ngrx/effects'; +import * as QueueListingActions from './queue-listing.actions'; +import { Store } from '@ngrx/store'; +import { CanvasState } from '../../../flow-designer/state'; +import { + asyncScheduler, + catchError, + filter, + from, + interval, + map, + of, + switchMap, + take, + takeUntil, + tap, + withLatestFrom +} from 'rxjs'; +import { selectConnectionIdFromRoute, selectListingRequestEntity } from './queue-listing.selectors'; +import { QueueService } from '../../service/queue.service'; +import { ListingRequest } from './index'; +import { CancelDialog } from '../../../../ui/common/cancel-dialog/cancel-dialog.component'; +import { MatDialog } from '@angular/material/dialog'; +import { selectAbout } from '../../../../state/about/about.selectors'; +import { FlowFileDialog } from '../../ui/queue-listing/flowfile-dialog/flowfile-dialog.component'; +import { NiFiCommon } from '../../../../service/nifi-common.service'; + +@Injectable() +export class QueueListingEffects { + constructor( + private actions$: Actions, + private store: Store<CanvasState>, + private queueService: QueueService, + private dialog: MatDialog, + private nifiCommon: NiFiCommon + ) {} + + loadConnectionLabel$ = createEffect(() => + this.actions$.pipe( + ofType(QueueListingActions.loadConnectionLabel), + map((action) => action.request), + switchMap((request) => + from(this.queueService.getConnection(request.connectionId)).pipe( + map((response) => { + const connection: any = response.component; + + let connectionLabel: string = 'Connection'; + if (!this.nifiCommon.isBlank(connection.name)) { + connectionLabel = connection.name; + } else if (connection.selectedRelationships) { + connectionLabel = connection.selectedRelationships.join(', '); + } + + return QueueListingActions.loadConnectionLabelSuccess({ + response: { + connectionLabel + } + }); + }), + catchError((error) => + of( + QueueListingActions.loadConnectionLabelSuccess({ + response: { + connectionLabel: 'Connection' + } + }) + ) + ) + ) + ) + ) + ); + + submitQueueListingRequest$ = createEffect(() => + this.actions$.pipe( + ofType(QueueListingActions.submitQueueListingRequest), + map((action) => action.request), + switchMap((request) => { + const dialogReference = this.dialog.open(CancelDialog, { + data: { + title: 'Queue Listing', + message: 'Waiting for queue listing to complete...' + }, + disableClose: true, + panelClass: 'small-dialog' + }); + + dialogReference.componentInstance.cancel.pipe(take(1)).subscribe(() => { + this.store.dispatch(QueueListingActions.stopPollingQueueListingRequest()); + }); + + return from(this.queueService.submitQueueListingRequest(request)).pipe( + map((response) => + QueueListingActions.submitQueueListingRequestSuccess({ + response: { + requestEntity: response + } + }) + ), + catchError((error) => + of( + QueueListingActions.queueListingApiError({ + error: error.error + }) + ) + ) + ); + }) + ) + ); + + resubmitQueueListingRequest$ = createEffect(() => + this.actions$.pipe( + ofType(QueueListingActions.resubmitQueueListingRequest), + withLatestFrom(this.store.select(selectConnectionIdFromRoute)), + switchMap(([action, connectionId]) => + of(QueueListingActions.submitQueueListingRequest({ request: { connectionId } })) + ) + ) + ); + + submitQueueListingRequestSuccess$ = createEffect(() => + this.actions$.pipe( + ofType(QueueListingActions.submitQueueListingRequestSuccess), + map((action) => action.response), + switchMap((response) => { + const listingRequest: ListingRequest = response.requestEntity.listingRequest; + if (listingRequest.finished) { + return of(QueueListingActions.deleteQueueListingRequest()); + } else { + return of(QueueListingActions.startPollingQueueListingRequest()); + } + }) + ) + ); + + startPollingQueueListingRequest$ = createEffect(() => + this.actions$.pipe( + ofType(QueueListingActions.startPollingQueueListingRequest), + switchMap(() => + interval(2000, asyncScheduler).pipe( + takeUntil(this.actions$.pipe(ofType(QueueListingActions.stopPollingQueueListingRequest))) + ) + ), + switchMap(() => of(QueueListingActions.pollQueueListingRequest())) + ) + ); + + pollQueueListingRequest$ = createEffect(() => + this.actions$.pipe( + ofType(QueueListingActions.pollQueueListingRequest), + withLatestFrom(this.store.select(selectListingRequestEntity)), + filter((requestEntity) => requestEntity != null), + switchMap(([action, requestEntity]) => { + // @ts-ignore Review Comment: Is this ts-ignore necessary? You could just filter out nulls... ########## nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-frontend/src/main/nifi/src/app/pages/queue/state/index.ts: ########## @@ -0,0 +1,38 @@ +/* + * 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. + */ + +/* + Parameter Contexts Review Comment: Did you mean to leave this comment here? -- 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]
