You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by GitBox <gi...@apache.org> on 2018/11/13 12:46:38 UTC

[GitHub] aBabiichuk commented on a change in pull request #5: [AMBARI-24551] [Log Search UI] get rid of redundant requests after undoing or redoing several history steps

aBabiichuk commented on a change in pull request #5: [AMBARI-24551] [Log Search UI] get rid of redundant requests after undoing or redoing several history steps
URL: https://github.com/apache/ambari-logsearch/pull/5#discussion_r233011840
 
 

 ##########
 File path: ambari-logsearch-web/src/app/components/filter-history-manager/filter-history-manager.component.ts
 ##########
 @@ -0,0 +1,382 @@
+import { Component, OnInit, OnDestroy, Input } from '@angular/core';
+import { Subject } from 'rxjs/Subject';
+import { Observable } from 'rxjs/Observable';
+import { Store } from '@ngrx/store';
+import { AppStore } from '@app/classes/models/store';
+import {
+  selectActiveFilterHistoryChangesUndoItems,
+  selectActiveFilterHistoryChangesRedoItems,
+  selectActiveFilterHistoryChanges,
+  selectActiveFilterHistoryChangeIndex
+} from '@app/store/selectors/filter-history.selectors';
+import { FilterUrlParamChange } from '@app/classes/models/filter-url-param-change.interface';
+import { Router, UrlTree, UrlSegmentGroup } from '@angular/router';
+import {
+  LogsFilteringUtilsService,
+  defaultUrlParamsForFiltersByLogsType,
+  UrlParamDifferences,
+  UrlParamsDifferenceType
+} from '@app/services/logs-filtering-utils.service';
+import { selectActiveLogsType } from '@app/store/selectors/app-state.selectors';
+import { LogsType } from '@app/classes/string';
+import { TranslateService } from '@ngx-translate/core';
+import { selectComponentsLabels } from '@app/store/selectors/components.selectors';
+import { selectDefaultAuditLogsFields } from '@app/store/selectors/audit-logs-fields.selectors';
+import { selectServiceLogsFieldState } from '@app/store/selectors/service-logs-fields.selectors';
+import { BehaviorSubject } from 'rxjs/BehaviorSubject';
+import { ListItem } from '@app/classes/list-item';
+
+import * as moment from 'moment';
+import { SearchBoxParameter } from '@app/classes/filtering';
+import { LogField } from '@app/classes/object';
+
+export const urlParamsActionType = {
+  clusters: 'multiple',
+  timeRange: 'single',
+  components: 'multiple',
+  levels: 'multiple',
+  hosts: 'multiple',
+  sortingKey: 'single',
+  sortingType: 'single',
+  pageSize: 'single',
+  page: 'single',
+  query: 'query',
+  users: 'multiple'
+};
+
+@Component({
+  selector: 'filter-history-manager',
+  templateUrl: './filter-history-manager.component.html',
+  styleUrls: ['./filter-history-manager.component.less']
+})
+export class FilterHistoryManagerComponent implements OnInit, OnDestroy {
+
+  @Input()
+  labelSeparator = ' | ';
+
+  activeLogsType$: Observable<LogsType> = this.store.select(selectActiveLogsType);
+
+  componentsLabels$: Observable<{[key: string]: string}> = this.store.select(selectComponentsLabels);
+  componentsLabelsLocalCopy$: BehaviorSubject<{[key: string]: string}> = new BehaviorSubject({});
+
+  activeHistoryChangeIndex$: Observable<number> = this.store.select(selectActiveFilterHistoryChangeIndex);
+
+  activeHistoryItems$: Observable<FilterUrlParamChange[]> = this.store.select(selectActiveFilterHistoryChanges);
+  hasActiveHistoryItems$: Observable<boolean> = this.activeHistoryItems$
+    .map(items => items && items.length > 0).startWith(false);
+  activeHistoryItemLabels$: Observable<{[key: string]: string}[]> = Observable.combineLatest(
+    this.activeHistoryItems$,
+    this.activeLogsType$,
+    this.componentsLabels$ // this is just to recalculate the labels when the components arrived
+  ).map(result => this.mapHistoryItemsToHistoryItemLabels(result));
+  activeHistoryListItems$: Observable<ListItem[]> = Observable.combineLatest(
+    this.activeHistoryItemLabels$.map((items) => this.mapHistoryItemLabelsToListItems(items, this.labelSeparator)),
+    this.store.select(selectActiveFilterHistoryChangeIndex)
+  ).map(([listItems, changeIndex]: [ListItem[], number]): ListItem[] => listItems.map((item, index) => {
+    item.cssClass = index === changeIndex ? 'active' : (index === 0 ? 'initial' : '');
+    return item;
+  }));
+
+  activeUndoHistoryItems$: Observable<FilterUrlParamChange[]> = this.store.select(selectActiveFilterHistoryChangesUndoItems);
+  hasActiveUndoHistoryItems$: Observable<boolean> = this.activeUndoHistoryItems$
+    .map(items => items && items.length > 0).startWith(false);
+  activeUndoHistoryListItems$: Observable<ListItem[]> = Observable.combineLatest(
+    this.activeHistoryListItems$,
+    this.store.select(selectActiveFilterHistoryChangeIndex)
+  ).map(([listItems, activeChangeIndex]: [ListItem[], number]): ListItem[] => listItems.slice(0, activeChangeIndex));
+
+  activeRedoHistoryItems$: Observable<FilterUrlParamChange[]> = this.store.select(selectActiveFilterHistoryChangesRedoItems);
+  hasActiveRedoHistoryItems$: Observable<boolean> = this.activeRedoHistoryItems$
+    .map(items => items && items.length > 0).startWith(false);
+  activeRedoHistoryListItems$: Observable<ListItem[]> = Observable.combineLatest(
+    this.activeHistoryListItems$,
+    this.store.select(selectActiveFilterHistoryChangeIndex)
+  ).map(([listItems, activeChangeIndex]: [ListItem[], number]): ListItem[] => listItems.slice(activeChangeIndex + 1));
+
+  activeQueryFieldsLabels$: Observable<{[key: string]: string}> = Observable.combineLatest(
+    this.store.select(selectServiceLogsFieldState),
+    this.store.select(selectDefaultAuditLogsFields),
+    this.activeLogsType$
+  ).map(
+    (
+      [serviceLogsFields, auditLogsFields, activeLogsType]: [LogField[], LogField[], LogsType]
+    ) => activeLogsType === 'serviceLogs' ? serviceLogsFields : auditLogsFields
+  ).map(
+    (fields: LogField[]) => fields ? fields.reduce(
+      (fieldLabels: {[key: string]: string}, field: LogField): {[key: string]: string} => ({
+        ...fieldLabels,
+        [field.name]: field.label || field.name
+      }),
+      {}
+    ) : []
+  );
+  activeQueryFieldsLocalCopy$: BehaviorSubject<{[key: string]: string}> = new BehaviorSubject({});
+
+  destroyed$ = new Subject();
+
+  constructor(
+    private store: Store<AppStore>,
+    private router: Router,
+    private logsFilteringUtilsService: LogsFilteringUtilsService,
+    private translateService: TranslateService
+  ) { }
+
+  ngOnInit() {
+    this.componentsLabels$.takeUntil(this.destroyed$).subscribe(componentsLabels => this.componentsLabelsLocalCopy$.next(componentsLabels));
+    this.activeQueryFieldsLabels$.takeUntil(this.destroyed$).subscribe(fieldLabels => this.activeQueryFieldsLocalCopy$.next(fieldLabels));
+
+    this.activeHistoryItemLabels$.takeUntil(this.destroyed$).subscribe(() => {});
 
 Review comment:
   What is this for?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services