| /******************************************************************************** |
| * Copyright (c) 2020 Contributors to the Eclipse Foundation |
| * |
| * See the NOTICE file(s) distributed with this work for additional |
| * information regarding copyright ownership. |
| * |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License 2.0 which is available at |
| * http://www.eclipse.org/legal/epl-2.0 |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| ********************************************************************************/ |
| |
| import {createSelector} from "@ngrx/store"; |
| import {IAPITextArrangementItemModel, IAPITextBlockGroupModel} from "../../../../core/api/text"; |
| import {arrayJoin, selectArrayProjector, selectPropertyProjector, TStoreEntities} from "../../../../util/store"; |
| import {IStatementEditorControlConfiguration} from "../../model"; |
| import {getStatementTextConfigurationSelector} from "../statement-configuration.selectors"; |
| import {getStatementErrorSelector} from "../statements-store-state.selectors"; |
| |
| const getTextConfigurationSelectorSelector = createSelector( |
| getStatementTextConfigurationSelector, |
| selectPropertyProjector("configuration") |
| ); |
| |
| export const getStatementStaticTextReplacementsSelector = createSelector( |
| getStatementTextConfigurationSelector, |
| selectPropertyProjector("replacements", {}) |
| ); |
| |
| export const getStatementTextSelectsSelector = createSelector( |
| getTextConfigurationSelectorSelector, |
| selectPropertyProjector("selects", {}) |
| ); |
| |
| export const getStatementTextBlockGroups = createSelector( |
| getTextConfigurationSelectorSelector, |
| selectArrayProjector("groups", []) |
| ); |
| |
| export const getStatementArrangementErrorSelector = createSelector( |
| getStatementErrorSelector, |
| selectArrayProjector("arrangement", []) |
| ); |
| |
| export const getStatementEditorControlConfigurationSelector = createSelector( |
| getStatementTextBlockGroups, |
| getStatementStaticTextReplacementsSelector, |
| getStatementTextSelectsSelector, |
| ( |
| textBlockGroups: IAPITextBlockGroupModel[], |
| replacements: TStoreEntities<string>, |
| selects: TStoreEntities<string[]>, |
| props: IAPITextArrangementItemModel[] |
| ): IStatementEditorControlConfiguration[] => { |
| const textBlocks = arrayJoin(...textBlockGroups.map(selectPropertyProjector("textBlocks"))); |
| return arrayJoin(props) |
| .map<IStatementEditorControlConfiguration>((item) => { |
| const textBlock = textBlocks.find((_) => _.id === item?.textblockId); |
| return { |
| textBlock, |
| selects, |
| replacements, |
| value: item |
| }; |
| }); |
| } |
| ); |