Skip to content

feature: op insights PR 1#1160

Merged
carddev81 merged 2 commits into
mainfrom
CK-7vn/op-insights
Jun 9, 2026
Merged

feature: op insights PR 1#1160
carddev81 merged 2 commits into
mainfrom
CK-7vn/op-insights

Conversation

@CK-7vn

@CK-7vn CK-7vn commented Jun 4, 2026

Copy link
Copy Markdown
Member

Pre-Submission PR Checklist

  • No debug/console/fmt.Println statements
  • Unnecessary development comments removed
  • All acceptance criteria verified
  • Functions according to ticket specifications
  • Tested manually where applicable
  • Branch rebased with latest main
  • No business logic exists within the database layer

Description of the change

First PR of the operational insights redesign, redesigned page brings in tabbed Insights and implements the Overview tab end-to-end. Two endpoints added to backend /department-metrics/login-trend - calculates daily login totals and /department-metrics/facility-comparison - - per facility registered/active/logins.

Screenshot(s)

image image

Additional context

This is PR 1 of...multiple....

@CK-7vn CK-7vn requested a review from a team as a code owner June 4, 2026 21:59
@CK-7vn CK-7vn requested review from carddev81 and removed request for a team June 4, 2026 21:59
@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Redesigned "Insights" dashboard with interactive analytics, tabs (Overview, Knowledge Center), and updated sidebar label ("Insights")
    • Login trend chart with 7-day smoothing and date-range presets (7/30/90/YTD/Custom) and facility-scoped views
    • Facility comparison table showing registered, active, and login metrics; dashboard now includes total admins
    • New reusable metric card component and disabled "Export Report" control
  • Tests

    • Integration tests added for login trend, facility comparison, and admin counts (authorization and aggregation)

Walkthrough

Adds backend aggregation and endpoints for login trends and facility engagement, integration tests, and a frontend Insights redesign with date-range controls, a 7-day avg login trend chart, metric cards, and a sortable facility comparison table.

Changes

Operational Insights Login Trends & Facility Comparison

Layer / File(s) Summary
Data models and types
backend/src/models/logins.go, frontend/src/types/insights.ts
New DailyLoginCount and FacilityEngagement structs on backend; matching TypeScript interfaces plus InsightsRangeKey union on frontend define shapes for aggregated login and facility metrics.
Backend database queries and API endpoints
backend/src/database/DB.go, backend/src/database/users.go, backend/src/handlers/dashboard.go
MigrateTesting includes LoginActivity; GetTotalAdmins, GetDailyLoginActivity (with day bucketing), and GetFacilityEngagementComparison compute aggregates; two new endpoints /api/department-metrics/login-trend and /api/department-metrics/facility-comparison expose these queries.
Backend integration tests
backend/tests/integration/login_trend_test.go, backend/tests/integration/facility_comparison_test.go, backend/tests/integration/department_metrics_test.go
Tests exercise daily login aggregation (single and multi-facility), facility comparison endpoint and authorization, and GetTotalAdmins counting behavior.
Frontend date range utilities
frontend/src/pages/insights/insightsRange.ts
Export InsightsDateParams, RANGE_OPTIONS, RANGE_LABELS, and rangeToParams to convert preset or custom ranges into { start_date, end_date } parameters.
Frontend chart and card components
frontend/src/components/charts/LoginTrendChart.tsx, frontend/src/pages/insights/MetricCard.tsx, frontend/src/pages/insights/KnowledgeCenterTab.tsx
LoginTrendChart renders a 7-day rolling-average line from daily counts; MetricCard shows icon/value/label with optional tooltip; KnowledgeCenterTab is a coming-soon placeholder.
Frontend OperationalInsights page redesign
frontend/src/pages/insights/OperationalInsights.tsx
Rewritten page with preset/custom date selector, optional facility selector (when authorized), disabled Export button, and tabbed layout delegating to OverviewTab and KnowledgeCenterTab.
Frontend OverviewTab with metrics and comparison
frontend/src/pages/insights/OverviewTab.tsx
Fetches department metrics, login trend, and (conditionally) facility comparison; renders metric cards, LoginTrendChart, and a sortable facility comparison table showing registered, active, logins, and activation rate.
Frontend layout and navigation updates
frontend/src/layouts/AuthenticatedLayout.tsx, frontend/src/components/navigation/Sidebar.tsx, frontend/src/routes/app-routes.tsx
Mark /operational-insights as full-bleed with gray background; Sidebar icon changed to PresentationChartLineIcon and label to "Insights"; route title updated to "Insights".
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.55% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'feature: op insights PR 1' is vague and does not clearly convey the primary change; it lacks specificity about what was implemented. Use a more descriptive title that summarizes the main feature, such as 'feature: add operational insights page with login trend and facility comparison endpoints'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description is well-organized, includes context about the operational insights redesign, specifies the two new endpoints, references the related Asana task, and provides screenshots.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@CK-7vn CK-7vn force-pushed the CK-7vn/op-insights branch from aef7325 to 0b5ed29 Compare June 4, 2026 22:00
@CK-7vn CK-7vn force-pushed the CK-7vn/op-insights branch from 0b5ed29 to ff1ac9e Compare June 5, 2026 20:01
@carddev81

Copy link
Copy Markdown
Contributor

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@frontend/src/pages/insights/insightsRange.ts`:
- Around line 42-43: When range === 'Custom' verify that customFrom and customTo
are non-empty and valid dates before returning { start_date: customFrom,
end_date: customTo }; if either is empty/invalid, return a safe fallback (e.g.,
30-day range) or null/undefined to prevent constructing API queries with empty
params. Update the conditional that checks range (the block using range,
customFrom, customTo) to perform this validation and return the fallback/null;
also ensure consumers (OperationalInsights.tsx / OverviewTab) handle the null
case by disabling the API call until valid dates are provided.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 46e3eb26-1abf-46f7-bf5e-1d0bf7da8ad8

📥 Commits

Reviewing files that changed from the base of the PR and between 5f9c489 and ff1ac9e.

📒 Files selected for processing (17)
  • backend/src/database/DB.go
  • backend/src/database/users.go
  • backend/src/handlers/dashboard.go
  • backend/src/models/logins.go
  • backend/tests/integration/facility_comparison_test.go
  • backend/tests/integration/login_trend_test.go
  • frontend/src/components/charts/LoginTrendChart.tsx
  • frontend/src/components/charts/OperationalInsightsCharts.tsx
  • frontend/src/components/navigation/Sidebar.tsx
  • frontend/src/layouts/AuthenticatedLayout.tsx
  • frontend/src/pages/insights/KnowledgeCenterTab.tsx
  • frontend/src/pages/insights/MetricCard.tsx
  • frontend/src/pages/insights/OperationalInsights.tsx
  • frontend/src/pages/insights/OverviewTab.tsx
  • frontend/src/pages/insights/insightsRange.ts
  • frontend/src/routes/app-routes.tsx
  • frontend/src/types/insights.ts
💤 Files with no reviewable changes (1)
  • frontend/src/components/charts/OperationalInsightsCharts.tsx

Comment on lines +42 to +43
if (range === 'Custom') {
return { start_date: customFrom, end_date: customTo };

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Validate custom date parameters before use.

When range === 'Custom' but customFrom or customTo are empty strings (initial state after selecting Custom), this function returns { start_date: '', end_date: '' }, which will be interpolated into API query strings as start_date=&end_date=. The backend may not handle empty date parameters gracefully, potentially causing errors or unexpected results until the user selects valid dates.

🛡️ Recommended validation approach

Consider one of these solutions:

Option 1: Return a fallback range (e.g., 30D) when custom dates are empty:

 export function rangeToParams(
     range: InsightsRangeKey,
     customFrom: string,
     customTo: string
 ): InsightsDateParams {
     if (range === 'Custom') {
+        if (!customFrom || !customTo) {
+            // Fallback to 30D if custom dates not yet selected
+            const end = new Date();
+            const start = daysAgo(end, 29);
+            return { start_date: formatDate(start), end_date: formatDate(end) };
+        }
         return { start_date: customFrom, end_date: customTo };
     }

Option 2: Disable API calls in the consumer until valid custom dates are provided (validate in OperationalInsights.tsx before passing to OverviewTab).

📝 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
if (range === 'Custom') {
return { start_date: customFrom, end_date: customTo };
if (range === 'Custom') {
if (!customFrom || !customTo) {
// Fallback to 30D if custom dates not yet selected
const end = new Date();
const start = daysAgo(end, 29);
return { start_date: formatDate(start), end_date: formatDate(end) };
}
return { start_date: customFrom, end_date: customTo };
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/src/pages/insights/insightsRange.ts` around lines 42 - 43, When
range === 'Custom' verify that customFrom and customTo are non-empty and valid
dates before returning { start_date: customFrom, end_date: customTo }; if either
is empty/invalid, return a safe fallback (e.g., 30-day range) or null/undefined
to prevent constructing API queries with empty params. Update the conditional
that checks range (the block using range, customFrom, customTo) to perform this
validation and return the fallback/null; also ensure consumers
(OperationalInsights.tsx / OverviewTab) handle the null case by disabling the
API call until valid dates are provided.

@carddev81 carddev81 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@CK-7vn OP PR 1 is good to go. Added some changes, but overall great work!!!

@carddev81 carddev81 merged commit 3fa1a02 into main Jun 9, 2026
10 of 11 checks passed
@carddev81 carddev81 deleted the CK-7vn/op-insights branch June 9, 2026 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants