@nvent-addon/app 0.5.9 → 0.5.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nventapp",
3
- "version": "0.5.9",
3
+ "version": "0.5.10",
4
4
  "configKey": "nventapp",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
@@ -0,0 +1,12 @@
1
+ import { type Ref } from '#imports';
2
+ /**
3
+ * Composable for real-time flow runs updates via WebSocket
4
+ * Similar to useQueueUpdates - triggers refresh flag when flow stats change
5
+ */
6
+ export declare function useFlowRunsUpdates(flowName: Ref<string>): {
7
+ isConnected: Ref<boolean, boolean>;
8
+ isReconnecting: Ref<boolean, boolean>;
9
+ shouldRefreshRuns: import("vue").ComputedRef<boolean>;
10
+ lastUpdate: import("vue").ComputedRef<number | null>;
11
+ resetRefreshFlag: () => void;
12
+ };
@@ -0,0 +1,59 @@
1
+ import { ref, computed, watch, onMounted, onUnmounted } from "#imports";
2
+ import { useFlowWebSocket } from "./useFlowWebSocket.js";
3
+ export function useFlowRunsUpdates(flowName) {
4
+ const flowWs = useFlowWebSocket();
5
+ const state = ref({
6
+ shouldRefreshRuns: false,
7
+ lastUpdate: null
8
+ });
9
+ let previousStats = null;
10
+ const setupSubscription = () => {
11
+ if (!import.meta.client) return;
12
+ flowWs.subscribeStats({
13
+ onInitial: (data) => {
14
+ if (data.id !== flowName.value) return;
15
+ const stats = data?.metadata?.stats;
16
+ if (stats) {
17
+ previousStats = { total: stats.total, running: stats.running };
18
+ }
19
+ },
20
+ onUpdate: (data) => {
21
+ if (data.id !== flowName.value) return;
22
+ const stats = data?.metadata?.stats;
23
+ if (!stats) return;
24
+ const hasNewRuns = previousStats && stats.total !== previousStats.total;
25
+ const runningChanged = previousStats && stats.running !== previousStats.running;
26
+ if (hasNewRuns || runningChanged) {
27
+ state.value.shouldRefreshRuns = true;
28
+ state.value.lastUpdate = Date.now();
29
+ }
30
+ previousStats = { total: stats.total, running: stats.running };
31
+ }
32
+ });
33
+ };
34
+ const resetRefreshFlag = () => {
35
+ state.value.shouldRefreshRuns = false;
36
+ };
37
+ onMounted(() => {
38
+ if (import.meta.client && flowName.value) {
39
+ setupSubscription();
40
+ }
41
+ });
42
+ watch(flowName, (newName, oldName) => {
43
+ if (newName && newName !== oldName) {
44
+ previousStats = null;
45
+ state.value.shouldRefreshRuns = false;
46
+ state.value.lastUpdate = null;
47
+ }
48
+ });
49
+ onUnmounted(() => {
50
+ flowWs.unsubscribeStats();
51
+ });
52
+ return {
53
+ isConnected: flowWs.connected,
54
+ isReconnecting: flowWs.reconnecting,
55
+ shouldRefreshRuns: computed(() => state.value.shouldRefreshRuns),
56
+ lastUpdate: computed(() => state.value.lastUpdate),
57
+ resetRefreshFlag
58
+ };
59
+ }
@@ -388,7 +388,7 @@
388
388
  </template>
389
389
 
390
390
  <script setup>
391
- import { ref, computed, watch, onMounted, onUnmounted } from "#imports";
391
+ import { ref, computed, watch } from "#imports";
392
392
  import FlowDiagram from "../../components/flow/Diagram.vue";
393
393
  import FlowRunOverview from "../../components/flow/RunOverview.vue";
394
394
  import FlowRunTimeline from "../../components/flow/RunTimeline.vue";
@@ -399,6 +399,7 @@ import { useRoute, useRouter } from "#app";
399
399
  import { useAnalyzedFlows } from "../../composables/useAnalyzedFlows";
400
400
  import { useFlowRuns } from "../../composables/useFlowRuns";
401
401
  import { useFlowRunTimeline } from "../../composables/useFlowRunTimeline";
402
+ import { useFlowRunsUpdates } from "../../composables/useFlowRunsUpdates";
402
403
  import { useComponentRouter } from "../../composables/useComponentRouter";
403
404
  const componentRouter = useComponentRouter();
404
405
  const router = useRouter();
@@ -474,36 +475,13 @@ const runs = computed(() => runsResponse.value?.items || []);
474
475
  const totalRuns = computed(() => runsResponse.value?.total || 0);
475
476
  const loadingRuns = computed(() => runsStatus.value === "pending");
476
477
  const { flowState, isConnected, isReconnecting } = useFlowRunTimeline(selectedFlowRef, selectedRunIdRef);
477
- let pollInterval = null;
478
- const startPolling = () => {
479
- if (pollInterval) return;
480
- pollInterval = setInterval(() => {
481
- if (selectedFlow.value) {
482
- refreshRuns();
483
- }
484
- }, 3e3);
485
- };
486
- const stopPolling = () => {
487
- if (pollInterval) {
488
- clearInterval(pollInterval);
489
- pollInterval = null;
490
- }
491
- };
492
- watch(selectedFlow, (flow) => {
493
- if (flow) {
494
- startPolling();
495
- } else {
496
- stopPolling();
497
- }
498
- }, { immediate: true });
499
- onMounted(() => {
500
- if (import.meta.client && selectedFlow.value) {
501
- startPolling();
478
+ const { shouldRefreshRuns, resetRefreshFlag } = useFlowRunsUpdates(selectedFlowRef);
479
+ watch(shouldRefreshRuns, async (shouldRefresh) => {
480
+ if (shouldRefresh) {
481
+ await refreshRuns();
482
+ resetRefreshFlag();
502
483
  }
503
484
  });
504
- onUnmounted(() => {
505
- stopPolling();
506
- });
507
485
  const startFlowModalOpen = ref(false);
508
486
  const flowInputJson = ref("{}");
509
487
  const jsonError = ref("");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nvent-addon/app",
3
- "version": "0.5.9",
3
+ "version": "0.5.10",
4
4
  "description": "nvent app module for Nuxt.js",
5
5
  "repository": "DevJoghurt/nvent",
6
6
  "license": "MIT",