Skip to content

Conversation

@mdconn
Copy link
Collaborator

@mdconn mdconn commented May 15, 2025

Summary by CodeRabbit

  • New Features

    • Introduced an interactive bar chart visualization for search results, allowing users to aggregate and view data by payer, recipient, province, or country.
    • Added a category selector to switch chart attributes dynamically.
    • Implemented loading indicators for both search results and chart visualization.
  • Enhancements

    • Search results table now supports scrollable content for improved usability with large result sets.
    • Pagination and sorting behavior refined for a smoother user experience.

@vercel
Copy link

vercel bot commented May 15, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
canada-spends ❌ Failed (Inspect) May 18, 2025 6:21pm

@coderabbitai
Copy link

coderabbitai bot commented May 15, 2025

Walkthrough

A new interactive bar chart component was introduced to visualize aggregated search results by selectable attributes. The search interface was updated to support this chart, including new state management, aggregation logic, and loading feedback. The results table now supports an onDataUpdate callback and a scrollable layout. A dependency was removed from the package configuration.

Changes

File(s) Change Summary
website/package.json Removed the react-instantsearch-hooks-web dependency.
website/src/components/FacetBarChart.tsx Added a new FacetBarChart React component for displaying a selectable, interactive bar chart of aggregated data with loading and empty states. Introduced related type definitions.
website/src/components/ResultsTable.tsx Updated ResultsTable to accept an optional onDataUpdate callback for reporting data changes. Modified table layout to be scrollable with a fixed maximum height.
website/src/components/Search.tsx Integrated the new chart into the search UI. Added state for chart data and attribute selection, aggregation logic, loading feedback, and updated result table handling. Refactored Typesense configuration and improved pagination and filter handling.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SearchControls
    participant ResultsTable
    participant FacetBarChart

    User->>SearchControls: Enters query or changes filters
    SearchControls->>ResultsTable: Renders with onDataUpdate callback
    ResultsTable-->>SearchControls: Calls onDataUpdate with new hits
    SearchControls->>SearchControls: Aggregates hits into chart data
    SearchControls->>FacetBarChart: Renders with aggregated data and selected attribute
    User->>FacetBarChart: Changes chart attribute
    FacetBarChart-->>SearchControls: setChartAttribute callback
    SearchControls->>FacetBarChart: Updates with new aggregation
Loading

Poem

In the garden of code, a new chart has bloomed,
Bars rise and fall, by filters consumed.
Data now dances in colors and light,
Scrollable tables keep results in sight.
With loading spinners and numbers so neat,
This bunny hops on—aggregation complete!
🐇📊✨

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 436fc8d and 8ebc306.

📒 Files selected for processing (2)
  • website/package.json (0 hunks)
  • website/src/components/ResultsTable.tsx (3 hunks)
💤 Files with no reviewable changes (1)
  • website/package.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • website/src/components/ResultsTable.tsx
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (1)
website/src/components/Search.tsx (1)

49-51: Duplicate ChartableAttribute union

See earlier note in FacetBarChart.tsx; import the shared type instead of redefining it here.

🧹 Nitpick comments (7)
website/src/app/[lang]/layout.tsx (1)

71-75: Avoid combining async and defer – one of them is ignored

When both attributes are present, browsers treat the script as async, making defer redundant.
Removing the extra attribute avoids confusion and keeps the markup tidy.

-<script async defer src="https://scripts.simpleanalyticscdn.com/latest.js"></script>
+<script async src="https://scripts.simpleanalyticscdn.com/latest.js"></script>
website/src/components/ResultsTable.tsx (2)

22-28: Prevent unnecessary re-renders when propagating hit data

useHits returns a new array instance on every search event, so the effect fires even when the underlying list hasn’t semantically changed, causing the parent component (chart) to re-render more often than needed.

Consider memoising the payload you send upstream (e.g. by comparing hits.map(h => h.objectID).join() or using fast-deep-equal) or throttling updates.

-useEffect(() => {
-  if (onDataUpdate) {
-    onDataUpdate(hits);
-  }
-}, [hits, onDataUpdate]);
+useEffect(() => {
+  if (!onDataUpdate) return;
+  const ids = hits.map(h => h.objectID).join(',');
+  onDataUpdate(hits);
+  // eslint-disable-next-line react-hooks/exhaustive-deps
+}, [ids]);           // fires only when the actual set of hits changes

31-44: Dual scroll containers can break Table semantics

You wrap <Table> in a scrolling <div> and give <TableBody> its own scroll/overflow styles.
This often results in two nested scrollbars or the header scrolling away on some browsers.

If vertical scrolling is desired, keep it on the wrapper only:

-<div className="max-h-[400px] overflow-y-auto">
+<div className="max-h-[400px] overflow-y-auto">
   <Table>
@@
-  <TableBody className="max-h-[400px] overflow-y-auto overflow-x-hidden">
+  <TableBody>
website/src/components/FacetBarChart.tsx (3)

3-4: useMemo is imported but unused

The unused import will trigger the linter/TypeScript error no-unused-vars. Remove it.

-import { useMemo } from 'react';
+// import removed – not used

26-30: ChartableAttribute is declared in multiple files – extract to a shared type

Both FacetBarChart.tsx and Search.tsx define the same union. Divergence later will create type mismatches.

Create src/types/chart.ts (or extend types/search.ts) and reuse:

// types/chart.ts
export type ChartableAttribute = 'payer' | 'recipient' | 'province' | 'country';

Then import it in both modules.


101-110: limit prop is accepted but ignored

Consumers can specify limit, yet the component always renders the entire dataset:

-const chartData = data;
+const chartData = data.slice(0, limit);

Either honour the prop (as above) or drop it from FacetBarChartProps.

website/src/components/Search.tsx (1)

72-75: Dead constants – remove or implement batching

MAX_CHART_RECORDS and CHART_BATCH_SIZE are declared but unused.
If you planned to fetch additional pages for charting, implement the batching; otherwise delete to keep the codebase clean.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between c8cf35c and 436fc8d.

⛔ Files ignored due to path filters (2)
  • package-lock.json is excluded by !**/package-lock.json
  • website/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • website/package.json (0 hunks)
  • website/src/app/[lang]/layout.tsx (1 hunks)
  • website/src/components/FacetBarChart.tsx (1 hunks)
  • website/src/components/ResultsTable.tsx (3 hunks)
  • website/src/components/Search.tsx (10 hunks)
💤 Files with no reviewable changes (1)
  • website/package.json
🧰 Additional context used
🧬 Code Graph Analysis (1)
website/src/components/Search.tsx (4)
website/src/types/search.ts (1)
  • SearchResult (1-16)
website/src/components/ResultsTable.tsx (1)
  • ResultsTable (19-81)
website/src/components/FacetBarChart.tsx (1)
  • FacetBarChart (101-183)
website/src/components/Layout.tsx (1)
  • H3 (27-31)
🪛 Gitleaks (8.21.2)
website/src/components/Search.tsx

54-54: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

Comment on lines +85 to 88
const [chartAttribute, setChartAttribute] = useState<ChartableAttribute>('payer');

const totalHits = results?.nbHits ?? 0;
const [isChartLoading, setIsChartLoading] = useState(false);

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

isChartLoading state is never updated

You initialise the flag and render loaders based on it, but no code sets it to true/false.
Either leverage status === 'loading' from InstantSearch or add logic that toggles the flag while you aggregate data.

-const [isChartLoading, setIsChartLoading] = useState(false);
+const [isChartLoading, setIsChartLoading] = useState<boolean>(false);

useEffect(() => {
  setIsChartLoading(status === 'loading');
}, [status]);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const [chartAttribute, setChartAttribute] = useState<ChartableAttribute>('payer');
const totalHits = results?.nbHits ?? 0;
const [isChartLoading, setIsChartLoading] = useState(false);
const [chartAttribute, setChartAttribute] = useState<ChartableAttribute>('payer');
- const [isChartLoading, setIsChartLoading] = useState(false);
+ const [isChartLoading, setIsChartLoading] = useState<boolean>(false);
+ useEffect(() => {
+ setIsChartLoading(status === 'loading');
+ }, [status]);
🤖 Prompt for AI Agents
In website/src/components/Search.tsx around lines 85 to 88, the isChartLoading
state is initialized but never updated, so loaders depending on it won't behave
correctly. Fix this by either removing isChartLoading and using the existing
status === 'loading' from InstantSearch to control loading states, or add logic
to set isChartLoading to true when data aggregation starts and false when it
finishes, ensuring the loading indicator reflects the actual loading status.

Comment on lines +53 to +57
const typesenseServerConfig = {
apiKey: 'YpZamILESYThUVYZZ87dIBuJorHtRPfa',
nodes: [{ host: 'search.canadasbuilding.com', port: 443, protocol: 'https' }],
cacheSearchResultsForSeconds: 120,
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Hard-coded Typesense API key is publicly exposed

The key YpZamILESYThUVYZZ87dIBuJorHtRPfa is embedded in client-side code, allowing anyone to query or exhaust your Typesense quota.

Move it to a server-side environment variable and inject a short-lived search-only token to the browser.

-const typesenseServerConfig = {
-  apiKey: 'YpZamILESYThUVYZZ87dIBuJorHtRPfa',
+const typesenseServerConfig = {
+  apiKey: process.env.NEXT_PUBLIC_TYPESENSE_SEARCH_KEY!, // search-only
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const typesenseServerConfig = {
apiKey: 'YpZamILESYThUVYZZ87dIBuJorHtRPfa',
nodes: [{ host: 'search.canadasbuilding.com', port: 443, protocol: 'https' }],
cacheSearchResultsForSeconds: 120,
};
const typesenseServerConfig = {
apiKey: process.env.NEXT_PUBLIC_TYPESENSE_SEARCH_KEY!, // search-only
nodes: [{ host: 'search.canadasbuilding.com', port: 443, protocol: 'https' }],
cacheSearchResultsForSeconds: 120,
};
🧰 Tools
🪛 Gitleaks (8.21.2)

54-54: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

🤖 Prompt for AI Agents
In website/src/components/Search.tsx around lines 53 to 57, the Typesense API
key is hard-coded in the client-side code, exposing it publicly. Remove the API
key from this file and instead store it securely as a server-side environment
variable. Implement a backend endpoint to generate and provide a short-lived,
search-only token to the client, and update the client code to use this token
for authentication when querying Typesense.

Copy link
Collaborator

@maktouch maktouch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deployment is failing because of the presence of package-lock.json
We use pnpm, it should be updating the pnpm-lock.yaml file instead

Comment on lines +42 to +52
function formatCompactNumber(value: number): string {
if (value >= 1e9) {
return `$${(value / 1e9).toFixed(1)}B`;
}
if (value >= 1e6) {
return `$${(value / 1e6).toFixed(1)}M`;
}
if (value >= 1e3) {
return `$${(value / 1e3).toFixed(1)}K`;
}
return `$${value.toFixed(0)}`; // Basic format for smaller numbers
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use Intl.NumberFormat functions instead?

new Intl.NumberFormat("en-CA", {
  notation: "compact",
  compactDisplay: "short",
}).format(987654321);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants