Skip to content

Commit

Permalink
refactored request handler state handling
Browse files Browse the repository at this point in the history
  • Loading branch information
imolorhe committed Aug 31, 2024
1 parent 505f6b6 commit b3ea0fd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 76 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
import {
Component,
EventEmitter,
Input,
OnChanges,
OnInit,
Output,
SimpleChanges,
} from '@angular/core';
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { json } from '@codemirror/lang-json';
import { Extension } from '@codemirror/state';
import {
HTTP_HANDLER_ID,
RequestHandlerData,
RequestHandlerIds,
WEBSOCKET_HANDLER_ID,
} from 'altair-graphql-core/build/request/types';
import { RequestHandlerInfo } from 'altair-graphql-core/build/types/state/query.interfaces';

Expand All @@ -22,7 +13,7 @@ import { RequestHandlerInfo } from 'altair-graphql-core/build/types/state/query.
templateUrl: './request-handler-dialog.component.html',
styles: ``,
})
export class RequestHandlerDialogComponent implements OnInit, OnChanges {
export class RequestHandlerDialogComponent {
@Input() requestHandlerId: RequestHandlerIds = HTTP_HANDLER_ID;
@Input() requestHandlerAdditionalParams = '{}';
@Input() subscriptionUrl = '';
Expand All @@ -36,45 +27,8 @@ export class RequestHandlerDialogComponent implements OnInit, OnChanges {

connectionParamsExtensions: Extension[] = [json()];

handlerInfo: RequestHandlerInfo = {
additionalParams: '{}',
requestHandlerId: HTTP_HANDLER_ID,
subscriptionRequestHandlerId: WEBSOCKET_HANDLER_ID,
subscriptionUrl: '',
subscriptionUseDefaultRequestHandler: false,
subscriptionConnectionParams: '',
};

ngOnInit() {
this.buildRequestHandlerInfo();
}

ngOnChanges(changes: SimpleChanges) {
if (
changes?.requestHandlerId?.currentValue ||
changes?.selectedSubscriptionRequestHandlerId?.currentValue
) {
this.buildRequestHandlerInfo();
}
}
buildRequestHandlerInfo() {
this.handlerInfo = {
requestHandlerId: this.requestHandlerId,
additionalParams: this.requestHandlerAdditionalParams,
subscriptionUseDefaultRequestHandler:
this.subscriptionUseDefaultRequestHandler,
subscriptionUrl: this.subscriptionUrl,
subscriptionConnectionParams: this.subscriptionConnectionParams,
subscriptionRequestHandlerId: this.selectedSubscriptionRequestHandlerId,
};
}

updateRequestHandlerInfo(data: Partial<RequestHandlerInfo>) {
this.handlerInfo = {
...this.handlerInfo,
...data,
};
this.requestHandlerInfoChange.emit(this.handlerInfo);
this.requestHandlerInfoChange.emit(data);
}

trackById(index: number, item: RequestHandlerData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,33 +126,7 @@ export function queryReducer(
case query.SET_REQUEST_HANDLER_INFO:
return {
...state,
...(action.payload.requestHandlerId
? { requestHandlerId: action.payload.requestHandlerId }
: {}),
...(action.payload.additionalParams
? { requestHandlerAdditionalParams: action.payload.additionalParams }
: {}),
...(action.payload.subscriptionUseDefaultRequestHandler
? {
subscriptionUseDefaultRequestHandler:
action.payload.subscriptionUseDefaultRequestHandler,
}
: {}),
...(action.payload.subscriptionUrl
? { subscriptionUrl: action.payload.subscriptionUrl }
: {}),
...(action.payload.subscriptionConnectionParams
? {
subscriptionConnectionParams:
action.payload.subscriptionConnectionParams,
}
: {}),
...(action.payload.subscriptionRequestHandlerId
? {
subscriptionRequestHandlerId:
action.payload.subscriptionRequestHandlerId,
}
: {}),
...action.payload,
};
case query.SET_IS_SUBSCRIBED:
return { ...state, isSubscribed: action.payload.isSubscribed };
Expand Down
2 changes: 2 additions & 0 deletions packages/altair-app/src/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
/** Evergreen browsers require these. **/
import 'core-js/es/reflect';

(window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['message'];

/** *************************************************************************************************
* Zone JS is required by Angular itself.
*/
Expand Down

0 comments on commit b3ea0fd

Please sign in to comment.