@tuki-io/tuki-widgets 0.0.219-dev.58 → 0.0.219-dev.59

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.
@@ -293,20 +293,43 @@ function mergeDevices(a, b) {
293
293
  webexUUID: b.webexUUID ?? a.webexUUID,
294
294
  };
295
295
  }
296
- function mergeWorkspacesByDeviceName(workspaces) {
297
- const merged = new Map();
298
- for (const workspace of workspaces) {
299
- const key = withoutSep(workspace.device.name);
300
- const existing = merged.get(key);
301
- merged.set(key, existing ? {
302
- ...existing,
303
- ...workspace,
304
- device: mergeDevices(existing.device, workspace.device),
296
+ function toMacKey(value) {
297
+ return value ? withoutSep(value).replace(/[^0-9A-F]/g, '') : '';
298
+ }
299
+ function mergeCucmAndWebexWorkspaces(cucmWorkspaces, webexItems, webexWorkspaces) {
300
+ const result = [...cucmWorkspaces];
301
+ const cucmIndexByMac = new Map();
302
+ cucmWorkspaces.forEach((workspace, index) => {
303
+ const key = toMacKey(workspace.device.name);
304
+ if (key && !cucmIndexByMac.has(key)) {
305
+ cucmIndexByMac.set(key, index);
306
+ }
307
+ });
308
+ webexWorkspaces.forEach((webexWorkspace, webexIndex) => {
309
+ const matchedMac = (webexItems[webexIndex].workspaceDevices || [])
310
+ .map(workspaceDevice => toMacKey(workspaceDevice.mac))
311
+ .find(key => key && cucmIndexByMac.has(key));
312
+ if (!matchedMac) {
313
+ result.push(webexWorkspace);
314
+ return;
315
+ }
316
+ const cucmIndex = cucmIndexByMac.get(matchedMac);
317
+ cucmIndexByMac.delete(matchedMac);
318
+ const cucmWorkspace = result[cucmIndex];
319
+ result[cucmIndex] = {
320
+ ...cucmWorkspace,
321
+ ...webexWorkspace,
322
+ displayName: cucmWorkspace.displayName,
323
+ device: {
324
+ ...mergeDevices(cucmWorkspace.device, webexWorkspace.device),
325
+ name: cucmWorkspace.device.name,
326
+ newName: cucmWorkspace.device.newName,
327
+ },
305
328
  isHybrid: true,
306
- cucmDeviceName: existing.cucmDeviceName ?? workspace.cucmDeviceName,
307
- } : workspace);
308
- }
309
- return Array.from(merged.values());
329
+ cucmDeviceName: cucmWorkspace.cucmDeviceName,
330
+ };
331
+ });
332
+ return result;
310
333
  }
311
334
  const FETCH_ALL_SIZE = 9999;
312
335
  class WorkspacesService {
@@ -332,9 +355,10 @@ class WorkspacesService {
332
355
  return forkJoin([cucm$, webex$]).pipe(map(([cucmResponse, webexResponse]) => {
333
356
  const cucmParsed = parseResponse(cucmResponse);
334
357
  const webexParsed = parseResponse(webexResponse);
358
+ const webexItems = webexParsed?.pageData || [];
335
359
  const cucmWorkspaces = (cucmParsed?.pageData || []).map((item, index) => toWorkspace(item, index, true));
336
- const webexWorkspaces = (webexParsed?.pageData || []).map((item, index) => toWorkspace(item, index, false));
337
- const workspaces = mergeWorkspacesByDeviceName([...cucmWorkspaces, ...webexWorkspaces]);
360
+ const webexWorkspaces = webexItems.map((item, index) => toWorkspace(item, index, false));
361
+ const workspaces = mergeCucmAndWebexWorkspaces(cucmWorkspaces, webexItems, webexWorkspaces);
338
362
  return {
339
363
  workspaces,
340
364
  total: workspaces.length,