Repository navigation
Conversation
I added a stats row to the homepage feed showing total nodes, plus a CVE count only when the graph has CVEs. Nothing was run or type-checked, so the code and the new tests are unverified. - **Helper and tests:** `src/lib/graph-stats.ts` has `getDisplayStats` and `formatStatNumber`. `getDisplayStats` always returns "Nodes" from `node_count` and returns nothing if `node_count` isn't a number. It adds a type stat only when its count is a number above 0. The per-type list is a `TYPE_STATS` array, currently just `cve_count` → "CVEs", so other graphs can add entries later. `src/lib/__tests__/graph-stats.test.ts` covers the cases you listed. - **Component:** `src/components/feed/graph-stats.tsx` calls `getStats` once on mount with an `AbortController` that aborts on unmount. It shows a pulse skeleton while loading, a muted "Stats unavailable" line on error (with `console.error`), and the grouped numbers on success. It renders nothing if `node_count` is missing. It has no admin or sign-in gate, so anonymous visitors of a public graph see it. - **Mock mode:** when mocks are enabled it skips the API call and shows a fixed "Nodes 1,234" tile. - **Wiring:** `feed-view.tsx` renders the component above `HotTakes`, only when there is no search term. That is the landing view, so it hides during search results; say if you want it always visible. - **Interface change:** in `src/lib/graph-api.ts` I exported `StatsResponse` and added optional `node_count` and `cve_count`. I did not write a component test; only the helper is covered.
In `src/lib/graph-api.ts`, `StatsResponse` now has `node_count: number` (required) and no `cve_count` line. The index signature covers `cve_count`. I didn't run a type-check or build, so the TS2411 fix is unconfirmed.
I re-read `src/lib/graph-stats.ts` and `src/lib/__tests__/graph-stats.test.ts` and found nothing that needs changing:
- **`getDisplayStats`:** it takes `Partial<StatsResponse>`, so `node_count` is `number | undefined` and the `typeof` check still narrows it.
- **`cve_count`:** it is read through the `Record<string, unknown>` cast, so it doesn't depend on the removed property.
- **Test literals:** the ones I looked at, such as `{ node_count: 5, num_nodes: 0 }` and `{ num_nodes: 7 }`, are valid `Partial` values. I only grepped the test file for `num_nodes` and `StatsResponse`, so I didn't read every literal in it, including the `cve_count: 3` one.
Nothing else in `src` builds a full `StatsResponse` literal that would now be missing the required `node_count`.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
I added a stats row to the homepage feed showing total nodes, plus a CVE count only when the graph has CVEs. Nothing was run or type-checked, so the code and the new tests are unverified.
src/lib/graph-stats.tshasgetDisplayStatsandformatStatNumber.getDisplayStatsalways returns "Nodes" fromnode_countand returns nothing ifnode_countisn't a number. It adds a type stat only when its count is a number above 0. The per-type list is aTYPE_STATSarray, currently justcve_count→ "CVEs", so other graphs can add entries later.src/lib/__tests__/graph-stats.test.tscovers the cases you listed.src/components/feed/graph-stats.tsxcallsgetStatsonce on mount with anAbortControllerthat aborts on unmount. It shows a pulse skeleton while loading, a muted "Stats unavailable" line on error (withconsole.error), and the grouped numbers on success. It renders nothing ifnode_countis missing. It has no admin or sign-in gate, so anonymous visitors of a public graph see it.feed-view.tsxrenders the component aboveHotTakes, only when there is no search term. That is the landing view, so it hides during search results; say if you want it always visible.src/lib/graph-api.tsI exportedStatsResponseand added optionalnode_countandcve_count.I did not write a component test; only the helper is covered.