-
Notifications
You must be signed in to change notification settings - Fork 1
refactor(frontend): readonly on graph cache/API types #1592
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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 |
|---|---|---|
| @@ -1,81 +1,88 @@ | ||
| /** | ||
| * Types for social network graph data | ||
| * | ||
| * These shapes are fetched once and cached in `GraphCacheService`, then read by | ||
| * multiple subscribers (graph components, the layout worker, the bubble | ||
| * renderer). `readonly` makes the shared-cache contract explicit at the type | ||
| * level: a stray in-place mutation (`.push`/`.sort`/field reassignment) on the | ||
| * cached instance would corrupt every consumer, so the compiler forbids it. | ||
| * Defensive copies (`[...nodes]`, `.map(...)`) are unaffected. | ||
| */ | ||
|
|
||
| export interface GraphNode { | ||
| id: number | ||
| name: string | ||
| grade: number | null | ||
| bunk_cm_id: number | null | ||
| centrality: number | ||
| clustering: number | ||
| community: number | null | ||
| satisfaction_status?: 'satisfied' | 'unsatisfied' | 'no_requests' | ||
| readonly id: number | ||
| readonly name: string | ||
| readonly grade: number | null | ||
| readonly bunk_cm_id: number | null | ||
| readonly centrality: number | ||
| readonly clustering: number | ||
| readonly community: number | null | ||
| readonly satisfaction_status?: 'satisfied' | 'unsatisfied' | 'no_requests' | ||
| // Stage 2 parent-paramount split. Both fields drive 3b's parent/staff edge | ||
| // filter checkbox; in 3a, only parent_satisfaction_status is rendered as the | ||
| // node border color. | ||
| parent_satisfaction_status?: 'satisfied' | 'unsatisfied' | 'no_requests' | ||
| staff_satisfaction_status?: 'satisfied' | 'unsatisfied' | 'no_requests' | ||
| readonly parent_satisfaction_status?: 'satisfied' | 'unsatisfied' | 'no_requests' | ||
| readonly staff_satisfaction_status?: 'satisfied' | 'unsatisfied' | 'no_requests' | ||
| // Legacy fields that may still be referenced | ||
| age?: number | ||
| sex?: string | ||
| degree_centrality?: number | ||
| betweenness_centrality?: number | ||
| isolated?: boolean | ||
| readonly age?: number | ||
| readonly sex?: string | ||
| readonly degree_centrality?: number | ||
| readonly betweenness_centrality?: number | ||
| readonly isolated?: boolean | ||
| } | ||
|
|
||
| export interface GraphEdge { | ||
| source: number | ||
| target: number | ||
| weight: number | ||
| readonly source: number | ||
| readonly target: number | ||
| readonly weight: number | ||
| /** Edge type. Always 'request' — the API only emits request edges. */ | ||
| edge_type: string | ||
| reciprocal: boolean | ||
| request_type?: string // 'bunk_with' | 'not_bunk_with' for edge_type='request' edges | ||
| confidence?: number // AI confidence score for request edges | ||
| metadata?: Record<string, unknown> // Additional edge metadata | ||
| readonly edge_type: string | ||
| readonly reciprocal: boolean | ||
| readonly request_type?: string // 'bunk_with' | 'not_bunk_with' for edge_type='request' edges | ||
| readonly confidence?: number // AI confidence score for request edges | ||
| readonly metadata?: Record<string, unknown> // Additional edge metadata | ||
| // Legacy fields that may still be referenced | ||
| is_reciprocal?: boolean | ||
| readonly is_reciprocal?: boolean | ||
| } | ||
|
|
||
| export interface GraphMetrics { | ||
| density: number | ||
| average_clustering: number | ||
| number_of_components: number | ||
| average_degree: number | ||
| [key: string]: number | ||
| readonly density: number | ||
| readonly average_clustering: number | ||
| readonly number_of_components: number | ||
| readonly average_degree: number | ||
| readonly [key: string]: number | ||
| } | ||
|
|
||
| /** Shape of a cross-scope edge as serialized by the Python CrossScopeEdge | ||
| * Pydantic model. Pydantic emits `null` for absent Optional fields (not | ||
| * `undefined`), so nullable required fields are typed `T | null`. */ | ||
| export interface CrossScopeEdge { | ||
| source: number | ||
| target: number | ||
| edge_type: string | ||
| weight: number | ||
| request_type: string | null | ||
| confidence: number | null | ||
| reciprocal: boolean | ||
| cross_scope: true | ||
| readonly source: number | ||
| readonly target: number | ||
| readonly edge_type: string | ||
| readonly weight: number | ||
| readonly request_type: string | null | ||
| readonly confidence: number | null | ||
| readonly reciprocal: boolean | ||
| readonly cross_scope: true | ||
| } | ||
|
|
||
| export interface GraphData { | ||
| nodes: GraphNode[] | ||
| edges: GraphEdge[] | ||
| metrics: GraphMetrics | ||
| readonly nodes: readonly GraphNode[] | ||
| readonly edges: readonly GraphEdge[] | ||
| readonly metrics: GraphMetrics | ||
| // Session-level only. The bunk-graph endpoint (BunkGraphResponse) does not | ||
| // emit this field, and the same GraphCacheService stores both shapes. | ||
| communities?: Record<number, number[]> | ||
| warnings?: string[] | ||
| layout_positions?: Record<number, [number, number]> | ||
| edge_type_counts?: Record<string, number> | ||
| readonly communities?: Record<number, readonly number[]> | ||
| readonly warnings?: readonly string[] | ||
| readonly layout_positions?: Record<number, readonly [number, number]> | ||
| readonly edge_type_counts?: Record<string, number> | ||
| /** Edges crossing the scope boundary when ?cross_scope=true. Frontend | ||
| * renders these as ghosted to show context without polluting the layout. | ||
| * Shape mirrors the Python CrossScopeEdge Pydantic model. */ | ||
| cross_scope_edges?: CrossScopeEdge[] | ||
| readonly cross_scope_edges?: readonly CrossScopeEdge[] | ||
| /** Out-of-scope endpoints of cross_scope_edges. Frontend renders these as | ||
| * ghosted-but-clickable nodes so users can click through to a potential | ||
| * connection, while the layout still treats the in-scope set as the focus. */ | ||
| cross_scope_nodes?: GraphNode[] | ||
| readonly cross_scope_nodes?: readonly GraphNode[] | ||
| } | ||
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.