This is an automated email from the ASF dual-hosted git repository. marat pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-karavan.git
commit 255658b23e1738d8ab3ec6aaef0347c3e282e7ca Author: Marat Gubaidullin <marat.gubaidul...@gmail.com> AuthorDate: Tue Feb 14 11:56:57 2023 -0500 Add SupportedOnly option for #658 --- karavan-core/src/core/api/ComponentApi.ts | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/karavan-core/src/core/api/ComponentApi.ts b/karavan-core/src/core/api/ComponentApi.ts index c5222286..0f7c10e8 100644 --- a/karavan-core/src/core/api/ComponentApi.ts +++ b/karavan-core/src/core/api/ComponentApi.ts @@ -18,9 +18,14 @@ import {Component, ComponentProperty, SupportedComponent} from "../model/Compone const Components: Component[] = []; const SupportedComponents: SupportedComponent[] = []; +let SupportedOnly: boolean = false; export const ComponentApi = { + setSupportedOnly: (supportedOnly: boolean) => { + SupportedOnly = supportedOnly; + }, + saveSupportedComponents: (jsons: string[]) => { SupportedComponents.length = 0; const sc: SupportedComponent[] = jsons.map(json => ComponentApi.jsonToSupportedComponent(json)); @@ -47,13 +52,19 @@ export const ComponentApi = { saveComponent: (json: string) => { const component: Component = ComponentApi.jsonToComponent(json); - if (Components.findIndex((c:Component) => c.component.name === component.component.name) === -1) { + if (Components.findIndex((c: Component) => c.component.name === component.component.name) === -1) { Components.push(component); } }, getComponents: (): Component[] => { - return Components + const comps: Component[] = []; + if (SupportedOnly) { + comps.push(...Components.filter(comp => SupportedComponents.findIndex(sc => sc.name === comp.component.name) !== -1)); + } else { + comps.push(...Components); + } + return comps .map(comp => { const sc = SupportedComponents.find(sc => sc.name === comp.component.name); if (sc !== undefined) { @@ -66,11 +77,11 @@ export const ComponentApi = { } }) .sort((a, b) => { - if (a.component.name < b.component.name) { - return -1; - } - return a.component.name > b.component.name ? 1 : 0; - }); + if (a.component.name < b.component.name) { + return -1; + } + return a.component.name > b.component.name ? 1 : 0; + }); }, findByName: (name: string): Component | undefined => { @@ -218,7 +229,7 @@ export const ComponentApi = { result.push(val); if (separator) result.push(separators[index]); }); - if (result.at(result.length -1) === '') return result.slice(0, -2).join(''); // remove last colon + if (result.at(result.length - 1) === '') return result.slice(0, -2).join(''); // remove last colon return result.join(''); } }