-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve node and edge filter options (#289)
- Loading branch information
Showing
18 changed files
with
462 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Jest current file", | ||
"skipFiles": ["<node_internals>/**"], | ||
"runtimeExecutable": "sh", | ||
"program": "${workspaceFolder}/node_modules/.bin/jest", | ||
"args": ["${relativeFile}", "--coverage=false"], | ||
"console": "integratedTerminal", | ||
"internalConsoleOptions": "openOnFirstSessionStart" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
packages/graph-explorer/src/core/StateProvider/filterCount.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { selector } from "recoil"; | ||
import { edgesTypesFilteredAtom } from "./edges"; | ||
import { nodesTypesFilteredAtom } from "./nodes"; | ||
|
||
/** | ||
* The count of filtered node and edge types | ||
*/ | ||
export const totalFilteredCount = selector({ | ||
key: "nodes-and-edges-filtered-count", | ||
get: ({ get }) => { | ||
// Get all the filtered entities | ||
const filteredNodeTypes = get(nodesTypesFilteredAtom); | ||
const filteredEdgeTypes = get(edgesTypesFilteredAtom); | ||
|
||
// Determine how many entity types are not checked | ||
return filteredNodeTypes.size + filteredEdgeTypes.size; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export * from "./ConfigurationProvider"; | ||
export * from "./ThemeProvider"; | ||
export * from "./ConnectedProvider"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
packages/graph-explorer/src/modules/EntitiesFilter/useFiltersConfig.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import { expect, jest } from "@jest/globals"; | ||
import { act, renderHook } from "@testing-library/react-hooks"; | ||
import useFiltersConfig from "./useFiltersConfig"; | ||
import { useTestSchema } from "../../utils/testing/useTestSchema"; | ||
import { createRandomSchema } from "../../utils/testing/randomData"; | ||
import { TestableRootProviders } from "../../utils/testing/TestableRootProviders"; | ||
import { sample, sortBy } from "lodash"; | ||
import { Schema } from "../../core"; | ||
|
||
jest.mock("localforage", () => ({ | ||
config: jest.fn(), | ||
getItem: jest.fn(), | ||
setItem: jest.fn(), | ||
})); | ||
|
||
/** Creates a config with the schema and makes it active, then renders the `useFiltersConfig` hook. */ | ||
function renderFilterConfigHook(schema: Schema) { | ||
return renderHook( | ||
() => { | ||
useTestSchema(schema); | ||
return useFiltersConfig(); | ||
}, | ||
{ | ||
wrapper: TestableRootProviders, | ||
} | ||
); | ||
} | ||
|
||
describe("useFiltersConfig", () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it("should have all entities selected", () => { | ||
const schema = createRandomSchema(); | ||
|
||
const { result } = renderFilterConfigHook(schema); | ||
|
||
expect(result.current.selectedVertexTypes).toEqual( | ||
new Set(schema.vertices.map(v => v.type)) | ||
); | ||
expect(result.current.selectedConnectionTypes).toEqual( | ||
new Set(schema.edges.map(v => v.type)) | ||
); | ||
}); | ||
|
||
it("should have all vertices in checkboxes", () => { | ||
const schema = createRandomSchema(); | ||
const expectedCheckboxIds = schema.vertices.map(v => v.type); | ||
|
||
const { result } = renderFilterConfigHook(schema); | ||
|
||
expect(result.current.vertexTypes.map(vt => vt.id)).toEqual( | ||
expect.arrayContaining(expectedCheckboxIds) | ||
); | ||
}); | ||
|
||
it("should sort vertex checkboxes alphabetically", () => { | ||
const schema = createRandomSchema(); | ||
|
||
const { result } = renderFilterConfigHook(schema); | ||
|
||
expect(result.current.vertexTypes).toEqual( | ||
sortBy(result.current.vertexTypes, vt => vt.text) | ||
); | ||
}); | ||
|
||
it("should have all edges in checkboxes", () => { | ||
const schema = createRandomSchema(); | ||
const expectedCheckboxIds = schema.edges.map(v => v.type); | ||
|
||
const { result } = renderFilterConfigHook(schema); | ||
|
||
expect(result.current.connectionTypes.map(vt => vt.id)).toEqual( | ||
expect.arrayContaining(expectedCheckboxIds) | ||
); | ||
}); | ||
|
||
it("should sort edge checkboxes alphabetically", () => { | ||
const schema = createRandomSchema(); | ||
|
||
const { result } = renderFilterConfigHook(schema); | ||
|
||
expect(result.current.connectionTypes).toEqual( | ||
sortBy(result.current.connectionTypes, vt => vt.text) | ||
); | ||
}); | ||
|
||
it("should unselect vertex when toggled", () => { | ||
const schema = createRandomSchema(); | ||
const changingVertex = sample(schema.vertices)!; | ||
|
||
const { result } = renderFilterConfigHook(schema); | ||
|
||
// Ensure vertex is selected initially | ||
expect(result.current.selectedVertexTypes.has(changingVertex.type)).toEqual( | ||
true | ||
); | ||
|
||
// Deselect vertex | ||
act(() => { | ||
result.current.onChangeVertexTypes(changingVertex.type, false); | ||
}); | ||
|
||
// Ensure vertex is no longer selected | ||
expect(result.current.selectedVertexTypes.has(changingVertex.type)).toEqual( | ||
false | ||
); | ||
}); | ||
|
||
it("should unselect edge when toggled", () => { | ||
const schema = createRandomSchema(); | ||
const changingEdge = sample(schema.edges)!; | ||
|
||
const { result } = renderFilterConfigHook(schema); | ||
|
||
// Ensure edge is selected initially | ||
expect( | ||
result.current.selectedConnectionTypes.has(changingEdge.type) | ||
).toEqual(true); | ||
|
||
// Deselect edge | ||
act(() => { | ||
result.current.onChangeConnectionTypes(changingEdge.type, false); | ||
}); | ||
|
||
// Ensure edge is no longer selected | ||
expect( | ||
result.current.selectedConnectionTypes.has(changingEdge.type) | ||
).toEqual(false); | ||
}); | ||
}); |
Oops, something went wrong.