Skip to content

Commit af22b93

Browse files
authored
Remove all Recoil references (#920)
* Rename to renderHookWithJotai * Remove usage of recoilDiffSets * Remove recoilDiffSets * Update changelog
1 parent 8fbfc9a commit af22b93

25 files changed

+137
-138
lines changed

Changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
- **Removed** Recoil state debugging tool that was never used
1414
([#909](https://github.com/aws/graph-explorer/pull/909))
1515
- **Updated** the state management layer to use Jotai instead of Recoil
16-
([#896](https://github.com/aws/graph-explorer/pull/896))
16+
([#896](https://github.com/aws/graph-explorer/pull/896),
17+
[#920](https://github.com/aws/graph-explorer/pull/920))
1718
- **Updated** to use the React Compiler to improve performance and simplify code
1819
([#916](https://github.com/aws/graph-explorer/pull/916))
1920
- **Fixed** issue where a schema sync would not automatically run when a

packages/graph-explorer/src/core/StateProvider/displayEdge.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
createRandomSchema,
77
createRandomVertex,
88
JotaiSnapshot,
9-
renderHookWithRecoilRoot,
9+
renderHookWithJotai,
1010
} from "@/utils/testing";
1111
import { DisplayEdge, useDisplayEdgeFromEdge } from "./displayEdge";
1212
import { formatDate, sanitizeText } from "@/utils";
@@ -230,7 +230,7 @@ describe("useDisplayEdgeFromEdge", () => {
230230
edge: Edge,
231231
initializeState?: (mutableSnapshot: JotaiSnapshot) => void
232232
) {
233-
const { result } = renderHookWithRecoilRoot(
233+
const { result } = renderHookWithJotai(
234234
() => useDisplayEdgeFromEdge(edge),
235235
initializeState
236236
);

packages/graph-explorer/src/core/StateProvider/displayTypeConfigs.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
createRandomSchema,
55
createRandomVertexTypeConfig,
66
JotaiSnapshot,
7-
renderHookWithRecoilRoot,
7+
renderHookWithJotai,
88
} from "@/utils/testing";
99
import {
1010
activeConfigurationAtom,
@@ -110,7 +110,7 @@ describe("useDisplayVertexTypeConfig", () => {
110110
// Helpers
111111

112112
function act(vertexConfigType: string, schema?: Schema) {
113-
const { result } = renderHookWithRecoilRoot(
113+
const { result } = renderHookWithJotai(
114114
() => useDisplayVertexTypeConfig(vertexConfigType),
115115
schema ? withSchema(schema) : undefined
116116
);
@@ -188,7 +188,7 @@ describe("useDisplayEdgeTypeConfig", () => {
188188
// Helpers
189189

190190
function act(edgeConfigType: string, schema?: Schema) {
191-
const { result } = renderHookWithRecoilRoot(
191+
const { result } = renderHookWithJotai(
192192
() => useDisplayEdgeTypeConfig(edgeConfigType),
193193
schema ? withSchema(schema) : undefined
194194
);

packages/graph-explorer/src/core/StateProvider/displayVertex.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
createRandomVertex,
55
createRandomVertexTypeConfig,
66
JotaiSnapshot,
7-
renderHookWithRecoilRoot,
7+
renderHookWithJotai,
88
} from "@/utils/testing";
99
import {
1010
createVertexId,
@@ -241,7 +241,7 @@ describe("useDisplayVertexFromVertex", () => {
241241
vertex: Vertex,
242242
initializeState?: (mutableSnapshot: JotaiSnapshot) => void
243243
) {
244-
const { result } = renderHookWithRecoilRoot(
244+
const { result } = renderHookWithJotai(
245245
() => useDisplayVertexFromVertex(vertex),
246246
initializeState
247247
);

packages/graph-explorer/src/core/StateProvider/edges.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { atom } from "jotai";
1+
import { atom, useSetAtom } from "jotai";
22
import { atomFamily, atomWithReset, RESET } from "jotai/utils";
33
import {
44
createRenderedEdgeId,
@@ -57,6 +57,22 @@ export const edgesOutOfFocusRenderedIdsAtom = atom(
5757
export const edgesFilteredIdsAtom = atomWithReset(new Set<EdgeId>());
5858
export const edgesTypesFilteredAtom = atomWithReset(new Set<string>());
5959

60+
const toggleFilteredEdgeAtom = atom(null, (_get, set, edgeId: EdgeId) => {
61+
set(edgesFilteredIdsAtom, prev => {
62+
const newSet = new Set(prev);
63+
if (prev.has(edgeId)) {
64+
newSet.delete(edgeId);
65+
} else {
66+
newSet.add(edgeId);
67+
}
68+
return newSet;
69+
});
70+
});
71+
72+
export function useToggleFilteredEdge() {
73+
return useSetAtom(toggleFilteredEdgeAtom);
74+
}
75+
6076
/**
6177
* Filters the edges added to the graph by:
6278
*

packages/graph-explorer/src/core/StateProvider/neighbors.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { calculateNeighbors, useNeighbors } from "./neighbors";
33
import {
44
createRandomVertex,
55
DbState,
6-
renderHookWithRecoilRoot,
6+
renderHookWithJotai,
77
} from "@/utils/testing";
88
import { explorerForTestingAtom } from "../connector";
99
import { createMockExplorer } from "@/utils/testing/createMockExplorer";
@@ -50,7 +50,7 @@ describe("useNeighbors", () => {
5050
const vertex = createRandomVertex();
5151
const explorer = createMockExplorer();
5252

53-
const { result } = renderHookWithRecoilRoot(
53+
const { result } = renderHookWithJotai(
5454
() => useNeighbors(vertex.id),
5555
snapshot => {
5656
dbState.applyTo(snapshot);
@@ -78,7 +78,7 @@ describe("useNeighbors", () => {
7878
};
7979
vi.mocked(explorer.fetchNeighborsCount).mockResolvedValueOnce(response);
8080

81-
const { result } = renderHookWithRecoilRoot(
81+
const { result } = renderHookWithJotai(
8282
() => useNeighbors(vertex.id),
8383
snapshot => {
8484
dbState.applyTo(snapshot);

packages/graph-explorer/src/core/StateProvider/nodes.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { atom, useAtomValue } from "jotai";
1+
import { atom, useAtomValue, useSetAtom } from "jotai";
22
import { atomFamily, atomWithReset, RESET } from "jotai/utils";
33
import {
44
createRenderedVertexId,
@@ -57,6 +57,22 @@ export const nodesOutOfFocusRenderedIdsAtom = atom(
5757
export const nodesFilteredIdsAtom = atomWithReset(new Set<VertexId>());
5858
export const nodesTypesFilteredAtom = atomWithReset(new Set<string>());
5959

60+
const toggleFilteredNodeAtom = atom(null, (_get, set, vertexId: VertexId) => {
61+
set(nodesFilteredIdsAtom, prev => {
62+
const newSet = new Set(prev);
63+
if (prev.has(vertexId)) {
64+
newSet.delete(vertexId);
65+
} else {
66+
newSet.add(vertexId);
67+
}
68+
return newSet;
69+
});
70+
});
71+
72+
export function useToggleFilteredNode() {
73+
return useSetAtom(toggleFilteredNodeAtom);
74+
}
75+
6076
/**
6177
* Filters the nodes added to the graph by:
6278
*

packages/graph-explorer/src/core/renderedEntities.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
createRandomEdge,
33
createRandomVertex,
44
DbState,
5-
renderHookWithRecoilRoot,
5+
renderHookWithJotai,
66
} from "@/utils/testing";
77
import { createEdgeId, createVertexId } from "./entityIdType";
88
import {
@@ -95,7 +95,7 @@ describe("useRenderedVertices", () => {
9595
createRenderedVertexId(dbState.vertices[2].id),
9696
];
9797

98-
const { result } = renderHookWithRecoilRoot(
98+
const { result } = renderHookWithJotai(
9999
() => useRenderedEntities(),
100100
snapshot => dbState.applyTo(snapshot)
101101
);
@@ -121,7 +121,7 @@ describe("useRenderedVertices", () => {
121121
createRenderedVertexId(dbState.vertices[2].id),
122122
];
123123

124-
const { result } = renderHookWithRecoilRoot(
124+
const { result } = renderHookWithJotai(
125125
() => useRenderedEntities(),
126126
snapshot => dbState.applyTo(snapshot)
127127
);
@@ -162,7 +162,7 @@ describe("useRenderedEdges", () => {
162162
createRenderedEdgeId(dbState.edges[3].id),
163163
];
164164

165-
const { result } = renderHookWithRecoilRoot(
165+
const { result } = renderHookWithJotai(
166166
() => useRenderedEntities(),
167167
snapshot => dbState.applyTo(snapshot)
168168
);
@@ -202,7 +202,7 @@ describe("useRenderedEdges", () => {
202202
createRenderedEdgeId(dbState.edges[3].id),
203203
];
204204

205-
const { result } = renderHookWithRecoilRoot(
205+
const { result } = renderHookWithJotai(
206206
() => useRenderedEntities(),
207207
snapshot => dbState.applyTo(snapshot)
208208
);
@@ -240,7 +240,7 @@ describe("useRenderedEdges", () => {
240240
createRenderedEdgeId(dbState.edges[3].id),
241241
];
242242

243-
const { result } = renderHookWithRecoilRoot(
243+
const { result } = renderHookWithJotai(
244244
() => useRenderedEntities(),
245245
snapshot => dbState.applyTo(snapshot)
246246
);
@@ -276,7 +276,7 @@ describe("useRenderedEdges", () => {
276276
createRenderedEdgeId(dbState.edges[1].id),
277277
];
278278

279-
const { result } = renderHookWithRecoilRoot(
279+
const { result } = renderHookWithJotai(
280280
() => useRenderedEntities(),
281281
snapshot => dbState.applyTo(snapshot)
282282
);

packages/graph-explorer/src/hooks/useAddToGraph.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
createRandomVertex,
55
createRandomVertexForRdf,
66
DbState,
7-
renderHookWithRecoilRoot,
7+
renderHookWithJotai,
88
} from "@/utils/testing";
99
import { useAddToGraph } from "./useAddToGraph";
1010
import { act } from "react";
@@ -39,7 +39,7 @@ test("should add one node", async () => {
3939
Promise.resolve(toNodeMap([vertex]))
4040
);
4141

42-
const { result } = renderHookWithRecoilRoot(() => {
42+
const { result } = renderHookWithJotai(() => {
4343
const callback = useAddToGraph();
4444
const vertices = useAtomValue(nodesAtom);
4545
const edges = useAtomValue(edgesAtom);
@@ -65,7 +65,7 @@ test("should materialize fragment vertices", async () => {
6565
Promise.resolve(toNodeMap([clonedVertex]))
6666
);
6767

68-
const { result } = renderHookWithRecoilRoot(() => {
68+
const { result } = renderHookWithJotai(() => {
6969
const callback = useAddToGraph();
7070
const vertices = useAtomValue(nodesAtom);
7171
const edges = useAtomValue(edgesAtom);
@@ -90,7 +90,7 @@ test("should add one edge", async () => {
9090
Promise.resolve(toNodeMap([node1, node2]))
9191
);
9292

93-
const { result } = renderHookWithRecoilRoot(
93+
const { result } = renderHookWithJotai(
9494
() => {
9595
const callback = useAddToGraph();
9696
const vertices = useAtomValue(nodesAtom);
@@ -118,7 +118,7 @@ test("should add multiple nodes and edges", async () => {
118118
Promise.resolve(randomEntities.nodes)
119119
);
120120

121-
const { result } = renderHookWithRecoilRoot(() => {
121+
const { result } = renderHookWithJotai(() => {
122122
const callback = useAddToGraph();
123123
const vertices = useAtomValue(nodesAtom);
124124
const edges = useAtomValue(edgesAtom);
@@ -153,7 +153,7 @@ test("should update schema when adding a node", async () => {
153153
Promise.resolve(toNodeMap([vertex]))
154154
);
155155

156-
const { result } = renderHookWithRecoilRoot(
156+
const { result } = renderHookWithJotai(
157157
() => {
158158
const callback = useAddToGraph();
159159
const vertices = useAtomValue(nodesAtom);
@@ -186,7 +186,7 @@ test("should update schema when adding a node with no label", async () => {
186186
Promise.resolve(toNodeMap([vertex]))
187187
);
188188

189-
const { result } = renderHookWithRecoilRoot(
189+
const { result } = renderHookWithJotai(
190190
() => {
191191
const callback = useAddToGraph();
192192
const vertices = useAtomValue(nodesAtom);
@@ -221,7 +221,7 @@ test("should update schema when adding an edge", async () => {
221221
Promise.resolve(toNodeMap([node1, node2]))
222222
);
223223

224-
const { result } = renderHookWithRecoilRoot(
224+
const { result } = renderHookWithJotai(
225225
() => {
226226
const callback = useAddToGraph();
227227
const vertices = useAtomValue(nodesAtom);
@@ -259,7 +259,7 @@ test("should add missing attributes to the schema when adding a node", async ()
259259
Promise.resolve(toNodeMap([vertex]))
260260
);
261261

262-
const { result } = renderHookWithRecoilRoot(
262+
const { result } = renderHookWithJotai(
263263
() => {
264264
const callback = useAddToGraph();
265265
const vertices = useAtomValue(nodesAtom);
@@ -301,7 +301,7 @@ test("should add missing attributes to the schema when adding an edge", async ()
301301
Promise.resolve(toNodeMap([node1, node2]))
302302
);
303303

304-
const { result } = renderHookWithRecoilRoot(
304+
const { result } = renderHookWithJotai(
305305
() => {
306306
const callback = useAddToGraph();
307307
const vertices = useAtomValue(nodesAtom);
@@ -331,7 +331,7 @@ test("should update graph storage when adding a node", async () => {
331331
Promise.resolve(toNodeMap([vertex]))
332332
);
333333

334-
const { result } = renderHookWithRecoilRoot(
334+
const { result } = renderHookWithJotai(
335335
() => {
336336
const callback = useAddToGraph();
337337
const graph = useAtomValue(activeGraphSessionAtom);
@@ -365,7 +365,7 @@ test("should update graph storage when adding an edge", async () => {
365365
Promise.resolve(toNodeMap([node1, node2]))
366366
);
367367

368-
const { result } = renderHookWithRecoilRoot(
368+
const { result } = renderHookWithJotai(
369369
() => {
370370
const callback = useAddToGraph();
371371
const graph = useAtomValue(activeGraphSessionAtom);
@@ -398,7 +398,7 @@ test("should ignore blank nodes when updating graph storage", async () => {
398398
Promise.resolve(toNodeMap([vertex, blankNode]))
399399
);
400400

401-
const { result } = renderHookWithRecoilRoot(
401+
const { result } = renderHookWithJotai(
402402
() => {
403403
const callback = useAddToGraph();
404404
const graph = useAtomValue(activeGraphSessionAtom);

packages/graph-explorer/src/hooks/useDeleteConfig.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
createRandomSchema,
1010
createRandomVertex,
1111
DbState,
12-
renderHookWithRecoilRoot,
12+
renderHookWithJotai,
1313
} from "@/utils/testing";
1414
import { waitFor } from "@testing-library/react";
1515
import { act } from "react";
@@ -19,7 +19,7 @@ import { useAtomValue } from "jotai";
1919
test("should delete the active configuration", async () => {
2020
const config1 = createRandomRawConfiguration();
2121

22-
const { result } = renderHookWithRecoilRoot(
22+
const { result } = renderHookWithJotai(
2323
() => {
2424
const callback = useDeleteActiveConfiguration();
2525
const allConfigs = useAtomValue(configurationAtom);
@@ -45,7 +45,7 @@ test("should delete the active schema", async () => {
4545
const config1 = createRandomRawConfiguration();
4646
const schema1 = createRandomSchema();
4747

48-
const { result } = renderHookWithRecoilRoot(
48+
const { result } = renderHookWithJotai(
4949
() => {
5050
const callback = useDeleteActiveConfiguration();
5151
const allSchemas = useAtomValue(schemaAtom);
@@ -70,7 +70,7 @@ test("should delete the graph session for the active connection", async () => {
7070
const dbState = new DbState();
7171
dbState.addVertexToGraph(createRandomVertex());
7272

73-
const { result } = renderHookWithRecoilRoot(
73+
const { result } = renderHookWithJotai(
7474
() => {
7575
const callback = useDeleteActiveConfiguration();
7676
const allGraphs = useAtomValue(allGraphSessionsAtom);

0 commit comments

Comments
 (0)