diff --git a/package-lock.json b/package-lock.json index 982ab8dc..e0891da4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@electron-toolkit/preload": "^2.0.0", "@electron-toolkit/utils": "^2.0.1", "@fastify/error": "^3.4.1", - "@platformatic/ui-components": "^0.1.126", + "@platformatic/ui-components": "^0.1.128", "autoprefixer": "^10.4.16", "boring-name-generator": "^1.0.3", "electron-updater": "^6.1.7", @@ -1430,9 +1430,9 @@ } }, "node_modules/@platformatic/ui-components": { - "version": "0.1.126", - "resolved": "https://registry.npmjs.org/@platformatic/ui-components/-/ui-components-0.1.126.tgz", - "integrity": "sha512-0TL6ew3GQOq5jZtcXPtzrLQx/s4Krvqh9af26+gVhq5ST68COVQU3UrOuAzj9IibV0x0YC+LeoW/fUDRAuQdPQ==", + "version": "0.1.128", + "resolved": "https://registry.npmjs.org/@platformatic/ui-components/-/ui-components-0.1.128.tgz", + "integrity": "sha512-N61b2NzdSZc8cn4tRV38tEZZf6uuzyEGDrRIPVk7YD0xgoNz9wqIliMEQXvIsHwavmehrS46wYIkH3uYlc0ISg==", "dependencies": { "autoprefixer": "^10.4.12", "postcss": "^8.4.17", diff --git a/package.json b/package.json index 32d18ab3..3078c74c 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "@electron-toolkit/preload": "^2.0.0", "@electron-toolkit/utils": "^2.0.1", "@fastify/error": "^3.4.1", - "@platformatic/ui-components": "^0.1.126", + "@platformatic/ui-components": "^0.1.128", "autoprefixer": "^10.4.16", "boring-name-generator": "^1.0.3", "electron-updater": "^6.1.7", diff --git a/src/renderer/src/components/templates/SelectTemplate.jsx b/src/renderer/src/components/templates/SelectTemplate.jsx index 14484585..ee410772 100644 --- a/src/renderer/src/components/templates/SelectTemplate.jsx +++ b/src/renderer/src/components/templates/SelectTemplate.jsx @@ -35,8 +35,7 @@ function SelectTemplate ({ onClick, serviceName }) { useEffect(() => { async function getTemplates () { const templates = await getApiTemplates() - const tmpOptions = templates.map(e => e.orgName).filter(onlyUnique).sort().map(ele => ({ label: ele, value: ele, iconName: 'OrganizationIcon' })) - setOptionsOrganizationsTemplates([...tmpOptions]) + setOptionsOrganizationsTemplates([...getOrganizationGrouped(templates)]) setTemplates(templates) setFilteredTemplates([...templates]) setTemplateSelected(templates[0]) @@ -90,8 +89,34 @@ function SelectTemplate ({ onClick, serviceName }) { onClick() } - function onlyUnique (value, index, array) { - return array.indexOf(value) === index + function getOrganizationGrouped (templates) { + return templates.map(e => e.orgName).reduce((acc, currentValue) => { + const found = acc.find(a => a.label === currentValue) + if (found) { + found.count += 1 + } else { + acc.push({ + label: currentValue, + count: 1 + }) + } + return acc + }, []).sort((a, b) => { + const labelA = a.label.toUpperCase() + const labelB = b.label.toUpperCase() + if (labelA < labelB) { + return -1 + } + if (labelA > labelB) { + return 1 + } + return 0 + }).map(ele => ({ + label: ele.label, + value: ele.label, + iconName: 'OrganizationIcon', + descriptionValue: `( ${ele.count} ${ele.count > 1 ? 'Templates' : 'Template'} )` + })) } function handleClearTemplates () {