-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Split properties switch into generalized function
- Loading branch information
Showing
4 changed files
with
155 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 2 additions & 8 deletions
10
packages/ui/src/components/PropertiesModal/PropertiesTabs.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/ui/src/components/PropertiesModal/camel-properties-to-tab.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { IPropertiesTableFilter } from '../../camel-utils/camel-to-table.adapter'; | ||
import { IPropertiesTab, IPropertiesTable } from './PropertiesModal.models'; | ||
|
||
interface IPropertiesTransformToTable { | ||
transformFunction: (properties: any, filter?: IPropertiesTableFilter) => IPropertiesTable; | ||
propertiesObject: any; | ||
tableCaption?: string; | ||
filter?: IPropertiesTableFilter; | ||
} | ||
|
||
/** | ||
* This function transforms properties data (from camel-component, camel-processor, kamelets) into one or more tables which are added into the final IPropertiesTab. | ||
* | ||
* @param transformationsData object which contains function which is used for transfromation properties object into IPropertiesTable, optionally filter and table caption | ||
* @param tabTitle - Title of the Tab | ||
* @returns Tab data which will be use for rendering one Tab | ||
*/ | ||
export const transformPropertiesIntoTab = ( | ||
transformationsData: IPropertiesTransformToTable[], | ||
tabTitle: string, | ||
): IPropertiesTab | undefined => { | ||
let tables = []; | ||
for (let transformationData of transformationsData) { | ||
let table = transformationData.transformFunction(transformationData.propertiesObject, transformationData.filter); | ||
if (table.rows.length == 0) continue; // we don't care about empty table | ||
if (transformationData.tableCaption) | ||
table.caption = transformationData.tableCaption + ' (' + table.rows.length + ')'; | ||
tables.push(table); | ||
} | ||
if (tables.length == 0) return undefined; | ||
|
||
let allRowsInAllTables = 0; | ||
tables.forEach((table) => { | ||
allRowsInAllTables += table.rows.length; | ||
}); | ||
return { | ||
rootName: tabTitle + ' (' + allRowsInAllTables + ')', | ||
tables: tables, | ||
}; | ||
}; |