-
Notifications
You must be signed in to change notification settings - Fork 121
Update Entities Visualizer #8783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yusufkinatas
wants to merge
15
commits into
main
Choose a base branch
from
yk/update-entities-visualizer-final
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
23840c5
Refactor entities visualizer: unified filter ribbon, header, and tablβ¦
yusufkinatas c907a20
adjust UI/UX
yusufkinatas 721b4ae
fix padding issue
yusufkinatas 426c3b4
cleanup
yusufkinatas 35ead7a
cleanup
yusufkinatas 1e2e7da
Refactor filter pill components: integrate FilterPill for Type and Weβ¦
yusufkinatas fa58d6e
cleanup
yusufkinatas 9830e1b
fix scroll issue
yusufkinatas 8628a27
remove now-working displayName usage
yusufkinatas bff34ce
fix test
yusufkinatas 7a2a2e2
use sx prop
yusufkinatas 6173ca7
cleanup
yusufkinatas 346ac94
simplify rendering conditions
yusufkinatas e044a45
cleanup
yusufkinatas c744e5a
cleanup styles
yusufkinatas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
407 changes: 178 additions & 229 deletions
407
apps/hash-frontend/src/pages/shared/entities-visualizer.tsx
Large diffs are not rendered by default.
Oops, something went wrong.
179 changes: 179 additions & 0 deletions
179
apps/hash-frontend/src/pages/shared/entities-visualizer/data/build-filter.ts
This file contains hidden or 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,179 @@ | ||
| import { ignoreNoisySystemTypesFilter } from "@local/hash-isomorphic-utils/graph-queries"; | ||
| import { systemPropertyTypes } from "@local/hash-isomorphic-utils/ontology-type-ids"; | ||
|
|
||
| import type { EntitiesFilterState } from "./types"; | ||
| import type { BaseUrl, VersionedUrl, WebId } from "@blockprotocol/type-system"; | ||
| import type { Filter } from "@local/hash-graph-client"; | ||
|
|
||
| const MATCH_NOTHING_WEB_ID = "00000000-0000-0000-0000-000000000000" as WebId; | ||
|
|
||
| const buildArchivedClauses = (includeArchived: boolean): Filter[] => { | ||
| if (includeArchived) { | ||
| return []; | ||
| } | ||
|
|
||
| return [ | ||
| { | ||
| notEqual: [{ path: ["archived"] }, { parameter: true }], | ||
| }, | ||
| { | ||
| any: [ | ||
| { | ||
| exists: { | ||
| path: [ | ||
| "properties", | ||
| systemPropertyTypes.archived.propertyTypeBaseUrl, | ||
| ], | ||
| }, | ||
| }, | ||
| { | ||
| equal: [ | ||
| { | ||
| path: [ | ||
| "properties", | ||
| systemPropertyTypes.archived.propertyTypeBaseUrl, | ||
| ], | ||
| }, | ||
| { parameter: false }, | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
| ]; | ||
| }; | ||
|
|
||
| const buildWebClause = ( | ||
| webState: EntitiesFilterState["web"], | ||
| internalWebIds: WebId[], | ||
| ): Filter | null => { | ||
| if (!webState.includeOtherWebs) { | ||
| const selected = internalWebIds.filter((id) => | ||
| webState.selectedInternalWebIds.has(id), | ||
| ); | ||
|
|
||
| const webIdsToMatch = selected.length ? selected : [MATCH_NOTHING_WEB_ID]; | ||
|
|
||
| return { | ||
| any: webIdsToMatch.map((webId) => ({ | ||
| equal: [{ path: ["webId"] }, { parameter: webId }], | ||
| })), | ||
| }; | ||
| } | ||
|
|
||
| const uncheckedInternalWebIds = internalWebIds.filter( | ||
| (id) => !webState.selectedInternalWebIds.has(id), | ||
| ); | ||
|
|
||
| if (uncheckedInternalWebIds.length === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| return { | ||
| all: uncheckedInternalWebIds.map((webId) => ({ | ||
| notEqual: [{ path: ["webId"] }, { parameter: webId }], | ||
| })), | ||
| }; | ||
| }; | ||
|
|
||
| const buildTypeClause = ({ | ||
| pinnedEntityTypeBaseUrl, | ||
| pinnedEntityTypeIds, | ||
| selectedTypeIds, | ||
| }: { | ||
| pinnedEntityTypeBaseUrl?: BaseUrl; | ||
| pinnedEntityTypeIds?: VersionedUrl[]; | ||
| selectedTypeIds: Set<VersionedUrl> | null; | ||
| }): { clause: Filter | null; isPinned: boolean } => { | ||
| if (pinnedEntityTypeBaseUrl) { | ||
| return { | ||
| clause: { | ||
| equal: [ | ||
| { path: ["type", "baseUrl"] }, | ||
| { parameter: pinnedEntityTypeBaseUrl }, | ||
| ], | ||
| }, | ||
| isPinned: true, | ||
| }; | ||
| } | ||
|
|
||
| if (pinnedEntityTypeIds?.length) { | ||
| return { | ||
| clause: { | ||
| any: pinnedEntityTypeIds.map((entityTypeId) => ({ | ||
| equal: [ | ||
| { path: ["type", "versionedUrl"] }, | ||
| { parameter: entityTypeId }, | ||
| ], | ||
| })), | ||
| }, | ||
| isPinned: true, | ||
| }; | ||
| } | ||
|
|
||
| if (selectedTypeIds === null) { | ||
| return { clause: null, isPinned: false }; | ||
| } | ||
|
|
||
| const typeIds = Array.from(selectedTypeIds); | ||
|
|
||
| if (typeIds.length === 0) { | ||
| return { | ||
| clause: { | ||
| equal: [{ path: ["type", "versionedUrl"] }, { parameter: "" }], | ||
| }, | ||
| isPinned: false, | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| clause: { | ||
| any: typeIds.map((entityTypeId) => ({ | ||
| equal: [ | ||
| { path: ["type", "versionedUrl"] }, | ||
| { parameter: entityTypeId }, | ||
| ], | ||
| })), | ||
| }, | ||
| isPinned: false, | ||
| }; | ||
| }; | ||
|
|
||
| export const buildEntitiesFilter = ({ | ||
| filterState, | ||
| internalWebIds, | ||
| pinnedEntityTypeBaseUrl, | ||
| pinnedEntityTypeIds, | ||
| }: { | ||
| filterState: EntitiesFilterState; | ||
| internalWebIds: WebId[]; | ||
| pinnedEntityTypeBaseUrl?: BaseUrl; | ||
| pinnedEntityTypeIds?: VersionedUrl[]; | ||
| }): Filter => { | ||
| const clauses: Filter[] = []; | ||
|
|
||
| clauses.push(...buildArchivedClauses(filterState.includeArchived)); | ||
|
|
||
| const webClause = buildWebClause(filterState.web, internalWebIds); | ||
| if (webClause) { | ||
| clauses.push(webClause); | ||
| } | ||
|
|
||
| const { clause: typeClause, isPinned: isTypePinned } = buildTypeClause({ | ||
| pinnedEntityTypeBaseUrl, | ||
| pinnedEntityTypeIds, | ||
| selectedTypeIds: filterState.type.selectedTypeIds, | ||
| }); | ||
|
|
||
| if (typeClause) { | ||
| clauses.push(typeClause); | ||
| } | ||
|
|
||
| const userPickedSpecificTypes = | ||
| !isTypePinned && filterState.type.selectedTypeIds !== null; | ||
|
|
||
| if (!isTypePinned && !userPickedSpecificTypes) { | ||
| clauses.push(ignoreNoisySystemTypesFilter); | ||
| } | ||
|
|
||
| return { all: clauses }; | ||
| }; |
34 changes: 34 additions & 0 deletions
34
apps/hash-frontend/src/pages/shared/entities-visualizer/data/traversal-paths.ts
This file contains hidden or 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,34 @@ | ||
| import type { VisualizerView } from "../../visualizer-views"; | ||
| import type { TraversalPath } from "@local/hash-graph-client"; | ||
|
|
||
| /** | ||
| * Graph view resolves links into and out of the displayed entities so link | ||
| * endpoints render even when the entity filter is narrow. | ||
| */ | ||
| const graphViewTraversalPaths: TraversalPath[] = [ | ||
| { | ||
| edges: [ | ||
| { kind: "has-left-entity", direction: "incoming" }, | ||
| { kind: "has-right-entity", direction: "outgoing" }, | ||
| ], | ||
| }, | ||
| ]; | ||
|
|
||
| /** | ||
| * Table / Grid views only need to resolve a link entity's own source and | ||
| * target endpoints. | ||
| */ | ||
| const tableViewTraversalPaths: TraversalPath[] = [ | ||
| { | ||
| edges: [ | ||
| { kind: "has-left-entity", direction: "outgoing" }, | ||
| { kind: "has-right-entity", direction: "outgoing" }, | ||
| ], | ||
| }, | ||
| ]; | ||
|
|
||
| export const traversalPathsForView = ( | ||
| view: VisualizerView, | ||
| ): TraversalPath[] => { | ||
| return view === "Graph" ? graphViewTraversalPaths : tableViewTraversalPaths; | ||
| }; | ||
23 changes: 23 additions & 0 deletions
23
apps/hash-frontend/src/pages/shared/entities-visualizer/data/types.ts
This file contains hidden or 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,23 @@ | ||
| import type { VersionedUrl, WebId } from "@blockprotocol/type-system"; | ||
|
|
||
| export type EntitiesFilterState = { | ||
| web: { | ||
| selectedInternalWebIds: Set<WebId>; | ||
| includeOtherWebs: boolean; | ||
| }; | ||
| type: { | ||
| selectedTypeIds: Set<VersionedUrl> | null; | ||
| }; | ||
| includeArchived: boolean; | ||
| }; | ||
|
|
||
| export const createDefaultFilterState = ( | ||
| internalWebIds: WebId[], | ||
| ): EntitiesFilterState => ({ | ||
| web: { | ||
| selectedInternalWebIds: new Set<WebId>(internalWebIds), | ||
| includeOtherWebs: false, | ||
| }, | ||
| type: { selectedTypeIds: null }, | ||
| includeArchived: false, | ||
| }); |
91 changes: 91 additions & 0 deletions
91
apps/hash-frontend/src/pages/shared/entities-visualizer/data/use-available-types.ts
This file contains hidden or 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,91 @@ | ||
| import { useQuery } from "@apollo/client"; | ||
| import { useMemo } from "react"; | ||
|
|
||
| import { currentTimeInstantTemporalAxes } from "@local/hash-isomorphic-utils/graph-queries"; | ||
|
|
||
| import { queryEntitySubgraphQuery } from "../../../../graphql/queries/knowledge/entity.queries"; | ||
| import { buildEntitiesFilter } from "./build-filter"; | ||
|
|
||
| import type { | ||
| QueryEntitySubgraphQuery, | ||
| QueryEntitySubgraphQueryVariables, | ||
| } from "../../../../graphql/api-types.gen"; | ||
| import type { EntitiesFilterState } from "./types"; | ||
| import type { BaseUrl, VersionedUrl, WebId } from "@blockprotocol/type-system"; | ||
|
|
||
| export type AvailableType = { | ||
| entityTypeId: VersionedUrl; | ||
| title: string; | ||
| count: number; | ||
| }; | ||
|
|
||
| export const useAvailableTypes = ({ | ||
| filterState, | ||
| internalWebIds, | ||
| entityTypeBaseUrl, | ||
| entityTypeIds, | ||
| }: { | ||
| filterState: EntitiesFilterState; | ||
| internalWebIds: WebId[]; | ||
| entityTypeBaseUrl?: BaseUrl; | ||
| entityTypeIds?: VersionedUrl[]; | ||
| }): { types: AvailableType[]; loading: boolean } => { | ||
| const skip = !!entityTypeBaseUrl || !!entityTypeIds?.length; | ||
|
|
||
| const filterStateWithoutType = useMemo<EntitiesFilterState>( | ||
| () => ({ | ||
| ...filterState, | ||
| type: { selectedTypeIds: null }, | ||
| }), | ||
| [filterState], | ||
| ); | ||
|
|
||
| const filter = useMemo( | ||
| () => | ||
| buildEntitiesFilter({ | ||
| filterState: filterStateWithoutType, | ||
| internalWebIds, | ||
| }), | ||
| [filterStateWithoutType, internalWebIds], | ||
| ); | ||
|
|
||
| const { data, loading } = useQuery< | ||
| QueryEntitySubgraphQuery, | ||
| QueryEntitySubgraphQueryVariables | ||
| >(queryEntitySubgraphQuery, { | ||
| skip, | ||
| fetchPolicy: "cache-and-network", | ||
| variables: { | ||
| request: { | ||
| limit: 1, | ||
| filter, | ||
| includeTypeIds: true, | ||
| includeTypeTitles: true, | ||
| temporalAxes: currentTimeInstantTemporalAxes, | ||
| includeDrafts: false, | ||
| includePermissions: false, | ||
| traversalPaths: [], | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| const types = useMemo<AvailableType[]>(() => { | ||
| if (skip || !data) { | ||
| return []; | ||
| } | ||
| const typeIds = data.queryEntitySubgraph.typeIds ?? {}; | ||
| const typeTitles = data.queryEntitySubgraph.typeTitles ?? {}; | ||
| return Object.entries(typeIds) | ||
| .map(([entityTypeId, count]) => { | ||
| const versionedUrl = entityTypeId as VersionedUrl; | ||
| return { | ||
| entityTypeId: versionedUrl, | ||
| title: typeTitles[versionedUrl] ?? entityTypeId, | ||
| count, | ||
| }; | ||
| }) | ||
| .sort((a, b) => a.title.localeCompare(b.title)); | ||
| }, [data, skip]); | ||
|
|
||
| return { types, loading: skip ? false : loading }; | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apps/hash-frontend/src/pages/shared/entities-visualizer/data/traversal-paths.ts:11 β The Graph traversal only follows
incoming has-left-entity -> outgoing has-right-entity, which seems to resolve links where the displayed entity is the left endpoint but not where itβs the right endpoint. That looks inconsistent with the comment about resolving links βinto and out ofβ displayed entities, and may cause some incoming links/endpoints to be missing in Graph view.Severity: medium
π€ Was this useful? React with π or π, or π if it prevented an incident/outage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CiaranMn this should be according to the requirements, right? Please resolve if so.