Skip to content

Develop - #442

Merged
ucswift merged 2 commits into
masterfrom
develop
Jul 28, 2026
Merged

Develop#442
ucswift merged 2 commits into
masterfrom
develop

Conversation

@ucswift

@ucswift ucswift commented Jul 28, 2026

Copy link
Copy Markdown
Member

Pull Request Description

This PR adds configurable per-lane work-time (crew fatigue) indicator thresholds to command board lanes. Each lane can now specify when its work-time indicator turns amber (warning) and red (critical) based on minutes resources have been assigned to that lane.

Changes

  • New data fields (WorkTimeAmberMinutes and WorkTimeRedMinutes) added to:

    • CommandBoardTemplateLane (template definition, with defaults of 20 and 40 minutes)
    • CommandDefinitionRole (command definition role)
    • CommandStructureNode (runtime node)
    • v4 API models (CommandRoleResultData and SaveCommandLaneInput)
  • Data propagation: Updated the template-to-definition creation, command seeding service, and the save/convert logic in CommandsController to flow these values through all layers.

  • Database migrations (Migration 103) for both SQL Server and PostgreSQL, adding the two new integer columns to the CommandStructureNodes and CommandDefinitionRoles tables with a default value of 0 (disabled).

A value of 0 disables the indicator, allowing clients to fall back to their own defaults. These thresholds are denormalized onto runtime nodes from the template role at seeding, consistent with how the existing lane limits (e.g., min/max time in role) are handled.

@Resgrid-Bot

Resgrid-Bot commented Jul 28, 2026

Copy link
Copy Markdown

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Validate Business Logic: Ask Kody to validate your code against business rules by adding a comment with the @kody -v business-logic command.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug
Performance
Security
Business Logic

Access your configuration settings here.

@request-info

request-info Bot commented Jul 28, 2026

Copy link
Copy Markdown

Thanks for opening this, but we'd appreciate a little more information. Could you update it with more details?

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Command lanes now support configurable amber and red work-time thresholds. Values flow from templates into command definitions and structure nodes, are persisted through SQL and PostgreSQL migrations, and round-trip through the v4 command API.

Changes

Lane threshold configuration and propagation

Layer / File(s) Summary
Template threshold propagation
Core/Resgrid.Model/CommandBoards/*``, Core/Resgrid.Model/CommandDefinitionRole.cs`
Lane templates define amber/red minute thresholds and copy them into generated command definition roles.
Storage and command seeding
Core/Resgrid.Model/IncidentCommand/CommandStructureNode.cs, Core/Resgrid.Services/IncidentCommandService.cs, Providers/Resgrid.Providers.Migrations/..., Providers/Resgrid.Providers.MigrationsPg/...
Command structure nodes store threshold values, command establishment seeds them from lane definitions, and both database providers add matching columns.
API threshold round trip
Web/Resgrid.Web.Services/Models/v4/Commands/CommandModels.cs, Web/Resgrid.Web.Services/Controllers/v4/CommandsController.cs
The v4 API accepts threshold values when saving lanes and returns stored values in lane results.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • Resgrid/Core#433: Related per-lane command-board template, model, API, and migration changes.

Suggested reviewers: github-actions

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% 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 is just the branch name and does not describe the PR’s actual change. Replace it with a concise summary of the feature, e.g. adding work-time amber/red thresholds for command lanes.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch develop

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.

@coderabbitai coderabbitai Bot 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.

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 `@Web/Resgrid.Web.Services/Models/v4/Commands/CommandModels.cs`:
- Around line 115-116: Update WorkTimeAmberMinutes and WorkTimeRedMinutes in the
command request model to nullable inputs, then adjust SaveCommand to retain each
stored threshold when its corresponding value is omitted while still persisting
an explicitly supplied 0 as the disable value.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 21d04f33-2967-498b-997c-c9a02d75d168

📥 Commits

Reviewing files that changed from the base of the PR and between 226cbc9 and 739821d.

📒 Files selected for processing (10)
  • Core/Resgrid.Model/CommandBoards/CommandBoardTemplate.cs
  • Core/Resgrid.Model/CommandBoards/CommandBoardTemplateCatalog.cs
  • Core/Resgrid.Model/CommandBoards/CommandBoardTemplateLane.cs
  • Core/Resgrid.Model/CommandDefinitionRole.cs
  • Core/Resgrid.Model/IncidentCommand/CommandStructureNode.cs
  • Core/Resgrid.Services/IncidentCommandService.cs
  • Providers/Resgrid.Providers.Migrations/Migrations/M0103_AddLaneWorkTimeThresholds.cs
  • Providers/Resgrid.Providers.MigrationsPg/Migrations/M0103_AddLaneWorkTimeThresholdsPg.cs
  • Web/Resgrid.Web.Services/Controllers/v4/CommandsController.cs
  • Web/Resgrid.Web.Services/Models/v4/Commands/CommandModels.cs

Comment on lines +115 to +116
public int WorkTimeAmberMinutes { get; set; }
public int WorkTimeRedMinutes { get; set; }

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Preserve omitted thresholds during updates.

Because these request fields are non-nullable, callers that omit the new JSON properties receive 0, and SaveCommand persists that value over existing thresholds. Since 0 disables the indicator, older or partial v4 clients can silently disable configured lane thresholds. Use nullable input fields and preserve stored values when they are omitted; reserve explicit 0 for disabling.

🤖 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 `@Web/Resgrid.Web.Services/Models/v4/Commands/CommandModels.cs` around lines
115 - 116, Update WorkTimeAmberMinutes and WorkTimeRedMinutes in the command
request model to nullable inputs, then adjust SaveCommand to retain each stored
threshold when its corresponding value is omitted while still persisting an
explicitly supplied 0 as the disable value.

string[] unitTypes = null, string[] personnelRoles = null, bool forceRequirements = false,
int minUnits = 0, int maxUnits = 0, int minUnitPersonnel = 0, int maxUnitPersonnel = 0, int minTimeInRole = 0, int maxTimeInRole = 0)
int minUnits = 0, int maxUnits = 0, int minUnitPersonnel = 0, int maxUnitPersonnel = 0, int minTimeInRole = 0, int maxTimeInRole = 0,
int workTimeAmberMinutes = 20, int workTimeRedMinutes = 40)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Kody Rules low

Uninitialized property WorkTimeAmberMinutes in CommandModels.cs lacks an explicit default initializer, leaving the object in an ambiguous state per Rule [32]. Add an explicit initializer such as = 0 or set it in the constructor.

Kody rule violation: Replace magic numbers with named constants

Prompt for LLM

File Core/Resgrid.Model/CommandBoards/CommandBoardTemplateCatalog.cs:

Line 45:

Uninitialized property WorkTimeAmberMinutes in CommandModels.cs lacks an explicit default initializer, leaving the object in an ambiguous state per Rule [32]. Add an explicit initializer such as = 0 or set it in the constructor.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

{
if (Schema.Table("CommandStructureNodes").Exists())
{
foreach (var column in new[] { "WorkTimeAmberMinutes", "WorkTimeRedMinutes" })

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Kody Rules low

WHAT: The column-name string literals are defined inline and will be repeated four times in this file. WHY: Repeating raw string literals for database identifiers risks typos and makes future renames error-prone. HOW: Extract a private static readonly string[] WorkTimeColumns = { "WorkTimeAmberMinutes", "WorkTimeRedMinutes" }; at class level and reference it in every loop.

Also found in:

  • Providers/Resgrid.Providers.Migrations/Migrations/M0103_AddLaneWorkTimeThresholds.cs:29-29
  • Providers/Resgrid.Providers.Migrations/Migrations/M0103_AddLaneWorkTimeThresholds.cs:44-44
  • Providers/Resgrid.Providers.Migrations/Migrations/M0103_AddLaneWorkTimeThresholds.cs:53-53

Kody rule violation: Centralize string constants

Prompt for LLM

File Providers/Resgrid.Providers.Migrations/Migrations/M0103_AddLaneWorkTimeThresholds.cs:

Line 17:

WHAT: The column-name string literals are defined inline and will be repeated four times in this file. WHY: Repeating raw string literals for database identifiers risks typos and makes future renames error-prone. HOW: Extract a private static readonly string[] WorkTimeColumns = { "WorkTimeAmberMinutes", "WorkTimeRedMinutes" }; at class level and reference it in every loop.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

{
if (Schema.Table("commandstructurenodes").Exists())
{
foreach (var column in new[] { "worktimeamberminutes", "worktimeredminutes" })

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Kody Rules low

WHAT: The column-name array literal new[] { "worktimeamberminutes", "worktimeredminutes" } is repeated on lines 17, 29, 44, and 53. WHY: Duplicated literals risk divergence if a column name is renamed or added. HOW: Declare a private static readonly string[] WorkTimeColumns at class level and reference it in all four loops; additionally, factor the repeated Alter/Table-check and Delete/Table-check blocks into helper methods.

Also found in:

  • Providers/Resgrid.Providers.Migrations/Migrations/M0103_AddLaneWorkTimeThresholds.cs:29-29
  • Providers/Resgrid.Providers.Migrations/Migrations/M0103_AddLaneWorkTimeThresholds.cs:53-53
  • Providers/Resgrid.Providers.MigrationsPg/Migrations/M0103_AddLaneWorkTimeThresholdsPg.cs:29-29
  • Providers/Resgrid.Providers.MigrationsPg/Migrations/M0103_AddLaneWorkTimeThresholdsPg.cs:53-53
  • Providers/Resgrid.Providers.MigrationsPg/Migrations/M0103_AddLaneWorkTimeThresholdsPg.cs:44-44

Kody rule violation: Extract duplicated logic into functions

Prompt for LLM

File Providers/Resgrid.Providers.MigrationsPg/Migrations/M0103_AddLaneWorkTimeThresholdsPg.cs:

Line 17:

WHAT: The column-name array literal new[] { "worktimeamberminutes", "worktimeredminutes" } is repeated on lines 17, 29, 44, and 53. WHY: Duplicated literals risk divergence if a column name is renamed or added. HOW: Declare a private static readonly string[] WorkTimeColumns at class level and reference it in all four loops; additionally, factor the repeated Alter/Table-check and Delete/Table-check blocks into helper methods.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

public int MaxUnits { get; set; }
public int MinTimeInRole { get; set; }
public int MaxTimeInRole { get; set; }
public int WorkTimeAmberMinutes { get; set; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Kody Rules low

WHAT: The new int property WorkTimeAmberMinutes has no explicit default initializer. WHY: Rule [32] requires properties to have sensible defaults or be initialized via constructors so the object is never in an ambiguous state. Although int defaults to 0 in C#, making the default explicit communicates intent (e.g., = 0 or a meaningful value). HOW: Add an explicit initializer such as public int WorkTimeAmberMinutes { get; set; } = 0; or set it in the constructor.

Also found in:

  • Web/Resgrid.Web.Services/Models/v4/Commands/CommandModels.cs:50-50
  • Web/Resgrid.Web.Services/Models/v4/Commands/CommandModels.cs:115-115
  • Web/Resgrid.Web.Services/Models/v4/Commands/CommandModels.cs:116-116

Kody rule violation: Initialize properties with default values

Prompt for LLM

File Web/Resgrid.Web.Services/Models/v4/Commands/CommandModels.cs:

Line 49:

WHAT: The new int property `WorkTimeAmberMinutes` has no explicit default initializer. WHY: Rule [32] requires properties to have sensible defaults or be initialized via constructors so the object is never in an ambiguous state. Although `int` defaults to `0` in C#, making the default explicit communicates intent (e.g., `= 0` or a meaningful value). HOW: Add an explicit initializer such as `public int WorkTimeAmberMinutes { get; set; } = 0;` or set it in the constructor.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

@ucswift

ucswift commented Jul 28, 2026

Copy link
Copy Markdown
Member Author

Approve

@github-actions github-actions 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.

This PR is approved.

@ucswift
ucswift merged commit 76df728 into master Jul 28, 2026
18 of 19 checks passed
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.

2 participants