Skip to content

feat: add 'Starting from weekday' date range#10

Open
Raian256 wants to merge 1 commit intodougcooper:mainfrom
Raian256:feat/starting-from-weekday-preset
Open

feat: add 'Starting from weekday' date range#10
Raian256 wants to merge 1 commit intodougcooper:mainfrom
Raian256:feat/starting-from-weekday-preset

Conversation

@Raian256
Copy link
Copy Markdown

Summary

Adds a new "Starting from weekday" date preset. When selected, a
secondary dropdown appears to pick a specific weekday (Mon–Sun).
The date range then spans from the most recent occurrence of that
weekday up to today (inclusive).

Example: today is Thursday → pick Tuesday → 3-day range.

Changes

  • index.html — new preset option, weekday picker UI, show/hide
    logic, and date calculation
  • tests/index.test.js — test covering picker visibility and
    correct range length for all 7 weekdays

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the dashboard's date range functionality by adding a new preset option. Users can now easily define a date range that begins from a specific day of the week, relative to the current date. This provides more flexibility in data visualization and reporting without requiring manual date input.

Highlights

  • New Date Preset: Introduced a new 'Starting from weekday' date preset, allowing users to select a date range from the most recent occurrence of a chosen weekday up to today.
  • Dynamic UI: Implemented a secondary dropdown for weekday selection that appears only when the 'Starting from weekday' preset is chosen, enhancing user experience.
  • Date Calculation Logic: Added JavaScript logic to correctly calculate the start date for the new 'from-weekday' preset based on the selected weekday and the current date.
  • Comprehensive Testing: Included a new test case to ensure the visibility of the weekday picker and the accuracy of the date range calculation for all seven weekdays.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new "Starting from weekday" date range preset to the dashboard. This feature includes UI updates in sp-dashboard/index.html to add the new preset option and a corresponding weekday selection dropdown, along with JavaScript logic to manage their visibility and calculate the date range. A new test case in tests/index.test.js validates this functionality. Review feedback highlights that the new test for the "from-weekday" preset could be flaky due to its reliance on new Date() and suggests mocking system time for determinism. Additionally, it's recommended to cache the weekday-select DOM element reference for improved performance and maintainability, and to remove a redundant window.processData call in the new test.

expect(weekdayPickerContainer.classList.contains('hidden')).toBe(false);

// Test each weekday
const today = new Date();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

This test could be flaky because it relies on the current system time (new Date()). If the test execution crosses a day boundary between this line and the new Date() call inside processData, the test might fail unexpectedly. It's a best practice to mock date/time for such tests to ensure they are deterministic.

You can use vi.useFakeTimers() and vi.setSystemTime() to control the system time within your test. For example:

const mockToday = new Date('2024-01-26T12:00:00Z'); // A Friday
vi.useFakeTimers();
vi.setSystemTime(mockToday);

// ... your test logic ...

vi.useRealTimers(); // cleanup

} else if (preset === 'year') {
startObj.setFullYear(endObj.getFullYear() - 1);
} else if (preset === 'from-weekday') {
const targetDay = parseInt(document.getElementById('weekday-select').value, 10);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

For better performance and maintainability, it's a good practice to cache DOM element references instead of querying for them repeatedly. The weekday-select element is accessed here and also when attaching an event listener (line 541). You can get the element once and store it in a variable at the top of the script block, similar to how presetSelect and customContainer are handled.

For example, you could add this line near line 533:

const weekdaySelect = document.getElementById('weekday-select');

Then you would change line 541 to:

weekdaySelect.addEventListener('change', () => processData(cachedTasks, cachedProjects));

And this line would become:

Suggested change
const targetDay = parseInt(document.getElementById('weekday-select').value, 10);
const targetDay = parseInt(weekdaySelect.value, 10);

for (const targetDay of [0, 1, 2, 3, 4, 5, 6]) {
weekdaySelect.value = String(targetDay);
weekdaySelect.dispatchEvent(new Event('change'));
window.processData([], []);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The dispatchEvent on the previous line already triggers processData via the event listener. This explicit call to window.processData is redundant and can be removed.

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.

1 participant