private trellisUpdateYAxisOptionAction$()

in clns-acuity-vahub/vahub/src/main/webapp/src/app/common/trellising/store/Trellising.ts [732:818]


    private trellisUpdateYAxisOptionAction$(): Observable<Action> {
        return this.actions$
            .withLatestFrom(this._store.select(getTabId),
                this._store.select(getCurrentNewYAxisOption),
                this._store.select(getCurrentNewColorBy))
            .filter(([action, tabId]) => {

                return action.type === TRELLIS_CHANGE_AXIS && action.payload.yAxis
                    && NEW_APPROACH_TAB_LIST.contains(tabId);
            })
            .do(([action, tabId, currentYAxisOption, currentColorBy]) => {
                this.trellisingDispatcher.cacheColorByForYAxis(currentYAxisOption, currentColorBy, tabId);
                this._store.dispatch(this.trellisingActionCreator.makeLoadingAction(true, action.payload.tabId));
                this._store.dispatch(
                    new ChangeGroupBySetting({
                        tabId,
                        groupBy: 'Y_AXIS',
                        groupBySetting: action.payload.option
                    })
                );

            })
            .withLatestFrom(
                this._store.select(getTrellisingRequired),
                this._store.select(getCurrentNewYAxisOption)
            )
            .mergeMap(([[action, tabId], trellisingRequired, yAxisOption]) => {
                if (trellisingRequired) {
                    return this.dataService.getTrellisOptions(tabId, yAxisOption)
                        .map((trellisOptions: TrellisOptions<any>[]) => {
                            return {
                                tabId, yAxisOption,
                                trellisOptions: trellisOptions.map(option => {
                                    (<any>option).category = 'MANDATORY_TRELLIS';
                                    return option;
                                })
                            };
                        });
                } else {
                    return Observable.of({tabId, yAxisOption, trellisOptions: []});
                }
            })
            .withLatestFrom(this._store.select(getColorByRequired), this._store.select(getFiltersUpdateOnYAxisChangeRequired))
            .mergeMap(([{tabId, yAxisOption, trellisOptions}, colorByRequired, updateFilters]) => {
                if (updateFilters) {
                    this.filtersUtils.getFilterModelById(tabId).makeFilterRequest(false);
                }
                if (colorByRequired) {
                    return this.dataService.getColorByOptions(tabId, yAxisOption)
                        .map((colorByOptions: TrellisOptions<any>[]) => {
                            return colorByOptions.map(option => {
                                (<any>option).category = 'NON_MANDATORY_SERIES';
                                return option;
                            });
                        })
                        .map((colorByOptions: TrellisOptions<any>[]) => {
                            this.updateTrellisOptions(colorByOptions.concat(trellisOptions), '', tabId);
                            return tabId;
                        });
                } else {
                    this.updateTrellisOptions(trellisOptions, '');
                    return Observable.of(tabId);
                }
            })
            .withLatestFrom(
                this._store.select(getPlotDataRequestOptions)
            )
            .mergeMap(([tabId, {
                xAxisOption, yAxisOption, limit, offset, trellising, colorByOptions,
                plotSettings, filterTrellisByOptions
            }]) => {
                const settings = constructDataRequestPayload(xAxisOption.toJS(),
                    yAxisOption.toJS(),
                    trellising,
                    limit,
                    offset,
                    colorByOptions,
                    plotSettings,
                    filterTrellisByOptions);
                return this.dataService.getPlotData(tabId, yAxisOption.toJS(), settings)
                    .map((payload: List<IPlot>) => {
                        this.trellisingDispatcher.clearSelection(tabId);
                        this.updatePlotOptions(payload, tabId, true);
                        return this.trellisingActionCreator.makeLoadingAction(false, tabId);
                    });
            });
    }