@opentrace/components 0.1.1-pr.118.26 → 0.1.1-pr.118.3

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.
@@ -7524,125 +7524,52 @@ const GraphCanvas = t.memo(
7524
7524
  )
7525
7525
  );
7526
7526
  function FilterPanel({
7527
- nodeTypes,
7528
- linkTypes,
7529
- hiddenNodeTypes,
7530
- hiddenLinkTypes,
7531
- subTypesByNodeType,
7532
- hiddenSubTypes,
7533
- onToggleNodeType,
7534
- onToggleLinkType,
7535
- onToggleSubType,
7536
- onShowAllNodes,
7537
- onHideAllNodes,
7538
- onShowAllLinks,
7539
- onHideAllLinks,
7540
- colorMode,
7541
- communities,
7542
- hiddenCommunities,
7543
- onToggleCommunity,
7544
- onShowAllCommunities,
7545
- onHideAllCommunities
7527
+ title,
7528
+ items,
7529
+ onToggle,
7530
+ onShowAll,
7531
+ onHideAll,
7532
+ indicator = "dot",
7533
+ emptyMessage
7546
7534
  }) {
7547
- const allLinksHidden = hiddenLinkTypes.size === linkTypes.length;
7548
- const [expandedTypes, setExpandedTypes] = t.useState(/* @__PURE__ */ new Set());
7549
- const toggleExpanded = (type) => {
7550
- setExpandedTypes((prev) => {
7535
+ const [expandedKeys, setExpandedKeys] = t.useState(/* @__PURE__ */ new Set());
7536
+ const toggleExpanded = (key) => {
7537
+ setExpandedKeys((prev) => {
7551
7538
  const next = new Set(prev);
7552
- if (next.has(type)) next.delete(type);
7553
- else next.add(type);
7539
+ if (next.has(key)) next.delete(key);
7540
+ else next.add(key);
7554
7541
  return next;
7555
7542
  });
7556
7543
  };
7557
- const getSubTypeState = t.useCallback(
7558
- (type, subs) => {
7559
- const keys = subs.map((s) => `${type}:${s.subType}`);
7560
- const hiddenCount = keys.filter((k) => hiddenSubTypes.has(k)).length;
7561
- if (hiddenCount === 0) return "all";
7562
- if (hiddenCount === keys.length) return "none";
7563
- return "some";
7564
- },
7565
- [hiddenSubTypes]
7566
- );
7567
- const allNodesHidden = nodeTypes.every(({ type }) => {
7568
- const subs = subTypesByNodeType.get(type);
7569
- if (subs && subs.length > 0) {
7570
- return getSubTypeState(type, subs) === "none";
7544
+ const allHidden = items.length > 0 && items.every((item) => {
7545
+ if (item.children && item.children.length > 0) {
7546
+ return item.children.every((c2) => c2.hidden);
7571
7547
  }
7572
- return hiddenNodeTypes.has(type);
7548
+ return item.hidden;
7573
7549
  });
7574
- const showCommunities = colorMode === "community" && communities && communities.length > 0 && hiddenCommunities && onToggleCommunity;
7575
- const allCommunitiesHidden = showCommunities && communities.every((c2) => hiddenCommunities.has(c2.communityId));
7576
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "filter-panel", children: [
7577
- showCommunities && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "filter-section", children: [
7578
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "filter-section-header", children: [
7579
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "filter-section-title", children: "Communities" }),
7580
- /* @__PURE__ */ jsxRuntime.jsx(
7581
- "button",
7582
- {
7583
- className: "filter-toggle-all",
7584
- onClick: allCommunitiesHidden ? onShowAllCommunities : onHideAllCommunities,
7585
- children: allCommunitiesHidden ? "Show all" : "Hide all"
7586
- }
7587
- )
7588
- ] }),
7589
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "filter-list", children: communities.map(({ communityId, label, count, color }) => {
7590
- const hidden = hiddenCommunities.has(communityId);
7591
- return /* @__PURE__ */ jsxRuntime.jsxs(
7592
- "label",
7593
- {
7594
- className: `filter-item ${hidden ? "hidden" : ""}`,
7595
- children: [
7596
- /* @__PURE__ */ jsxRuntime.jsx(
7597
- "input",
7598
- {
7599
- type: "checkbox",
7600
- checked: !hidden,
7601
- onChange: () => onToggleCommunity(communityId)
7602
- }
7603
- ),
7604
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "filter-expand-spacer" }),
7605
- /* @__PURE__ */ jsxRuntime.jsx(
7606
- "span",
7607
- {
7608
- className: "filter-dot",
7609
- style: {
7610
- backgroundColor: hidden ? "var(--muted)" : color
7611
- }
7612
- }
7613
- ),
7614
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "filter-type-name", children: label }),
7615
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "filter-count", children: count })
7616
- ]
7617
- },
7618
- communityId
7619
- );
7620
- }) })
7550
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "filter-section", children: [
7551
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "filter-section-header", children: [
7552
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "filter-section-title", children: title }),
7553
+ /* @__PURE__ */ jsxRuntime.jsx(
7554
+ "button",
7555
+ {
7556
+ className: "filter-toggle-all",
7557
+ onClick: allHidden ? onShowAll : onHideAll,
7558
+ children: allHidden ? "Show all" : "Hide all"
7559
+ }
7560
+ )
7621
7561
  ] }),
7622
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "filter-section", children: [
7623
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "filter-section-header", children: [
7624
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "filter-section-title", children: "Node Types" }),
7625
- /* @__PURE__ */ jsxRuntime.jsx(
7626
- "button",
7627
- {
7628
- className: "filter-toggle-all",
7629
- onClick: allNodesHidden ? onShowAllNodes : onHideAllNodes,
7630
- children: allNodesHidden ? "Show all" : "Hide all"
7631
- }
7632
- )
7633
- ] }),
7634
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "filter-list", children: nodeTypes.map(({ type, count }) => {
7635
- const subTypes = subTypesByNodeType.get(type);
7636
- const hasSubTypes = subTypes && subTypes.length > 0;
7637
- const isExpanded = expandedTypes.has(type);
7638
- let hidden;
7562
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "filter-list", children: [
7563
+ items.map((item) => {
7564
+ const hasChildren = item.children && item.children.length > 0;
7565
+ const isExpanded = expandedKeys.has(item.key);
7566
+ let hidden = item.hidden;
7639
7567
  let indeterminate = false;
7640
- if (hasSubTypes) {
7641
- const state = getSubTypeState(type, subTypes);
7642
- hidden = state === "none";
7643
- indeterminate = state === "some";
7644
- } else {
7645
- hidden = hiddenNodeTypes.has(type);
7568
+ if (hasChildren) {
7569
+ const hiddenCount = item.children.filter((c2) => c2.hidden).length;
7570
+ if (hiddenCount === item.children.length) hidden = true;
7571
+ else if (hiddenCount > 0) indeterminate = true;
7572
+ else hidden = false;
7646
7573
  }
7647
7574
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "filter-type-group", children: [
7648
7575
  /* @__PURE__ */ jsxRuntime.jsxs(
@@ -7658,17 +7585,17 @@ function FilterPanel({
7658
7585
  ref: (el) => {
7659
7586
  if (el) el.indeterminate = indeterminate;
7660
7587
  },
7661
- onChange: () => onToggleNodeType(type)
7588
+ onChange: () => onToggle(item.key)
7662
7589
  }
7663
7590
  ),
7664
- hasSubTypes ? /* @__PURE__ */ jsxRuntime.jsx(
7591
+ hasChildren ? /* @__PURE__ */ jsxRuntime.jsx(
7665
7592
  "button",
7666
7593
  {
7667
7594
  className: "filter-expand-btn",
7668
7595
  onClick: (e2) => {
7669
7596
  e2.preventDefault();
7670
7597
  e2.stopPropagation();
7671
- toggleExpanded(type);
7598
+ toggleExpanded(item.key);
7672
7599
  },
7673
7600
  title: isExpanded ? "Collapse" : "Expand sub-types",
7674
7601
  children: /* @__PURE__ */ jsxRuntime.jsx(
@@ -7691,111 +7618,67 @@ function FilterPanel({
7691
7618
  )
7692
7619
  }
7693
7620
  ) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "filter-expand-spacer" }),
7694
- /* @__PURE__ */ jsxRuntime.jsx(
7621
+ indicator === "line" ? /* @__PURE__ */ jsxRuntime.jsx(
7622
+ "span",
7623
+ {
7624
+ className: "filter-line",
7625
+ style: {
7626
+ backgroundColor: hidden ? "var(--muted)" : item.color
7627
+ }
7628
+ }
7629
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
7695
7630
  "span",
7696
7631
  {
7697
7632
  className: "filter-dot",
7698
7633
  style: {
7699
- backgroundColor: hidden ? "var(--muted)" : useHighlights.getNodeColor(type)
7634
+ backgroundColor: hidden ? "var(--muted)" : item.color
7700
7635
  }
7701
7636
  }
7702
7637
  ),
7703
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "filter-type-name", children: type }),
7704
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "filter-count", children: count })
7638
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "filter-type-name", children: item.label }),
7639
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "filter-count", children: item.count })
7705
7640
  ]
7706
7641
  }
7707
7642
  ),
7708
- hasSubTypes && isExpanded && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "filter-subtypes", children: subTypes.map(({ subType, count: subCount }) => {
7709
- const subKey = `${type}:${subType}`;
7710
- const subHidden = hiddenSubTypes.has(subKey);
7711
- return /* @__PURE__ */ jsxRuntime.jsxs(
7712
- "label",
7713
- {
7714
- className: `filter-item filter-subitem ${subHidden ? "hidden" : ""}`,
7715
- children: [
7716
- /* @__PURE__ */ jsxRuntime.jsx(
7717
- "input",
7718
- {
7719
- type: "checkbox",
7720
- checked: !subHidden,
7721
- onChange: () => onToggleSubType(subKey)
7722
- }
7723
- ),
7724
- /* @__PURE__ */ jsxRuntime.jsx(
7725
- "span",
7726
- {
7727
- className: "filter-dot filter-dot--small",
7728
- style: {
7729
- backgroundColor: subHidden ? "var(--muted)" : useHighlights.getNodeColor(type),
7730
- opacity: subHidden ? 1 : 0.7
7731
- }
7732
- }
7733
- ),
7734
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "filter-type-name", children: subType }),
7735
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "filter-count", children: subCount })
7736
- ]
7737
- },
7738
- subKey
7739
- );
7740
- }) })
7741
- ] }, type);
7742
- }) })
7743
- ] }),
7744
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "filter-section", children: [
7745
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "filter-section-header", children: [
7746
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "filter-section-title", children: "Edges" }),
7747
- /* @__PURE__ */ jsxRuntime.jsx(
7748
- "button",
7749
- {
7750
- className: "filter-toggle-all",
7751
- onClick: allLinksHidden ? onShowAllLinks : onHideAllLinks,
7752
- children: allLinksHidden ? "Show all" : "Hide all"
7753
- }
7754
- )
7755
- ] }),
7756
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "filter-list", children: [
7757
- linkTypes.map(({ type, count }) => {
7758
- const hidden = hiddenLinkTypes.has(type);
7759
- return /* @__PURE__ */ jsxRuntime.jsxs(
7643
+ hasChildren && isExpanded && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "filter-subtypes", children: item.children.map((child) => /* @__PURE__ */ jsxRuntime.jsxs(
7760
7644
  "label",
7761
7645
  {
7762
- className: `filter-item ${hidden ? "hidden" : ""}`,
7646
+ className: `filter-item filter-subitem ${child.hidden ? "hidden" : ""}`,
7763
7647
  children: [
7764
7648
  /* @__PURE__ */ jsxRuntime.jsx(
7765
7649
  "input",
7766
7650
  {
7767
7651
  type: "checkbox",
7768
- checked: !hidden,
7769
- onChange: () => onToggleLinkType(type)
7652
+ checked: !child.hidden,
7653
+ onChange: () => onToggle(child.key)
7770
7654
  }
7771
7655
  ),
7772
7656
  /* @__PURE__ */ jsxRuntime.jsx(
7773
7657
  "span",
7774
7658
  {
7775
- className: "filter-line",
7659
+ className: "filter-dot filter-dot--small",
7776
7660
  style: {
7777
- backgroundColor: hidden ? "var(--muted)" : useHighlights.getLinkColor(type)
7661
+ backgroundColor: child.hidden ? "var(--muted)" : child.color,
7662
+ opacity: child.hidden ? 1 : 0.7
7778
7663
  }
7779
7664
  }
7780
7665
  ),
7781
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "filter-type-name", children: type.toLowerCase() }),
7782
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "filter-count", children: count })
7666
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "filter-type-name", children: child.label }),
7667
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "filter-count", children: child.count })
7783
7668
  ]
7784
7669
  },
7785
- type
7786
- );
7787
- }),
7788
- linkTypes.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "filter-empty", children: "No edges" })
7789
- ] })
7670
+ child.key
7671
+ )) })
7672
+ ] }, item.key);
7673
+ }),
7674
+ items.length === 0 && emptyMessage && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "filter-empty", children: emptyMessage })
7790
7675
  ] })
7791
7676
  ] });
7792
7677
  }
7793
7678
  const DEFAULT_MAX_VISIBLE = 5;
7794
7679
  function GraphLegend({
7795
- colorMode,
7796
- legendItems,
7797
- communityLegendItems,
7798
- legendLinkItems,
7680
+ items,
7681
+ linkItems = [],
7799
7682
  maxVisible = DEFAULT_MAX_VISIBLE
7800
7683
  }) {
7801
7684
  const [showOverflow, setShowOverflow] = t.useState(false);
@@ -7810,41 +7693,15 @@ function GraphLegend({
7810
7693
  document.addEventListener("mousedown", handler);
7811
7694
  return () => document.removeEventListener("mousedown", handler);
7812
7695
  }, [showOverflow]);
7813
- const nodeItems = [];
7814
- if (colorMode === "community") {
7815
- for (const { label, count, color } of communityLegendItems) {
7816
- nodeItems.push({ key: `c:${label}`, label, count, color, shape: "dot" });
7817
- }
7818
- } else {
7819
- for (const { type, count, color } of legendItems) {
7820
- nodeItems.push({
7821
- key: `n:${type}`,
7822
- label: type,
7823
- count,
7824
- color,
7825
- shape: "dot"
7826
- });
7827
- }
7828
- }
7829
- const linkItems = [];
7830
- for (const { type, count, color } of legendLinkItems) {
7831
- linkItems.push({
7832
- key: `l:${type}`,
7833
- label: type,
7834
- count,
7835
- color,
7836
- shape: "line"
7837
- });
7838
- }
7839
- const visibleNodes = nodeItems.slice(0, maxVisible);
7840
- const overflowNodes = nodeItems.slice(maxVisible);
7696
+ const visibleItems = items.slice(0, maxVisible);
7697
+ const overflowItems = items.slice(maxVisible);
7841
7698
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "legend", ref: popoverRef, children: [
7842
- visibleNodes.map(({ key, label, count, color }) => /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "legend-item", title: label, children: [
7699
+ visibleItems.map(({ label, count, color }) => /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "legend-item", title: label, children: [
7843
7700
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "legend-dot", style: { backgroundColor: color } }),
7844
7701
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "legend-count", children: count }),
7845
7702
  label.length > 10 ? label.slice(0, 10) + "…" : label
7846
- ] }, key)),
7847
- overflowNodes.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
7703
+ ] }, label)),
7704
+ overflowItems.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
7848
7705
  /* @__PURE__ */ jsxRuntime.jsxs(
7849
7706
  "button",
7850
7707
  {
@@ -7852,12 +7709,12 @@ function GraphLegend({
7852
7709
  onClick: () => setShowOverflow((v2) => !v2),
7853
7710
  children: [
7854
7711
  "+",
7855
- overflowNodes.length,
7712
+ overflowItems.length,
7856
7713
  " more"
7857
7714
  ]
7858
7715
  }
7859
7716
  ),
7860
- showOverflow && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "legend-popover", children: nodeItems.map(({ key, label, count, color }) => /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "legend-item", children: [
7717
+ showOverflow && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "legend-popover", children: items.map(({ label, count, color }) => /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "legend-item", children: [
7861
7718
  /* @__PURE__ */ jsxRuntime.jsx(
7862
7719
  "span",
7863
7720
  {
@@ -7867,11 +7724,11 @@ function GraphLegend({
7867
7724
  ),
7868
7725
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "legend-count", children: count }),
7869
7726
  label
7870
- ] }, key)) })
7727
+ ] }, label)) })
7871
7728
  ] }),
7872
7729
  linkItems.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
7873
7730
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "legend-divider" }),
7874
- linkItems.map(({ key, label, count, color }) => /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "legend-item", children: [
7731
+ linkItems.map(({ label, count, color }) => /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "legend-item", children: [
7875
7732
  /* @__PURE__ */ jsxRuntime.jsx(
7876
7733
  "span",
7877
7734
  {
@@ -7881,7 +7738,7 @@ function GraphLegend({
7881
7738
  ),
7882
7739
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "legend-count", children: count }),
7883
7740
  label
7884
- ] }, key))
7741
+ ] }, label))
7885
7742
  ] })
7886
7743
  ] });
7887
7744
  }