@axa-fr/slimfaas-planet-saver 0.30.6 → 0.30.7

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@axa-fr/slimfaas-planet-saver",
3
3
  "private": false,
4
- "version": "0.30.6",
4
+ "version": "0.30.7",
5
5
  "type": "module",
6
6
  "module": "./src/SlimFaasPlanetSaver.js",
7
7
  "description": "Pure vanilla javascript which call SlimFaas API to convert infrastructures resilience to an UX resilience and help to save the planet",
@@ -4,7 +4,7 @@
4
4
  return tempUrl;
5
5
  }
6
6
 
7
-
7
+ let id =1;
8
8
 
9
9
  export default class SlimFaasPlanetSaver {
10
10
  constructor(baseUrl, options = {}) {
@@ -25,11 +25,12 @@ export default class SlimFaasPlanetSaver {
25
25
  this.spanElement = null;
26
26
  this.styleElement = null;
27
27
  this.isReady = false;
28
-
29
- this.events = document.createElement('div');
28
+ this.id = id++;
29
+ this.cleanned = false;
30
30
  }
31
31
 
32
32
  initialize() {
33
+ this.cleanned = false;
33
34
  this.lastMouseMoveTime = Date.now();
34
35
  this.handleMouseMove = this.handleMouseMove.bind(this);
35
36
  this.handleVisibilityChange = this.handleVisibilityChange.bind(this);
@@ -39,6 +40,7 @@ export default class SlimFaasPlanetSaver {
39
40
 
40
41
  this.createOverlay();
41
42
  this.injectStyles();
43
+
42
44
  }
43
45
  handleMouseMove() {
44
46
  this.lastMouseMoveTime = Date.now();
@@ -46,11 +48,6 @@ export default class SlimFaasPlanetSaver {
46
48
 
47
49
  handleVisibilityChange() {
48
50
  this.isDocumentVisible = !document.hidden;
49
- if (this.isDocumentVisible) {
50
- this.startPolling();
51
- } else {
52
- this.stopPolling();
53
- }
54
51
  }
55
52
 
56
53
  async wakeUpPods(data) {
@@ -100,9 +97,11 @@ export default class SlimFaasPlanetSaver {
100
97
  const errorMessage = error.message;
101
98
  this.updateOverlayMessage(this.overlayErrorMessage, 'error', this.overlayErrorSecondaryMessage);
102
99
  this.errorCallback(errorMessage);
103
- this.triggerEvent('error', { message: errorMessage });
104
100
  console.error('Error fetching slimfaas data:', errorMessage);
105
101
  } finally {
102
+ if(!this.intervalId) {
103
+ return;
104
+ }
106
105
  this.intervalId = setTimeout(() => {
107
106
  this.fetchStatus();
108
107
  }, this.interval);
@@ -119,7 +118,7 @@ export default class SlimFaasPlanetSaver {
119
118
  }
120
119
 
121
120
  startPolling() {
122
- if (this.intervalId || !this.baseUrl) return;
121
+ if (this.intervalId || !this.baseUrl || this.cleanned) return;
123
122
 
124
123
  this.fetchStatus();
125
124
 
@@ -208,6 +207,7 @@ export default class SlimFaasPlanetSaver {
208
207
  createOverlay() {
209
208
  this.overlayElement = document.createElement('div');
210
209
  this.overlayElement.className = 'slimfaas-environment-overlay';
210
+ this.overlayElement.id = `slimfaas-environment-overlay-${this.id}`;
211
211
 
212
212
  // Créer l'élément icône
213
213
  this.iconElement = document.createElement('div');
@@ -234,6 +234,7 @@ export default class SlimFaasPlanetSaver {
234
234
  }
235
235
 
236
236
  showOverlay() {
237
+ if(this.cleanned) return;
237
238
  if (this.overlayElement && !document.body.contains(this.overlayElement)) {
238
239
  document.body.appendChild(this.overlayElement);
239
240
  }
@@ -264,15 +265,14 @@ export default class SlimFaasPlanetSaver {
264
265
  }
265
266
  }
266
267
 
267
- triggerEvent(eventName, detail) {
268
- const event = new CustomEvent(eventName, { detail });
269
- this.events.dispatchEvent(event);
270
- }
271
-
272
268
  cleanup() {
269
+ this.cleanned = true;
273
270
  this.stopPolling();
274
271
  document.removeEventListener('visibilitychange', this.handleVisibilityChange);
275
272
  document.removeEventListener('mousemove', this.handleMouseMove);
273
+
274
+ document.getElementById(`slimfaas-environment-overlay-${this.id}`)?.remove();
275
+
276
276
  if (this.overlayElement && document.body.contains(this.overlayElement)) {
277
277
  document.body.removeChild(this.overlayElement);
278
278
  }