Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Jun 13, 2025

Link issues

fixes #6223

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Add support for optionally displaying the year in the FlipClock component by introducing a ShowYear parameter, updating samples and JavaScript logic, and ensuring coverage with a new unit test.

New Features:

  • Add ShowYear parameter and markup to render four-digit year flips in FlipClock.
  • Add a toggle control for ShowYear in the FlipClocks sample page and include it in the component's attribute table.
  • Extend the FlipClock JavaScript init logic to handle years as a flip unit.

Enhancements:

  • Refactor FlipClock JavaScript to use a generic configuration array (getConfig) and setDigits function for updating all time units (years, months, days, hours, minutes, seconds).

Documentation:

  • Update the FlipClocks sample page and attribute documentation to showcase the new ShowYear option.

Tests:

  • Add a unit test to verify that the year flip list is rendered when ShowYear is enabled.

@bb-auto bb-auto bot added the enhancement New feature or request label Jun 13, 2025
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jun 13, 2025

Reviewer's Guide

This PR adds a new ShowYear option to the FlipClock component—enabling optional rendering and animation of the year digits—and refactors the JavaScript timing logic into a generic unit configuration. It also updates the Razor component, sample page, localization, and tests to support the new parameter.

Sequence Diagram for Refactored JavaScript Clock Logic

sequenceDiagram
    participant Timer
    participant go()
    participant getDate()
    participant getConfig()
    participant setDigits()

    Timer->>go(): Executes every second
    go()->>getDate(): Get current time data
    getDate()-->>go(): Returns {years, months, ...}
    go()->>getConfig(): Get unit configurations
    getConfig()-->>go(): Returns [{key:'years',...}, {key:'months',...}]
    loop For each time unit
        go()->>go(): Check if value changed
        alt Value has changed
            go()->>setDigits(): Update DOM for the unit
        end
    end
Loading

Class Diagram for FlipClock Component Changes

classDiagram
    class FlipClock {
        +bool ShowYear
        +bool ShowMonth
        +bool ShowDay
        +bool ShowHour
        +bool ShowMinute
        +bool ShowSecond
        +FlipClockViewMode ViewMode
    }

    class FlipClocks {
        -bool _showYear
        -bool _showMonth
        -bool _showDay
        -bool _showHour
        -bool _showMinute
        -bool _showSecond
    }

    FlipClocks --|> FlipClock : uses
Loading

File-Level Changes

Change Details Files
Introduce ShowYear parameter in FlipClock component
  • Declare ShowYear [Parameter] in component class
  • Conditionally render four year digit slots in the Razor markup
src/BootstrapBlazor/Components/FlipClock/FlipClock.razor.cs
src/BootstrapBlazor/Components/FlipClock/FlipClock.razor
Refactor JavaScript flip-clock logic to support years and generic units
  • Enhance getDate() to return years for DateTime mode
  • Replace individual list variables with a unit config array
  • Implement setDigits() for all time units and remove old setTime()
src/BootstrapBlazor/Components/FlipClock/FlipClock.razor.js
Extend sample page to demonstrate ShowYear toggle
  • Add _showYear field and bind a switch control in FlipClocks.razor
  • Pass ShowYear/_showYear alongside other ShowX parameters
  • Include ShowYear attribute metadata in the samples attribute table
src/BootstrapBlazor.Server/Components/Samples/FlipClocks.razor
src/BootstrapBlazor.Server/Components/Samples/FlipClocks.razor.cs
Add unit test for ShowYear behavior
  • Verify absence of year list by default
  • Assert presence of year list when ShowYear=true
test/UnitTest/Components/FlipClockTest.cs
Update localization resources for ShowYear
  • Add ShowYear label and description in English resource
  • Add ShowYear label and description in Chinese resource
src/BootstrapBlazor.Server/Locales/en-US.json
src/BootstrapBlazor.Server/Locales/zh-CN.json

Assessment against linked issues

Issue Objective Addressed Explanation

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto bot added this to the 9.7.0 milestone Jun 13, 2025
@codecov
Copy link

codecov bot commented Jun 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (48289a4) to head (db1ce31).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #6224   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          704       704           
  Lines        31105     31113    +8     
  Branches      4397      4398    +1     
=========================================
+ Hits         31105     31113    +8     
Flag Coverage Δ
BB 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

sourcery-ai[bot]
sourcery-ai bot previously approved these changes Jun 13, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @ArgoZhang - I've reviewed your changes - here's some feedback:

  • In getDate(), you’re calling new Date() multiple times and always returning the current year in countdown mode—consider using a single Date instance and properly computing a year delta when countDown is true.
  • The new ShowYear localization keys (e.g. ShowYear_Description, ShowYearText, ShowYearIntro) don’t appear to be added to en-US.json/zh-CN.json—please include those entries so the sample renders correctly.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In getDate(), you’re calling new Date() multiple times and always returning the current year in countdown mode—consider using a single Date instance and properly computing a year delta when countDown is true.
- The new ShowYear localization keys (e.g. ShowYear_Description, ShowYearText, ShowYearIntro) don’t appear to be added to en-US.json/zh-CN.json—please include those entries so the sample renders correctly.

## Individual Comments

### Comment 1
<location> `src/BootstrapBlazor/Components/FlipClock/FlipClock.razor:8` </location>
<code_context>
 <div @attributes="@AdditionalAttributes" class="@ClassString" style="@StyleString" id="@Id">
+    @if (ShowYear)
+    {
+        <div class="bb-flip-clock-list year">
+            @RenderItem(10)
+            @RenderItem(10)
</code_context>

<issue_to_address>
DRY up repeating @RenderItem calls

Consider replacing the repeated `@RenderItem(10)` lines with a `@for` loop to eliminate duplication and improve maintainability.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
        <div class="bb-flip-clock-list year">
            @RenderItem(10)
            @RenderItem(10)
            @RenderItem(10)
            @RenderItem(10)
        </div>
=======
        <div class="bb-flip-clock-list year">
            @for (var i = 0; i < 4; i++)
            {
                @RenderItem(10)
            }
        </div>
>>>>>>> REPLACE

</suggested_fix>

### Comment 2
<location> `src/BootstrapBlazor/Components/FlipClock/FlipClock.razor.js:127` </location>
<code_context>
     }
 }

+const setYear = (list, year, countDown) => {
+    if (list) {
+        list.classList.remove('flip');
</code_context>

<issue_to_address>
Consider refactoring the repeated time unit update logic into a generic helper and loop to reduce duplication and centralize state management.

Here’s one way to collapse the repeated “year/month/day/…” logic into a small generic loop and helper, while only ever calling new Date() once:

```js
// 1) Replace setTime + setYear with a single generic:
const setDigits = (list, value, digits, countDown) => {
  if (!list) return;
  list.classList.remove('flip');
  for (let i = 0; i < digits; i++) {
    const place = digits - 1 - i;
    const digit = Math.floor(value / 10 ** place) % 10;
    setFlip(list.children[i], digit, countDown);
  }
  list.classList.add('flip');
};

// 2) In your initializer, build a config array and shared last-state:
const unitConfig = [
  { key: 'years',  list: el.querySelector('.bb-flip-clock-list.year'),   digits: 4 },
  { key: 'months', list: el.querySelector('.bb-flip-clock-list.month'),  digits: 2 },
  { key: 'days',   list: el.querySelector('.bb-flip-clock-list.day'),    digits: 2 },
  { key: 'hours',  list: el.querySelector('.bb-flip-clock-list.hour'),   digits: 2 },
  { key: 'minutes',list: el.querySelector('.bb-flip-clock-list.minute'), digits: 2 },
  { key: 'seconds',list: el.querySelector('.bb-flip-clock-list.second'), digits: 2 },
];

const lastValues = {}; // will hold lastValues.years, .months, …

// 3) Simplify getDate() to a single Date() call:
const getDate = () => {
  if (!countDown && !options.fixed) {
    const now = new Date();
    return {
      years:   now.getFullYear(),
      months:  now.getMonth() + 1,
      days:    now.getDate(),
      hours:   now.getHours(),
      minutes: now.getMinutes(),
      seconds: now.getSeconds()
    };
  }
  // … your existing elapsed / countdown logic returning the same shape …
};

// 4) Collapse go() into one small loop:
const go = () => {
  const d = getDate();
  unitConfig.forEach(({ key, list, digits }) => {
    const v = d[key];
    if (lastValues[key] !== v) {
      lastValues[key] = v;
      setDigits(list, v, digits, countDown);
    }
  });
  return d;
};
```

Benefits:

- No more separate `setYear` vs `setTime`.
- Only one `new Date()` per tick.
- All “lastX” state lives in a single object.
- Adding/removing units (e.g. weeks) is just editing `unitConfig`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@ArgoZhang
Copy link
Member Author

@sourcery-ai review

sourcery-ai[bot]
sourcery-ai bot previously approved these changes Jun 13, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @ArgoZhang - I've reviewed your changes - here's some feedback:

  • It appears the locale files weren’t updated with the new ShowYear and ShowYear_Description keys—please add them to both en-US.json and zh-CN.json.
  • Several DemoBlock examples for month/day/hour/minute/second were removed from FlipClocks.razor—please restore them (or confirm the intent) so existing usage demos aren’t lost.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- It appears the locale files weren’t updated with the new ShowYear and ShowYear_Description keys—please add them to both en-US.json and zh-CN.json.
- Several DemoBlock examples for month/day/hour/minute/second were removed from FlipClocks.razor—please restore them (or confirm the intent) so existing usage demos aren’t lost.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@ArgoZhang ArgoZhang merged commit 6f84d88 into main Jun 13, 2025
5 checks passed
@ArgoZhang ArgoZhang deleted the feat-year branch June 13, 2025 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(FlipClock): add ShowYear parameter

2 participants