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


The following commit(s) were added to refs/heads/main by this push:
     new d53434d7 Fix #1307
d53434d7 is described below

commit d53434d799e2f7137be317ff391744a20e727f18
Author: Marat Gubaidullin <[email protected]>
AuthorDate: Fri May 31 09:57:59 2024 -0400

    Fix #1307
---
 .../src/main/webui/src/api/NotificationService.ts   |  1 -
 .../src/main/webui/src/api/ProjectService.ts        |  9 +++++----
 karavan-app/src/main/webui/src/api/ProjectStore.ts  |  7 ++++++-
 karavan-app/src/main/webui/src/main/Main.tsx        | 21 +++++++++++++--------
 4 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/karavan-app/src/main/webui/src/api/NotificationService.ts 
b/karavan-app/src/main/webui/src/api/NotificationService.ts
index 75fb501b..8b82ed9e 100644
--- a/karavan-app/src/main/webui/src/api/NotificationService.ts
+++ b/karavan-app/src/main/webui/src/api/NotificationService.ts
@@ -39,7 +39,6 @@ export const NotificationEventBus = {
     onEvent: () => karavanEvents.asObservable(),
 }
 
-console.log("Start Notification subscriber");
 const sub = NotificationEventBus.onEvent()?.subscribe((event: KaravanEvent) => 
{
     if (event.event === 'commit' && event.className === 'Project') {
         const projectId = event.data?.projectId;
diff --git a/karavan-app/src/main/webui/src/api/ProjectService.ts 
b/karavan-app/src/main/webui/src/api/ProjectService.ts
index b0364415..e829b908 100644
--- a/karavan-app/src/main/webui/src/api/ProjectService.ts
+++ b/karavan-app/src/main/webui/src/api/ProjectService.ts
@@ -25,7 +25,7 @@ import {
     useStatusesStore,
     useFileStore, useLogStore,
     useProjectsStore,
-    useProjectStore, useDevModeStore
+    useProjectStore, useDevModeStore, useAppConfigStore
 } from './ProjectStore';
 import {ProjectEventBus} from './ProjectEventBus';
 import {EventBus} from "../designer/utils/EventBus";
@@ -98,6 +98,7 @@ export class ProjectService {
     }
 
     public static pushProject(project: Project, commitMessage: string) {
+        useAppConfigStore.setState({notificationFetcherId: 
Math.random().toString()});
         const params = {
             'projectId': project.projectId,
             'message': commitMessage,
@@ -296,9 +297,9 @@ export class ProjectService {
             useProjectStore.setState({images: images})
         });
     }
-    
+
     public static reloadBlockedTemplates() {
-      KaravanApi.getTemplatesFiles((files: ProjectFile[]) => {
+        KaravanApi.getTemplatesFiles((files: ProjectFile[]) => {
             files.filter(f => f.name.endsWith('blocklist.txt')).forEach(file 
=> {
                 if (file.name === 'components-blocklist.txt') {
                     
ComponentApi.saveBlockedComponentNames(file.code.split(/\r?\n/));
@@ -307,6 +308,6 @@ export class ProjectService {
                     
KameletApi.saveBlockedKameletNames(file.code.split(/\r?\n/));
                 }
             });
-       });
+        });
     }
 }
\ No newline at end of file
diff --git a/karavan-app/src/main/webui/src/api/ProjectStore.ts 
b/karavan-app/src/main/webui/src/api/ProjectStore.ts
index 6476d58c..fb6b129c 100644
--- a/karavan-app/src/main/webui/src/api/ProjectStore.ts
+++ b/karavan-app/src/main/webui/src/api/ProjectStore.ts
@@ -41,6 +41,8 @@ interface AppConfigState {
     selectedEnv: string[];
     setSelectedEnv: (selectedEnv: string[]) => void;
     selectEnvironment: (name: string, selected: boolean) => void;
+    notificationFetcherId?: string;
+    resetNotificationFetcher: () => void
 }
 
 export const useAppConfigStore = createWithEqualityFn<AppConfigState>((set) => 
({
@@ -85,7 +87,10 @@ export const useAppConfigStore = 
createWithEqualityFn<AppConfigState>((set) => (
             }
             return {selectedEnv: state.selectedEnv};
         });
-    }
+    },
+    resetNotificationFetcher: ()  => {
+        set({notificationFetcherId: Math.random().toString()})
+    },
 }), shallow)
 
 
diff --git a/karavan-app/src/main/webui/src/main/Main.tsx 
b/karavan-app/src/main/webui/src/main/Main.tsx
index ed16b04b..b28d320d 100644
--- a/karavan-app/src/main/webui/src/main/Main.tsx
+++ b/karavan-app/src/main/webui/src/main/Main.tsx
@@ -34,7 +34,8 @@ import {NotificationApi} from "../api/NotificationApi";
 
 export function Main() {
 
-    const [readiness, setReadiness, isAuthorized] = useAppConfigStore((s) => 
[s.readiness, s.setReadiness, s.isAuthorized], shallow)
+    const [readiness, setReadiness, isAuthorized, notificationFetcherId, 
resetNotificationFetcher] =
+        useAppConfigStore((s) => [s.readiness, s.setReadiness, s.isAuthorized, 
s.notificationFetcherId, s.resetNotificationFetcher], shallow)
     const {getData} = useMainHook();
 
     useEffect(() => {
@@ -52,13 +53,7 @@ export function Main() {
     useEffect(() => {
         if (showMain()) {
             getData();
-            console.log("Start Notification fetcher");
-            const controller = new AbortController();
-            NotificationApi.notification(controller);
-            return () => {
-                console.log("Stop Notification fetcher");
-                controller.abort();
-            };
+            resetNotificationFetcher();
         } else if (KaravanApi.authType === 'oidc') {
             SsoApi.auth(() => {
                 KaravanApi.getMe((user: any) => {
@@ -68,6 +63,16 @@ export function Main() {
         }
     }, [readiness, isAuthorized]);
 
+    useEffect(() => {
+        console.log("Notification fetcher: start")
+        const controller = new AbortController();
+        NotificationApi.notification(controller);
+        return () => {
+            console.log("Notification fetcher: stop")
+            controller.abort();
+        };
+    }, [notificationFetcherId]);
+
     function checkAuthType() {
         KaravanApi.getAuthType((authType: string) => {
             console.log("Main AuthType", authType);

Reply via email to