in web/frontend/src/app/pages/streams/components/stream-details/stream-details.component.ts [104:225]
ngOnInit() {
this.activeTab$ = this.appStore.pipe(select(getActiveOrFirstTab));
this.activeTab$
.pipe(take(1))
.subscribe(() => this.appStore.dispatch(new StreamDetailsActions.RemoveErrorMessage()));
this.error$ = this.streamDetailsStore
.pipe(select(streamsDetailsStateSelector))
.pipe(map((details) => details.errorMessage));
this.tabSettings$ = this.appStore.pipe(select(getActiveTabSettings));
this.tabSettings$
.pipe(takeUntil(this.destroy$))
.subscribe((settings: TabSettingsModel) => (this.tabSettings = settings));
this.appStore
.pipe(select(getOpenNewTabState))
.subscribe((_openNewTab) => (this.isOpenInNewTab = _openNewTab));
this.appStore
.pipe(
select(streamsListStateSelector),
filter(() => !!this.currentTab),
takeUntil(this.destroy$),
)
.subscribe((listState: ListState) => {
if (listState.dbState) {
if (listState.dbState.renamed && listState.dbState.renamed.length) {
const eqItem = listState.dbState.renamed.find((item) => item.oldName === this.tabName);
if (eqItem) {
const tab = new TabModel({...{}, ...this.currentTab});
tab.stream = eqItem.newName;
this.streamsStore.dispatch(
new StreamsTabsActions.AddTab({
tab: tab,
position: this.currentPosition,
}),
);
this.streamsStore.dispatch(
new StreamsTabsActions.RemoveTab({
tab: this.currentTab,
}),
);
}
}
if (
(listState.dbState.added &&
listState.dbState.added.find((item) => item === this.tabName)) ||
(listState.dbState.changed &&
listState.dbState.changed.find((item) => item === this.tabName))
) {
this.appStore.dispatch(new StreamsTabsActions.SetFilters({filter: this.tabFilter}));
}
}
});
this.appStore
.pipe(
select(getActiveTabFilters),
filter((filter) => !!filter),
takeUntil(this.destroy$),
)
.subscribe((filter: FilterModel) => {
this.tabFilter = {...filter};
});
this.appStore
.pipe(
select(getStreamsList),
filter((streams) => !!streams),
switchMap(() => this.appStore.pipe(select(getTabs))),
filter((tabs) => !!tabs),
withLatestFrom(
this.appStore.pipe(
select(getActiveTab),
map((activeTab) => (activeTab ? activeTab.id : '')),
),
),
take(1),
takeUntil(this.destroy$),
switchMap(([tabs, activeTabId]: [TabModel[], string]) => {
return this.route.params.pipe(
filter((params: {stream: string; id: string; symbol?: string}) => !!params.stream),
withLatestFrom(this.route.data),
withLatestFrom(this.route.queryParams),
switchMap(
([[params, data], queryParams]: [
[{stream: string; id: string; symbol?: string}, Data],
Params,
]) => {
return this.appStore.pipe(
select(getStreamOrSymbolByID, {
streamID: params.stream,
symbol: params.symbol,
uid: params.id,
space: queryParams.space,
}),
filter((tabModel: TabModel) => !!tabModel),
take(1),
map((tabModel: TabModel) => {
return [tabModel, data, tabs, activeTabId];
}),
);
},
),
);
}),
takeUntil(this.destroy$),
)
.subscribe(([tabModel, data, tabs, activeTabId]: [TabModel, Data, TabModel[], string]) => {
this.streamDetailsStore.dispatch(
new StreamDetailsActions.GetSymbols({
streamId: tabModel.stream,
...(tabModel.space ? {spaceId: tabModel.space} : {}),
}),
);
this.live = data.hasOwnProperty('live');
this.streamName = tabModel.stream;
});
}