Skip to content

Conversation

@astandrik
Copy link
Collaborator

@astandrik astandrik commented Dec 2, 2025

Closes #3133

Greptile Overview

Greptile Summary

This PR consolidates duration formatting by renaming functions to be more semantically accurate and consistent across the codebase.

Key Changes:

  • Renamed formatUptimeInSeconds to formatDurationSeconds and formatMsToUptime to formatDurationMs for clearer naming that better reflects their generic duration formatting purpose
  • Updated all usages across VDisk components, Operations table, and Tenant Diagnostics (Consumers/Partitions)
  • Renamed test file from formatUptime.test.ts to formatDuration.test.ts with updated test cases
  • Removed duplicate duration formatting logic in Operations columns that was using @gravity-ui/date-utils directly, now uses shared formatDurationMs function

Impact:
The refactor improves code maintainability by consolidating duration formatting into consistently-named utility functions, eliminating duplication and ensuring uniform formatting across the application.

Confidence Score: 5/5

  • This PR is safe to merge with no risk - it's a straightforward refactoring that renames functions and consolidates formatting logic
  • The changes are purely refactoring with no logic modifications. All function renaming is consistent, all usages are updated, tests are maintained with new names, and no old function references remain in the codebase. The implementation maintains backward compatibility in behavior while improving code clarity.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
src/utils/dataFormatters/dataFormatters.ts 5/5 Renamed formatUptimeInSeconds to formatDurationSeconds and formatMsToUptime to formatDurationMs for clearer function naming
src/utils/dataFormatters/test/formatDuration.test.ts 5/5 Renamed test file from formatUptime.test.ts to formatDuration.test.ts and updated test cases to use new function names
src/containers/Operations/columns.tsx 5/5 Replaced custom duration formatting logic using @gravity-ui/date-utils with formatDurationMs, removed unused imports and constants

Sequence Diagram

sequenceDiagram
    participant Components as UI Components
    participant Formatters as Duration Formatters
    participant GravityUI as @gravity-ui/date-utils

    Note over Components,GravityUI: Duration Formatting Refactor

    Components->>Formatters: formatDurationMs(ms)
    Formatters->>Formatters: Convert ms to seconds
    Formatters->>Formatters: formatDurationSeconds(seconds)
    
    alt seconds is NaN
        Formatters-->>Components: undefined
    else valid duration
        Formatters->>GravityUI: duration(Math.abs(seconds), 's').rescale()
        GravityUI-->>Formatters: duration object
        
        alt days > 0
            Formatters->>Formatters: format as "Xd HH:MM:SS"
        else hours > 0
            Formatters->>Formatters: format as "H:MM:SS"
        else minutes > 0
            Formatters->>Formatters: format as "M:SS"
        else seconds only
            Formatters->>Formatters: format as "Xs"
        end
        
        Formatters->>Formatters: Add sign if negative
        Formatters-->>Components: formatted string
    end

    Note over Components: VDiskInfo, VDiskPopup
    Note over Components: Operations columns
    Note over Components: Consumers/Partitions diagnostics
Loading

CI Results

Test Status: ⚠️ FLAKY

📊 Full Report

Total Passed Failed Flaky Skipped
378 375 0 1 2
Test Changes Summary ⏭️2

⏭️ Skipped Tests (2)

  1. Scroll to row, get shareable link, navigate to URL and verify row is scrolled into view (tenant/diagnostics/tabs/queries.test.ts)
  2. Copy result button copies to clipboard (tenant/queryEditor/queryEditor.test.ts)

Bundle Size: ✅

Current: 62.33 MB | Main: 62.33 MB
Diff: 0.28 KB (-0.00%)

✅ Bundle size unchanged.

ℹ️ CI Information
  • Test recordings for failed tests are available in the full report.
  • Bundle size is measured for the entire 'dist' directory.
  • 📊 indicates links to detailed reports.
  • 🔺 indicates increase, 🔽 decrease, and ✅ no change in bundle size.

Copilot AI review requested due to automatic review settings December 2, 2025 10:46
Copilot finished reviewing on behalf of astandrik December 2, 2025 10:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors duration formatting functions to use more consistent and descriptive naming conventions. The changes rename formatUptimeInSeconds to formatDurationSeconds and formatMsToUptime to formatDurationMs to better reflect their generic duration formatting purpose rather than being specific to uptime.

  • Renamed duration formatting functions to more descriptive names
  • Updated all usages across the codebase consistently
  • Improved the Operations duration column to use the standardized formatting approach

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/utils/dataFormatters/dataFormatters.ts Renamed core formatting functions and updated documentation
src/utils/dataFormatters/test/formatDuration.test.ts Updated test suite to use new function names
src/containers/Tenant/Diagnostics/Partitions/columns/columns.tsx Updated partition lag/idle time formatting calls
src/containers/Tenant/Diagnostics/Consumers/columns/columns.tsx Updated consumer lag/idle time formatting calls
src/containers/Tenant/Diagnostics/Consumers/TopicStats/ConsumersTopicStats.tsx Updated topic stats formatting calls
src/containers/Operations/columns.tsx Replaced custom duration formatting with standardized function and removed unnecessary imports
src/components/VDiskPopup/VDiskPopup.tsx Updated VDisk replication time formatting
src/components/VDiskInfo/VDiskInfo.tsx Updated VDisk info time formatting and imports

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

8 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

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.

feat: use same duration functions

3 participants