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 c8490c42366248a094f99f183c3566ab4c6fecb0 Author: Marat Gubaidullin <[email protected]> AuthorDate: Fri Feb 27 17:23:22 2026 -0500 Front-end Fix for 4.18.0 --- karavan-app/src/main/webui/public/logo.svg | 178 +++++++++++++++++++++ .../src/main/webui/public/silent-check-sso.html | 8 + .../src/main/webui/src/karavan/api/AccessApi.tsx | 16 ++ .../src/main/webui/src/karavan/api/KaravanApi.tsx | 12 -- .../webui/src/karavan/app/login/OrbitLines.tsx | 68 ++++++++ .../src/karavan/app/navigation/MainRoutes.tsx | 7 +- .../src/karavan/app/navigation/PlatformLogo.tsx | 28 ++++ .../karavan/app/navigation/ProjectFunctionHook.tsx | 124 +++++++++++--- 8 files changed, 399 insertions(+), 42 deletions(-) diff --git a/karavan-app/src/main/webui/public/logo.svg b/karavan-app/src/main/webui/public/logo.svg new file mode 100644 index 00000000..4452ba66 --- /dev/null +++ b/karavan-app/src/main/webui/public/logo.svg @@ -0,0 +1,178 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + width="360.13885" + height="360.13885" + viewBox="0 0 360.13885 360.13885" + version="1.1" + preserveAspectRatio="xMidYMid" + id="svg50" + xmlns:xlink="http://www.w3.org/1999/xlink" + xmlns="http://www.w3.org/2000/svg"> + <defs + id="defs31"> + <linearGradient + id="linearGradient1351"> + <stop + style="stop-color:#dcffff;stop-opacity:1" + offset="0" + id="stop1347" /> + <stop + style="stop-color:#96d2e6;stop-opacity:1" + offset="1" + id="stop1349" /> + </linearGradient> + <circle + id="path-1" + cx="128" + cy="128.00015" + r="128" /> + <linearGradient + x1="-26.051073" + y1="271.33054" + x2="254.31573" + y2="0.047514945" + id="linearGradient-3" + gradientUnits="userSpaceOnUse"> + <stop + stop-color="#F69923" + offset="0%" + id="stop10" + style="stop-color:#4790bb;stop-opacity:1" /> + <stop + stop-color="#F79A23" + offset="10.996%" + id="stop12" + style="stop-color:#64b7db;stop-opacity:1" /> + <stop + stop-color="#E97826" + offset="94.502%" + id="stop14" + style="stop-color:#326ea0;stop-opacity:1" /> + </linearGradient> + <linearGradient + x1="-32.163429" + y1="277.02905" + x2="259.33835" + y2="-5.0281582" + id="linearGradient-4" + gradientUnits="userSpaceOnUse"> + <stop + stop-color="#F69923" + offset="0%" + id="stop17" /> + <stop + stop-color="#F79A23" + offset="8.0478%" + id="stop19" /> + <stop + stop-color="#E97826" + offset="41.874%" + id="stop21" /> + </linearGradient> + <linearGradient + x1="217.94496" + y1="67.504837" + x2="99.458817" + y2="247.00549" + id="linearGradient-5" + gradientTransform="scale(0.96441978,1.0368929)" + gradientUnits="userSpaceOnUse" + xlink:href="#linearGradient-4"> + <stop + stop-color="#F6E423" + offset="0%" + id="stop24" + style="stop-color:#92d6d5;stop-opacity:1" /> + <stop + stop-color="#F79A23" + offset="41.191%" + id="stop26" + style="stop-color:#79b7cc;stop-opacity:1" /> + <stop + stop-color="#E97826" + offset="73.271%" + id="stop28" + style="stop-color:#5891c5;stop-opacity:1" /> + </linearGradient> + <mask + id="mask-2" + fill="#ffffff"> + <use + xlink:href="#path-1" + id="use33" + x="0" + y="0" + width="100%" + height="100%" /> + </mask> + <mask + id="mask-2-7" + fill="#ffffff"> + <use + xlink:href="#path-1" + id="use137" + x="0" + y="0" + width="100%" + height="100%" /> + </mask> + <linearGradient + xlink:href="#linearGradient1351" + id="linearGradient1345" + x1="233.12198" + y1="56.01545" + x2="2.2396212" + y2="242.78015" + gradientUnits="userSpaceOnUse" /> + </defs> + <g + id="g36" + transform="translate(45.104634,56.041665)" /> + <circle + fill="url(#linearGradient-3)" + fill-rule="nonzero" + mask="url(#mask-2)" + cx="127.99429" + cy="127.99429" + r="123.11053" + id="circle38" + style="fill:url(#linearGradient-3)" + transform="translate(45.104634,56.041665)" /> + <g + id="g2266" + transform="translate(45.104634,56.041665)"> + <path + d="m 98.043695,75.516752 c -1.750682,-0.002 -3.524167,0.0098 -5.292059,0.06144 -2.05519,0.06065 -4.816316,0.713182 -7.999625,1.784532 53.775199,40.834016 73.108199,114.497516 39.875049,178.514206 1.12865,0.0293 2.24876,0.12307 3.38456,0.12307 60.7361,0 111.49261,-42.32269 124.60904,-99.07129 C 214.07872,111.75077 161.80794,75.61511 98.043301,75.516654 Z" + fill="url(#linearGradient-5)" + fill-rule="nonzero" + opacity="0.75" + mask="url(#mask-2)" + id="path42" + style="fill:url(#linearGradient-5);fill-opacity:1" /> + </g> + <path + d="M 84.752011,77.367742 C 66.89547,83.377158 32.82977,104.54579 0.07906091,132.8108 2.5662796,200.14549 57.107277,254.12351 124.62706,255.88195 157.86021,191.86526 138.528,118.20176 84.752011,77.367742 Z" + fill="#28170b" + fill-rule="nonzero" + opacity="0.75" + mask="url(#mask-2)" + id="path44" + style="fill:#1e4b7b;fill-opacity:1" + transform="translate(45.104634,56.041665)" /> + <path + d="m 128.74719,54.004528 c -10.98485,5.495372 0,27.466068 0,27.466068 -32.973011,27.483724 -25.9672,74.429124 -64.435392,74.429124 -20.970343,0 -42.242226,-24.0768 -64.23273709,-38.82804 -0.28309669,3.47897 -0.78535974,6.97247 -0.78535974,10.52442 0,48.09504 26.26287383,89.92436 65.41967783,111.89721 10.952683,-1.3796 22.838636,-4.11444 31.050991,-9.59255 43.14527,-28.76482 53.85703,-83.49096 71.48633,-109.92509 10.97897,-16.492 62.43429,-15.06102 65.90679,-22.01013 5.50126,-10 [...] + fill="#ffffff" + fill-rule="nonzero" + mask="url(#mask-2-7)" + id="path150" + transform="translate(44.335601,55.908568)" + style="fill:url(#linearGradient1345);fill-opacity:1" /> + <path + d="M 128,256 C 57.307552,256 0,198.69245 0,128 0,57.307552 57.307552,0 128,0 c 70.69245,0 128,57.307552 128,128 0,70.69245 -57.30755,128 -128,128 z m 0,-9.76795 C 193.29776,246.23205 246.23205,193.29776 246.23205,128 246.23205,62.702243 193.29776,9.7679529 128,9.7679529 62.702243,9.7679529 9.7679529,62.702243 9.7679529,128 9.7679529,193.29776 62.702243,246.23205 128,246.23205 Z" + fill="url(#linearGradient-4)" + fill-rule="nonzero" + mask="url(#mask-2)" + id="path40" + style="fill:#2d4150;fill-opacity:1" + transform="matrix(1.020345,0,0,1.020345,41.979634,53.958328)" /> +</svg> \ No newline at end of file diff --git a/karavan-app/src/main/webui/public/silent-check-sso.html b/karavan-app/src/main/webui/public/silent-check-sso.html new file mode 100644 index 00000000..f1156265 --- /dev/null +++ b/karavan-app/src/main/webui/public/silent-check-sso.html @@ -0,0 +1,8 @@ +<!doctype html> +<html> +<body> +<script> + parent.postMessage(location.href, location.origin); +</script> +</body> +</html> \ No newline at end of file diff --git a/karavan-app/src/main/webui/src/karavan/api/AccessApi.tsx b/karavan-app/src/main/webui/src/karavan/api/AccessApi.tsx index dbc1dd71..e6cd1812 100644 --- a/karavan-app/src/main/webui/src/karavan/api/AccessApi.tsx +++ b/karavan-app/src/main/webui/src/karavan/api/AccessApi.tsx @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ import axios, {AxiosResponse} from "axios"; import {AccessPassword, AccessRole, AccessUser} from "../models/AccessModels"; import {ErrorEventBus} from "@bus/ErrorEventBus"; diff --git a/karavan-app/src/main/webui/src/karavan/api/KaravanApi.tsx b/karavan-app/src/main/webui/src/karavan/api/KaravanApi.tsx index 845c33c5..1d7c437e 100644 --- a/karavan-app/src/main/webui/src/karavan/api/KaravanApi.tsx +++ b/karavan-app/src/main/webui/src/karavan/api/KaravanApi.tsx @@ -34,7 +34,6 @@ import {Buffer} from 'buffer'; import {EventBus} from "@features/project/designer/utils/EventBus"; import {ErrorEventBus} from "@bus/ErrorEventBus"; import {AuthApi, getCurrentUser} from "@api/auth/AuthApi"; -import {ProjectFolderCommit} from "@stores/CommitsStore"; const instance = AuthApi.getInstance(); @@ -213,17 +212,6 @@ export class KaravanApi { }); } - static async getProjectCommits(projectId: string, after: (commits: ProjectFolderCommit[]) => void) { - instance.get(`/ui/git/commits/${projectId}`) - .then(res => { - if (res.status === 200) { - after(res.data); - } - }).catch(err => { - ErrorEventBus.sendApiError(err); - }); - } - static async loadProjectCommits(projectId: string, after: (res: any) => void) { instance.post(`/ui/git/commits/${projectId}`) .then(res => { diff --git a/karavan-app/src/main/webui/src/karavan/app/login/OrbitLines.tsx b/karavan-app/src/main/webui/src/karavan/app/login/OrbitLines.tsx new file mode 100644 index 00000000..544466a1 --- /dev/null +++ b/karavan-app/src/main/webui/src/karavan/app/login/OrbitLines.tsx @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import React from 'react'; + +const OrbitLines = () => { + return ( + <svg + className="orbit-lines-svg" + viewBox="0 0 400 400" + xmlns="http://www.w3.org/2000/svg" + > + <defs> + {/* The Magic Gradient: Orange to Transparent to Blue */} + <linearGradient id="orbit-grad" x1="0%" y1="0%" x2="100%" y2="100%"> + <stop offset="0%" stopColor="#ec7a08" stopOpacity="1" /> + <stop offset="50%" stopColor="#f97316" stopOpacity="0.5" /> + <stop offset="100%" stopColor="#0066cc" stopOpacity="1" /> + </linearGradient> + + {/* The Glow Effect */} + <filter id="glow"> + <feGaussianBlur stdDeviation="2.5" result="coloredBlur" /> + <feMerge> + <feMergeNode in="coloredBlur" /> + <feMergeNode in="SourceGraphic" /> + </feMerge> + </filter> + </defs> + + {/* Outer Ring (Matches your icon radius of 150px) */} + <circle + cx="200" cy="200" r="170" + fill="none" + stroke="url(#orbit-grad)" + strokeWidth="2" + filter="url(#glow)" + opacity="1" + /> + + {/* Inner Decorative Ring (Smaller, thinner) */} + <circle + cx="200" cy="200" r="130" + fill="none" + stroke="url(#orbit-grad)" + strokeWidth="1" + strokeDasharray="10 10" /* Makes it dashed/techy */ + filter="url(#glow)" + opacity="0.5" + /> + </svg> + ); +}; + +export default OrbitLines; \ No newline at end of file diff --git a/karavan-app/src/main/webui/src/karavan/app/navigation/MainRoutes.tsx b/karavan-app/src/main/webui/src/karavan/app/navigation/MainRoutes.tsx index 799d4293..504a2a7d 100644 --- a/karavan-app/src/main/webui/src/karavan/app/navigation/MainRoutes.tsx +++ b/karavan-app/src/main/webui/src/karavan/app/navigation/MainRoutes.tsx @@ -21,18 +21,13 @@ import {SystemPage} from "@features/system/SystemPage"; import {AccessPage} from "@features/access/AccessPage"; import {DocumentationPage} from "@features/documentation/DocumentationPage"; import {ROUTES} from "./Routes"; -import {AsyncPage} from "@features/landscape/AsyncPage"; import {ProtectedRoute} from "@app/navigation/ProtectedRoute"; import {ProjectFunctionHook} from "@app/navigation/ProjectFunctionHook"; import {ProjectProvider} from "@features/project/ProjectContext"; import {DeveloperManager} from "@features/project/developer/DeveloperManager"; import ProjectPage from "@features/project/ProjectPage"; import {ProjectsPage} from "@features/projects/ProjectsPage"; -import {SharedSchemasPage} from "@features/schemas/SharedSchemasPage"; -import {DashboardPage} from "@features/dashboard/DashboardPage"; -import {OpenApiPage} from "@features/apis/OpenApiPage"; import {LoginPage} from "@app/login/LoginPage"; -import {useReadinessStore} from "@stores/ReadinessStore"; import {SettingsPage} from "@features/settings/SettingsPage"; export function MainRoutes() { @@ -84,7 +79,7 @@ export function MainRoutes() { <Route path={ROUTES.ACL} element={<ProtectedRoute><AccessPage/></ProtectedRoute>}/> <Route path={ROUTES.FORBIDDEN} element={<NotAuthorizedPage/>}/> {/*{readiness?.environment === 'dev' && <Route path="*" element={<Navigate to={ROUTES.PROJECTS} replace/>}/>}*/} - <Route path="*" element={<Navigate to={ROUTES.DASHBOARD} replace/>}/> + <Route path="*" element={<Navigate to={ROUTES.PROJECTS} replace/>}/> </Routes> ) } \ No newline at end of file diff --git a/karavan-app/src/main/webui/src/karavan/app/navigation/PlatformLogo.tsx b/karavan-app/src/main/webui/src/karavan/app/navigation/PlatformLogo.tsx new file mode 100644 index 00000000..3a116817 --- /dev/null +++ b/karavan-app/src/main/webui/src/karavan/app/navigation/PlatformLogo.tsx @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import {KaravanIcon} from "@features/project/designer/icons/KaravanIcons"; + +export function PlatformLogoBase64() { + + return 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgICAgICB3aWR0aD0iMzYwLjEzODg1IgogICAgICAgIGhlaWdodD0iMzYwLjEzODg1IgogICAgICAgIHZpZXdCb3g9IjAgMCAzNjAuMTM4ODUgMzYwLjEzODg1IgogICAgICAgIHZlcnNpb249IjEuMSIKICAgICAgICBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCIKICAgICAgICBpZD0ic3ZnNTAiCiAgICAgICAgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiCiAgICAgICAgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KICA8ZGVmcwogIC [...] +} + +export function PlatformLogo(classNames?: string) { + return KaravanIcon() +} + +export default PlatformLogo; diff --git a/karavan-app/src/main/webui/src/karavan/app/navigation/ProjectFunctionHook.tsx b/karavan-app/src/main/webui/src/karavan/app/navigation/ProjectFunctionHook.tsx index 7759312b..5e2d14c4 100644 --- a/karavan-app/src/main/webui/src/karavan/app/navigation/ProjectFunctionHook.tsx +++ b/karavan-app/src/main/webui/src/karavan/app/navigation/ProjectFunctionHook.tsx @@ -1,20 +1,39 @@ -import {EventBus} from "@features/integration/designer/utils/EventBus"; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {EventBus} from "@features/project/designer/utils/EventBus"; import {ProjectFile} from "@models/ProjectModels"; -import {DslMetaModel} from "@features/integration/designer/utils/DslMetaModel"; +import {DslMetaModel} from "@features/project/designer/utils/DslMetaModel"; import {v4 as uuidv4} from "uuid"; -import {CamelUi} from "@features/integration/designer/utils/CamelUi"; +import {CamelUi} from "@features/project/designer/utils/CamelUi"; import {KaravanApi} from "@api/KaravanApi"; import {Integration} from "@karavan-core/model/IntegrationDefinition"; -import {ASYNCAPI_FILE_NAME_JSON, FILE_WORDS_SEPARATOR, KARAVAN_DOT_EXTENSION, KARAVAN_FILENAME, OPENAPI_FILE_NAME_JSON} from "@karavan-core/contants"; -import {FromDefinition, RouteConfigurationDefinition} from "@karavan-core/model/CamelDefinition"; +import {FILE_WORDS_SEPARATOR, KARAVAN_DOT_EXTENSION, KARAVAN_FILENAME, OPENAPI_FILE_NAME_JSON} from "@karavan-core/contants"; +import {RouteConfigurationDefinition} from "@karavan-core/model/CamelDefinition"; import {CamelDefinitionApiExt} from "@karavan-core/api/CamelDefinitionApiExt"; import {CamelDefinitionYaml} from "@karavan-core/api/CamelDefinitionYaml"; import {CamelDefinitionApi} from "@karavan-core/api/CamelDefinitionApi"; -import {useDesignerStore, useSelectorStore} from "@features/integration/designer/DesignerStore"; +import {useDesignerStore, useSelectorStore} from "@features/project/designer/DesignerStore"; import {shallow} from "zustand/shallow"; import {useAppConfigStore, useFilesStore, useFileStore, useProjectStore, useWizardStore} from "@stores/ProjectStore"; -import {toSpecialRouteId} from "@features/integration/designer/utils/ValidatorUtils"; +import {toSpecialRouteId} from "@features/project/designer/utils/ValidatorUtils"; import {ProjectService} from "@services/ProjectService"; +import {useTemplatesStore} from "@stores/SettingsStore"; +import {useContainerStatusesStore} from "@stores/ContainerStatusesStore"; export function ProjectFunctionHook() { @@ -24,8 +43,10 @@ export function ProjectFunctionHook() { const [setFile] = useFileStore((s) => [s.setFile], shallow); const [setShowWizard] = useWizardStore((s) => [s.setShowWizard], shallow) const [setDesignerSwitch] = useDesignerStore((s) => [s.setDesignerSwitch], shallow) - const [project, tabIndex, setTabIndex, refreshTrace] = - useProjectStore((s) => [s.project, s.tabIndex, s.setTabIndex, s.refreshTrace], shallow); + const [project, tabIndex, setTabIndex, refreshTrace, fetchCamelStatuses] = + useProjectStore((s) => [s.project, s.tabIndex, s.setTabIndex, s.refreshTrace, s.fetchCamelStatuses], shallow); + const {fetchTemplateFiles} = useTemplatesStore(); + const { fetchContainers } = useContainerStatusesStore(); function createRouteConfiguration() { const integration = Integration.createNew(KARAVAN_FILENAME.ROUTE_CONFIGURATION); @@ -60,11 +81,14 @@ export function ProjectFunctionHook() { const integration = Integration.createNew(fName); let i; if (isRouteTemplate) { - const route = CamelDefinitionApi.createRouteDefinition({ - from: new FromDefinition({uri: dsl.uri}), - nodePrefixId: `route${FILE_WORDS_SEPARATOR}${fullUri}` - }); - const routeTemplate = CamelDefinitionApi.createRouteTemplateDefinition({route: route}); + const keys = dsl.properties ? Object.keys(dsl.properties) : []; + const key = keys.at(0); + const routeId = dsl.properties?.[key] + "Route"; + const templateId = dsl.properties?.[key] + "RouteTemplate"; + const route = CamelUi.createRouteFromComponent(dsl.uri, dsl.properties, ''); + route.id = routeId + route.nodePrefixId = routeId + const routeTemplate = CamelDefinitionApi.createRouteTemplateDefinition({id: templateId, route: route}); i = CamelDefinitionApiExt.addRouteTemplateToIntegration(integration, routeTemplate); } else { i = CamelDefinitionApiExt.addStepToIntegration(integration, route, ''); @@ -168,19 +192,71 @@ export function ProjectFunctionHook() { }) } - function isOpenApiExists(): boolean { - const openApiFile = files.filter(f => f.name === OPENAPI_FILE_NAME_JSON)?.at(0); - return openApiFile !== undefined + async function saveFiles(projectId: string, filesToSave: ProjectFile[], afterSuccess?: () => void) { + + // 1. Fetch all existing files for the project once + KaravanApi.getFiles(projectId, async (existingFiles: ProjectFile[]) => { + const existingNames = new Set(existingFiles.map(f => f.name)); + + // 2. Map each file to a Promise (Update if exists, Create if not) + const savePromises = filesToSave.map(file => { + return new Promise<boolean>((resolve) => { + const alreadyExists = existingNames.has(file.name); + + if (alreadyExists) { + KaravanApi.putProjectFile(file, (result) => resolve(!!result)); + } else { + KaravanApi.saveProjectFile(file, (result) => resolve(!!result)); + } + }); + }); + + try { + // 3. Wait for all individual save/put operations to finish + const results = await Promise.all(savePromises); + const allSuccessful = results.every(res => res === true); + + // 4. Final actions after all operations complete + if (allSuccessful) { + afterSuccess?.(); + EventBus.sendAlert("Success", `All ${filesToSave.length} files processed`, "success"); + } else { + const failCount = results.filter(r => !r).length; + EventBus.sendAlert("Warning", `${failCount} files failed to save`, "danger"); + } + } catch (error) { + EventBus.sendAlert("Error", "A critical error occurred during the batch save", "danger"); + } + }); } - function isAsyncApiExists(): boolean { - const asyncApiFile = files.filter(f => f.name === ASYNCAPI_FILE_NAME_JSON)?.at(0); - return asyncApiFile !== undefined + function saveFile(file: ProjectFile, afterSuccess?: () => void) { + KaravanApi.getProjectFilesByName(file.projectId, file.name, found => { + if (found) { + KaravanApi.putProjectFile(file, (result) => { + if (result) { + afterSuccess?.(); + EventBus.sendAlert("Success", `File ${file.name} successfully updated`, "success"); + } else { + EventBus.sendAlert("Error updating file", file.name, "danger"); + } + }) + } else { + KaravanApi.saveProjectFile(file, (result, fileRes) => { + if (result) { + afterSuccess?.(); + EventBus.sendAlert("Success", `File ${file.name} successfully created`, "success"); + } else { + EventBus.sendAlert("Error creating file", fileRes?.response?.data, "danger"); + } + }) + } + }) } function refreshData() { - ProjectService.refreshAllContainerStatuses(); - ProjectService.refreshCamelStatus(project.projectId, config.environment); + fetchCamelStatuses(project.projectId, config.environment); + fetchContainers(); if (tabIndex === "build") { ProjectService.refreshAllDeploymentStatuses(); ProjectService.refreshImages(project.projectId); @@ -191,9 +267,9 @@ export function ProjectFunctionHook() { } function refreshSharedData() { - + fetchTemplateFiles(); } return {createNewRouteFile, createOpenApiRestFile, createNewBean, createNewKamelet, createRouteConfiguration, refreshSharedData, - createAsyncApi, isOpenApiExists, createNewRestFile, refreshData, isAsyncApiExists, createOpenApi, project} + project, createNewRestFile, refreshData, createAsyncApi, createOpenApi} }
