vc-create-dashboard 3.0.86 → 3.0.88

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.
@@ -296,6 +296,94 @@ function filterActiveWidgets(widgets) {
296
296
  return (widgets ?? []).filter((w) => !w?.state || w.state === 'ACTIVE');
297
297
  }
298
298
 
299
+ const TIMEFRAME_DATE_TIME = /^(\d{4})-(\d{2})-(\d{2})[ T](\d{2}):(\d{2}):(\d{2})/;
300
+ function pad(value) {
301
+ return String(value).padStart(2, '0');
302
+ }
303
+ function formatLocalDateTime(date) {
304
+ return (`${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ` +
305
+ `${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`);
306
+ }
307
+ /**
308
+ * API timeframe values are UTC `YYYY-MM-DD HH:mm:ss` without a zone suffix.
309
+ * Convert to the browser/system timezone and keep the same format.
310
+ * Date-only values are left unchanged so legacy `YYYY-MM-DD` fields do not shift.
311
+ */
312
+ function utcTimeframeToLocal(value) {
313
+ if (value == null || value === '') {
314
+ return value ?? null;
315
+ }
316
+ const raw = String(value).trim();
317
+ const match = raw.match(TIMEFRAME_DATE_TIME);
318
+ if (!match) {
319
+ return raw;
320
+ }
321
+ const utcDate = new Date(Date.UTC(Number(match[1]), Number(match[2]) - 1, Number(match[3]), Number(match[4]), Number(match[5]), Number(match[6])));
322
+ if (isNaN(utcDate.getTime())) {
323
+ return raw;
324
+ }
325
+ return formatLocalDateTime(utcDate);
326
+ }
327
+ function toLocalDashboardTimeframe(timeframe) {
328
+ if (!timeframe || typeof timeframe !== 'object') {
329
+ return timeframe;
330
+ }
331
+ const source = timeframe;
332
+ const converted = { ...source };
333
+ ['from', 'to', 'start_date', 'end_date'].forEach((key) => {
334
+ if (converted[key] != null && converted[key] !== '') {
335
+ converted[key] = utcTimeframeToLocal(String(converted[key]));
336
+ }
337
+ });
338
+ return converted;
339
+ }
340
+ /** Converts `timeframe` (and nested `dashboard.timeframe`) on a dashboard API item. */
341
+ function applyLocalTimeframeToDashboard(dashboard) {
342
+ if (!dashboard || typeof dashboard !== 'object') {
343
+ return dashboard;
344
+ }
345
+ const item = dashboard;
346
+ const next = { ...item };
347
+ if (item['timeframe']) {
348
+ next['timeframe'] = toLocalDashboardTimeframe(item['timeframe']);
349
+ }
350
+ if (item['time_frame_from'] != null) {
351
+ next['time_frame_from'] = utcTimeframeToLocal(item['time_frame_from']);
352
+ }
353
+ if (item['time_frame_to'] != null) {
354
+ next['time_frame_to'] = utcTimeframeToLocal(item['time_frame_to']);
355
+ }
356
+ const nested = item['dashboard'];
357
+ if (nested && typeof nested === 'object' && nested !== dashboard) {
358
+ next['dashboard'] = applyLocalTimeframeToDashboard(nested);
359
+ }
360
+ return next;
361
+ }
362
+ /** Walks getCustomDashboards / customDashboard envelopes and localizes timeframe. */
363
+ function applyLocalTimeframeToDashboardResponse(res) {
364
+ if (!res || typeof res !== 'object') {
365
+ return res;
366
+ }
367
+ if (Array.isArray(res)) {
368
+ return res.map((item) => applyLocalTimeframeToDashboard(item));
369
+ }
370
+ const body = res;
371
+ let next = { ...body };
372
+ if (body['timeframe'] || body['time_frame_from'] || body['time_frame_to']) {
373
+ next = applyLocalTimeframeToDashboard(next);
374
+ }
375
+ if (Array.isArray(body['dashboards'])) {
376
+ next['dashboards'] = body['dashboards'].map((item) => applyLocalTimeframeToDashboard(item));
377
+ }
378
+ if (body['dashboard'] && typeof body['dashboard'] === 'object') {
379
+ next['dashboard'] = applyLocalTimeframeToDashboard(body['dashboard']);
380
+ }
381
+ if (body['data'] && typeof body['data'] === 'object') {
382
+ next['data'] = applyLocalTimeframeToDashboardResponse(body['data']);
383
+ }
384
+ return next;
385
+ }
386
+
299
387
  class Configurations {
300
388
  envConfig;
301
389
  constructor() {
@@ -414,37 +502,32 @@ class CreateDashboardService {
414
502
  }
415
503
  normalizeWidgetDetailsResponse(res) {
416
504
  const payload = res?.data ?? res;
417
- const widgetArr = payload?.widgetArr ?? res?.widgetArr;
418
- const allWidgetsArray = payload?.allWidgetsArray ?? res?.allWidgetsArray ?? widgetArr;
419
- if (widgetArr || allWidgetsArray) {
420
- const normalizedWidgetArr = Array.isArray(widgetArr) ? widgetArr : [];
421
- const normalizedAll = Array.isArray(allWidgetsArray)
422
- ? allWidgetsArray
423
- : normalizedWidgetArr;
424
- return {
425
- widgetArr: normalizedWidgetArr,
426
- allWidgetsArray: normalizedAll,
427
- activeWidgetArr: payload?.activeWidgetArr ??
428
- res?.activeWidgetArr ??
429
- normalizedWidgetArr,
430
- };
431
- }
432
- if (Array.isArray(res)) {
433
- return { widgetArr: res, allWidgetsArray: res, activeWidgetArr: res };
434
- }
435
- if (Array.isArray(res?.data)) {
436
- return {
437
- widgetArr: res.data,
438
- allWidgetsArray: res.data,
439
- activeWidgetArr: res.data,
440
- };
441
- }
442
- const legacyWidgets = res?.widget_details ?? res?.widgets ?? [];
443
- const legacyAll = res?.all_widgets ?? legacyWidgets;
505
+ const collect = (...candidates) => {
506
+ const collected = [];
507
+ const seen = new Set();
508
+ candidates.forEach((candidate) => {
509
+ if (!Array.isArray(candidate)) {
510
+ return;
511
+ }
512
+ candidate.forEach((widget) => {
513
+ const code = widget?.widget_code ?? widget?.widgetCode;
514
+ const key = code != null ? String(code) : JSON.stringify(widget);
515
+ if (seen.has(key)) {
516
+ return;
517
+ }
518
+ seen.add(key);
519
+ collected.push(widget);
520
+ });
521
+ });
522
+ return collected;
523
+ };
524
+ const widgetArr = collect(payload?.widgetArr, res?.widgetArr, payload?.widget_details, Array.isArray(payload) ? payload : null, Array.isArray(res?.data) ? res.data : null);
525
+ const allWidgetsArray = collect(payload?.allWidgetsArray, payload?.all_widgets, payload?.allWidgets, payload?.allWidgetArray, payload?.widgets, res?.allWidgetsArray, res?.all_widgets, res?.allWidgets, res?.widgets, widgetArr);
526
+ const activeWidgetArr = collect(payload?.activeWidgetArr, res?.activeWidgetArr, widgetArr);
444
527
  return {
445
- widgetArr: legacyWidgets,
446
- allWidgetsArray: legacyAll,
447
- activeWidgetArr: res?.activeWidgetArr ?? legacyWidgets,
528
+ widgetArr,
529
+ allWidgetsArray: allWidgetsArray.length ? allWidgetsArray : widgetArr,
530
+ activeWidgetArr: activeWidgetArr.length ? activeWidgetArr : widgetArr,
448
531
  };
449
532
  }
450
533
  getSailsProgramList() {
@@ -461,7 +544,7 @@ class CreateDashboardService {
461
544
  fetchCustomDashboardById(id) {
462
545
  return this.http
463
546
  .get(`${this.env.dashboard}customDashboard/${id}`, this.httpOptions)
464
- .pipe(retry(2));
547
+ .pipe(map((res) => applyLocalTimeframeToDashboardResponse(res)), retry(2));
465
548
  }
466
549
  getUserInformation() {
467
550
  return this.http
@@ -484,10 +567,14 @@ class CreateDashboardService {
484
567
  .pipe(retry(2));
485
568
  }
486
569
  createDashboard(payload) {
487
- return this.http.post(this.env.dashboard + 'customDashboard', payload, this.httpOptions);
570
+ return this.http
571
+ .post(this.env.dashboard + 'customDashboard', payload, this.httpOptions)
572
+ .pipe(map((res) => applyLocalTimeframeToDashboardResponse(res)));
488
573
  }
489
574
  updateDashboard(payload, id) {
490
- return this.http.put(this.env.dashboard + 'customDashboard/' + id, payload, this.httpOptions);
575
+ return this.http
576
+ .put(this.env.dashboard + 'customDashboard/' + id, payload, this.httpOptions)
577
+ .pipe(map((res) => applyLocalTimeframeToDashboardResponse(res)));
491
578
  }
492
579
  saveWidgetDetails(payload) {
493
580
  return this.http.post(this.env.dashboard + 'createWidgets/creator', payload, this.httpOptions);
@@ -1534,12 +1621,12 @@ class ConfigureWidgetsComponent {
1534
1621
  visibility: true,
1535
1622
  module: 'COMPLIANCE',
1536
1623
  subWidgets: [
1537
- {
1538
- title: 'Overview',
1539
- id: 'key_responsibilities_overview_flag',
1540
- value: false,
1541
- visibility: true,
1542
- },
1624
+ // {
1625
+ // title: 'Overview',
1626
+ // id: 'key_responsibilities_overview_flag',
1627
+ // value: false,
1628
+ // visibility: true,
1629
+ // },
1543
1630
  {
1544
1631
  title: 'My Responsibilities',
1545
1632
  id: 'key_my_responsibilities_flag',