@localstack/appinspector-ui 1.0.0-dev-f55daae2 → 1.0.0-dev-c7a4c87a

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/index.js CHANGED
@@ -3417,7 +3417,7 @@ var SpansListPage = () => {
3417
3417
  );
3418
3418
  };
3419
3419
 
3420
- // src/pages/trace-graph.tsx
3420
+ // src/pages/trace-graph-page.tsx
3421
3421
  import { Box as Box12, Drawer, Paper as Paper2 } from "@mui/material";
3422
3422
  import { styled } from "@mui/material/styles";
3423
3423
  import { ReactFlowProvider } from "@xyflow/react";
@@ -3838,17 +3838,15 @@ var nodeTypes = {
3838
3838
  var TraceGraph = ({
3839
3839
  initialFocusEventId,
3840
3840
  onEventSelect,
3841
- traceId,
3841
+ onRefresh,
3842
+ spans,
3842
3843
  viewPortPixelWidth
3843
3844
  }) => {
3844
3845
  const [nodes, setNodes] = useState6([]);
3845
3846
  const [edges, setEdges] = useState6([]);
3846
- const [isLoading, setIsLoading] = useState6(true);
3847
3847
  const [initialViewSet, setInitialViewSet] = useState6(false);
3848
3848
  const { fitView, setCenter } = useReactFlow();
3849
3849
  const store = useStoreApi();
3850
- const api = useAppInspectorApi();
3851
- const [fetchError, setFetchError] = useState6();
3852
3850
  const updateSelectedNode = useCallback6(
3853
3851
  (nodeId) => {
3854
3852
  const { addSelectedNodes } = store.getState();
@@ -3861,57 +3859,40 @@ var TraceGraph = ({
3861
3859
  },
3862
3860
  [nodes, store]
3863
3861
  );
3864
- const fetchTrace = useCallback6(async () => {
3865
- setIsLoading(true);
3866
- try {
3867
- const response = await api.getSpans({ trace_id: traceId });
3868
- const spansMap = /* @__PURE__ */ new Map();
3869
- const rootSpans = [];
3870
- for (const span of response.spans) {
3871
- spansMap.set(span.span_id, { ...span, children: [] });
3872
- }
3873
- for (const span of response.spans) {
3874
- const currentSpan = spansMap.get(span.span_id);
3875
- if (!currentSpan) continue;
3876
- if (span.parent_span_id && spansMap.has(span.parent_span_id)) {
3877
- const parentSpan = spansMap.get(span.parent_span_id);
3878
- if (parentSpan) {
3879
- parentSpan.children ??= [];
3880
- parentSpan.children.push(currentSpan);
3881
- }
3882
- } else {
3883
- rootSpans.push(currentSpan);
3862
+ useEffect4(() => {
3863
+ const spansMap = /* @__PURE__ */ new Map();
3864
+ const rootSpans = [];
3865
+ for (const span of spans.data ?? []) {
3866
+ spansMap.set(span.span_id, { ...span, children: [] });
3867
+ }
3868
+ for (const span of spans.data ?? []) {
3869
+ const currentSpan = spansMap.get(span.span_id);
3870
+ if (!currentSpan) continue;
3871
+ if (span.parent_span_id && spansMap.has(span.parent_span_id)) {
3872
+ const parentSpan = spansMap.get(span.parent_span_id);
3873
+ if (parentSpan) {
3874
+ parentSpan.children ??= [];
3875
+ parentSpan.children.push(currentSpan);
3884
3876
  }
3877
+ } else {
3878
+ rootSpans.push(currentSpan);
3885
3879
  }
3886
- let allNodes = [];
3887
- let allEdges = [];
3888
- for (const rootSpan of rootSpans) {
3889
- const { edges: newEdges, nodes: newNodes } = generateNodesAndEdges(rootSpan, (event) => {
3890
- onEventSelect(event);
3891
- });
3892
- allNodes = [...allNodes, ...newNodes];
3893
- allEdges = [...allEdges, ...newEdges];
3894
- }
3895
- const { edges: layoutedEdges, nodes: layoutedNodes } = getLayoutedNodesAndEdges(allNodes, allEdges);
3896
- setNodes(layoutedNodes);
3897
- setEdges(layoutedEdges);
3898
- setIsLoading(false);
3899
- setFetchError(void 0);
3900
- } catch (error) {
3901
- console.error("Error fetching trace:", error);
3902
- setFetchError(error instanceof Error ? error : new Error("Unknown error", { cause: error }));
3903
- } finally {
3904
- setIsLoading(false);
3905
3880
  }
3906
- }, [api, traceId, onEventSelect]);
3907
- const fetchTraceSync = useCallback6(() => {
3908
- void fetchTrace();
3909
- }, [fetchTrace]);
3910
- useEffect4(() => {
3911
- fetchTraceSync();
3912
- }, [fetchTraceSync]);
3881
+ let allNodes = [];
3882
+ let allEdges = [];
3883
+ for (const rootSpan of rootSpans) {
3884
+ const { edges: newEdges, nodes: newNodes } = generateNodesAndEdges(rootSpan, (event) => {
3885
+ onEventSelect(event);
3886
+ });
3887
+ allNodes = [...allNodes, ...newNodes];
3888
+ allEdges = [...allEdges, ...newEdges];
3889
+ }
3890
+ const { edges: layoutedEdges, nodes: layoutedNodes } = getLayoutedNodesAndEdges(allNodes, allEdges);
3891
+ setNodes(layoutedNodes);
3892
+ setEdges(layoutedEdges);
3893
+ }, [onEventSelect, spans.data]);
3913
3894
  useEffect4(() => {
3914
- const shouldSetInitialView = !isLoading && nodes.length > 0 && !initialViewSet;
3895
+ const shouldSetInitialView = !spans.loading && nodes.length > 0 && !initialViewSet;
3915
3896
  if (shouldSetInitialView) {
3916
3897
  if (initialFocusEventId) {
3917
3898
  const focusNode = nodes.find((node) => node.id === initialFocusEventId);
@@ -3929,7 +3910,7 @@ var TraceGraph = ({
3929
3910
  }
3930
3911
  setInitialViewSet(true);
3931
3912
  }
3932
- }, [isLoading, nodes, initialFocusEventId, viewPortPixelWidth, setCenter, fitView, onEventSelect, initialViewSet]);
3913
+ }, [spans.loading, nodes, initialFocusEventId, viewPortPixelWidth, setCenter, fitView, onEventSelect, initialViewSet]);
3933
3914
  useEffect4(() => {
3934
3915
  if (initialFocusEventId) {
3935
3916
  updateSelectedNode(initialFocusEventId);
@@ -3940,15 +3921,17 @@ var TraceGraph = ({
3940
3921
  updateSelectedNode(node.id);
3941
3922
  }, [onEventSelect, updateSelectedNode]);
3942
3923
  return /* @__PURE__ */ jsxs127(Fragment3, { children: [
3943
- fetchError && /* @__PURE__ */ jsxs127(
3924
+ spans.error && /* @__PURE__ */ jsxs127(
3944
3925
  Alert3,
3945
3926
  {
3946
- action: /* @__PURE__ */ jsx134(Button4, { onClick: fetchTraceSync, children: "Retry" }),
3927
+ action: /* @__PURE__ */ jsx134(Button4, { onClick: () => {
3928
+ onRefresh();
3929
+ }, children: "Retry" }),
3947
3930
  severity: "error",
3948
3931
  children: [
3949
3932
  "Unexpected error:",
3950
3933
  " ",
3951
- fetchError.message
3934
+ spans.error.message
3952
3935
  ]
3953
3936
  }
3954
3937
  ),
@@ -3974,7 +3957,7 @@ var TraceGraph = ({
3974
3957
  ] });
3975
3958
  };
3976
3959
 
3977
- // src/pages/trace-graph.tsx
3960
+ // src/pages/trace-graph-page.tsx
3978
3961
  import { Fragment as Fragment4, jsx as jsx135, jsxs as jsxs128 } from "react/jsx-runtime";
3979
3962
  var HEADER_HEIGHT = 56;
3980
3963
  var DRAWER_WIDTH = "35%";
@@ -3995,7 +3978,6 @@ var Main = styled("main", { shouldForwardProp: (property) => property !== "open"
3995
3978
  }));
3996
3979
  var StyledDrawer = styled(Drawer)(() => ({
3997
3980
  "& .MuiDrawer-paper": {
3998
- backgroundColor: "#ffffff",
3999
3981
  bottom: 0,
4000
3982
  boxSizing: "border-box",
4001
3983
  height: `calc(100% - ${HEADER_HEIGHT.toString()}px)`,
@@ -4011,6 +3993,28 @@ var TraceGraphPage = () => {
4011
3993
  const { traceId } = useParams();
4012
3994
  const [searchParameters] = useSearchParams();
4013
3995
  const spanId = searchParameters.get("spanId");
3996
+ const api = useAppInspectorApi();
3997
+ const [spans, setSpans] = useState7();
3998
+ const [loading, setLoading] = useState7(false);
3999
+ const [fetchError, setFetchError] = useState7();
4000
+ const fetchSpans = useCallback7(async () => {
4001
+ setLoading(true);
4002
+ try {
4003
+ const response = await api.getSpans({
4004
+ trace_id: traceId
4005
+ });
4006
+ setSpans(response.spans);
4007
+ setFetchError(void 0);
4008
+ } catch (error) {
4009
+ console.error(error);
4010
+ setFetchError(error instanceof Error ? error : new Error("Unknown error", { cause: error }));
4011
+ } finally {
4012
+ setLoading(false);
4013
+ }
4014
+ }, [api, traceId]);
4015
+ useEffect5(() => {
4016
+ void fetchSpans();
4017
+ }, [fetchSpans]);
4014
4018
  const [open, setOpen] = useState7(true);
4015
4019
  const [selectedEvent, setSelectedEvent] = useState7();
4016
4020
  const [viewPortPixelWidth, setViewPortPixelWidth] = useState7(0);
@@ -4086,7 +4090,14 @@ var TraceGraphPage = () => {
4086
4090
  {
4087
4091
  initialFocusEventId: spanId,
4088
4092
  onEventSelect: handleEventSelect,
4089
- traceId,
4093
+ onRefresh: () => {
4094
+ void fetchSpans();
4095
+ },
4096
+ spans: {
4097
+ data: spans,
4098
+ error: fetchError,
4099
+ loading
4100
+ },
4090
4101
  viewPortPixelWidth
4091
4102
  }
4092
4103
  ) })