Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Invalid Date Display in Table Widget's Date Column When Using Unix Timestamp (ms) #36455

Merged
merged 22 commits into from
Sep 30, 2024

Conversation

jacquesikot
Copy link
Contributor

@jacquesikot jacquesikot commented Sep 20, 2024

Description

Problem
When populating a table widget with data that includes dates in Unix timestamp (milliseconds) format, setting the column type to "Date," the input format to "Unix timestamp (ms)," and selecting a display format leads to an issue during inline editing. While the date picker behaves correctly, selecting a new date results in the table cell showing an "Invalid Date" error.

Root Cause
The platform currently uses DateInputFormat.MILLISECONDS for Unix timestamp (ms) formatting. However, this value is not a valid option for the moment.format() function, which expects the input format to be 'x' for Unix timestamps in milliseconds. This mismatch leads to the "Invalid Date" error.

Solution
Modify the logic to map DateInputFormat.MILLISECONDS to the correct moment format string 'x'.
Adjust the table's transformDataPureFn to correctly process and display dates in Unix timestamp (ms) format after inline edits, ensuring the moment library can handle the input properly.

Outcome
This fix ensures that when a user selects a date via the date picker in inline editing mode, the selected date is displayed correctly in the table without any errors.

Fixes #35631

Automation

/ok-to-test tags="@tag.Sanity, @tag.Binding, @tag.Table, @tag.Datepicker"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11101758400
Commit: 6a3cae7
Cypress dashboard.
Tags: @tag.Sanity, @tag.Binding, @tag.Table, @tag.Datepicker
Spec:


Mon, 30 Sep 2024 08:54:58 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced date column editing in table widgets to accept Unix timestamps in milliseconds without errors.
    • Introduced a new enumeration for improved date formatting options.
    • Added mock data structures for testing various date formats and transformations in the table widget.
    • New method for generating formatted date strings for tomorrow in both verbose and ISO formats.
  • Bug Fixes

    • Improved validation logic for date inputs in the table, ensuring proper handling of different date formats.
  • Tests

    • Added new test cases to validate date handling and input formats in the table widget.
    • Introduced a new test suite for transforming table data based on specified column metadata.

@jacquesikot jacquesikot added ok-to-test Required label for CI Widgets & Accelerators Pod Issues related to widgets & Accelerators labels Sep 20, 2024
@jacquesikot jacquesikot self-assigned this Sep 20, 2024
Copy link
Contributor

coderabbitai bot commented Sep 20, 2024

Walkthrough

The pull request introduces enhancements to the date column editing functionality in a table widget. It adds a test case that verifies the acceptance of Unix timestamps in milliseconds, ensuring they do not trigger errors during inline editing. Additionally, modifications are made to the DateCell component to improve date formatting handling, and a new enumeration for millisecond input formats is introduced. The changes refine the validation process for date inputs, particularly for non-millisecond formats.

Changes

File Change Summary
app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/Date_column_editing_2_spec.ts, app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/fixtures.ts Added a test case for Unix timestamps in milliseconds and introduced a new fixture for user data.
app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/helpers.ts Introduced a helper function to generate formatted date strings for tomorrow.
app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/Date_column_types_validation_spec.ts Created tests for validating various date column types in a table widget.
app/client/src/widgets/TableWidgetV2/component/cellComponents/DateCell.tsx, app/client/src/widgets/TableWidgetV2/constants.ts Modified date formatting logic and introduced a new enumeration for millisecond input formats.
app/client/src/widgets/TableWidgetV2/widget/reactTableUtils/TransformDataPureFn.test.ts, app/client/src/widgets/TableWidgetV2/widget/reactTableUtils/fixtures.ts Introduced unit tests for the transformDataPureFn function and mock data for testing scenarios.

Assessment against linked issues

Objective Addressed Explanation
Ensure correct handling of Unix Timestamp values in Date type columns (#35631)
Validate that updated values in the datepicker are correct for Unix timestamps (#35631)

Possibly related PRs

Suggested labels

Table Widget V2

Suggested reviewers

  • ApekshaBhosale
  • rahulbarwal
  • sagar-qa007
  • yatinappsmith

In the world of dates, a change so bright,
Unix timestamps now shine with light.
Editing made easy, no errors in sight,
A table of joy, all values just right!
With tests in place, our code feels so tight! 🌟


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b13f966 and 6a3cae7.

📒 Files selected for processing (1)
  • app/client/src/widgets/TableWidgetV2/widget/reactTableUtils/TransformDataPureFn.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/client/src/widgets/TableWidgetV2/widget/reactTableUtils/TransformDataPureFn.test.ts

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added Bug Something isn't working Community Reported issues reported by community members High This issue blocks a user from building or impacts a lot of users Needs More Info Needs additional information Needs Triaging Needs attention from maintainers to triage Production Table Inline Edit Issues related to inline editing Widgets Product This label groups issues related to widgets labels Sep 20, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
app/client/cypress/fixtures/tableDateColumnTypes.ts (1)

2-26: Attention, students! Let's review the content of our date formats.

While the variety of date formats is impressive, we need to address some inconsistencies:

  1. Property naming conventions:

    • Most properties use quotes, but iso8601 doesn't. Let's be consistent.
    • Some use camelCase (unixms), others use snake_case (yyyymmdd). Choose one style.
  2. Time representation:

    • Some formats use 24-hour time (14:30), others use 12-hour time (2:30 PM). Consider standardizing.
  3. Redundancy:

    • ll and dmmmmyyyy represent the same format. Consider removing one.

Here's an example of how to improve consistency:

 {{
   [
     {
       "unixs": 1727212200,
       "unixms": 1727212200000,
       "yyyymmdd": "2024-09-25",
       "yyyymmddhhmm": "2024-09-25 14:30",
-      iso8601: "2024-09-25T14:30:00.000Z",
+      "iso8601": "2024-09-25T14:30:00.000Z",
       "yyyymmddTHHmmss": "2024-09-25T14:30:00",
       "yyyymmddhhmmss": "2024-09-25 14:30:00",
       "doMMMyyyy": "25th Sep 2024",
       "ddmmyyyy": "25/09/2024",
       "ddmmyyyyhhmm": "25/09/2024 14:30",
       "lll": "September 25, 2024 2:30 PM",
-      ll: "September 25, 2024",
+      "ll": "September 25, 2024",
       "dmmmmyyyy": "25 September, 2024",
       "hmmAdmmmmyyyy": "2:30 PM 25 September, 2024",
       "mm1dd1yyyy": "09-25-2024",
       "dd1mm1yyyy": "25-09-2024",
       "ddimmiyy": "25/09/24",
       "mmddyy": "09/25/24",
     },
   ]
 }}

Remember, consistency is key in programming, just like in your homework!

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 17fa7e9 and 17e8f41.

📒 Files selected for processing (2)
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/Date_column_types_validation_spec.ts (1 hunks)
  • app/client/cypress/fixtures/tableDateColumnTypes.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/Date_column_types_validation_spec.ts
🧰 Additional context used
📓 Path-based instructions (1)
app/client/cypress/fixtures/tableDateColumnTypes.ts (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
🔇 Additional comments (1)
app/client/cypress/fixtures/tableDateColumnTypes.ts (1)

1-1: Well done, class! The constant declaration looks correct.

The naming convention and export statement are appropriate for this TypeScript file. Using a template string for the multi-line content is a good choice.

rahulbarwal
rahulbarwal previously approved these changes Sep 27, 2024
rahulbarwal
rahulbarwal previously approved these changes Sep 27, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between dfe7b65 and b13f966.

📒 Files selected for processing (2)
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/Date_column_types_validation_spec.ts (1 hunks)
  • app/client/cypress/support/Pages/Table.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/Date_column_types_validation_spec.ts
🧰 Additional context used
📓 Path-based instructions (1)
app/client/cypress/support/Pages/Table.ts (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.

Comment on lines +859 to +884
public getFormattedTomorrowDates() {
// Create a new Date object for today
const tomorrow = new Date();

// Set the date to tomorrow by adding 1 to today's date
tomorrow.setDate(tomorrow.getDate() + 1);

// Format tomorrow's date in verbose form (e.g., "Sat Sep 21 2024")
const verboseFormat = tomorrow
.toLocaleDateString("en-US", {
weekday: "short",
year: "numeric",
month: "short",
day: "2-digit",
})
.replace(/,/g, ""); // Remove commas from the formatted string

// Format tomorrow's date in ISO form (e.g., "2024-09-21")
const isoFormat = tomorrow.toISOString().split("T")[0]; // Extract the date part only

// Return both formatted date strings as an object
return {
verboseFormat,
isoFormat,
};
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Class, let's improve our new method!

The getFormattedTomorrowDates method is a fine addition to our Table class. However, we can make it even better with a few tweaks:

  1. Let's rename it to getFormattedTomorrowDateStrings to be more specific about returning multiple formats.

  2. We should use JSDoc comments for better documentation. Here's an example:

/**
 * Gets formatted date strings for tomorrow's date.
 * @returns {Object} An object containing formatted date strings.
 * @property {string} verboseFormat - Date in verbose format (e.g., "Sat Sep 21 2024").
 * @property {string} isoFormat - Date in ISO format (e.g., "2024-09-21").
 */
  1. Let's add TypeScript type annotations for better type safety:
public getFormattedTomorrowDateStrings(): { verboseFormat: string; isoFormat: string } {
  // ... method implementation ...
}
  1. Consider using padStart for consistent day formatting:
day: "2-digit" -> day: (tomorrow.getDate().toString().padStart(2, '0'))

Now, who would like to come to the board and implement these improvements?

sagar-qa007
sagar-qa007 previously approved these changes Sep 27, 2024
@jacquesikot jacquesikot added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Sep 30, 2024
@jacquesikot jacquesikot merged commit 6f27959 into release Sep 30, 2024
71 of 73 checks passed
@jacquesikot jacquesikot deleted the fix/incorrect-selected-date-in-table-date-cell branch September 30, 2024 09:02
@github-actions github-actions bot added QA Needs QA attention QA Pod Issues under the QA Pod labels Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Community Reported issues reported by community members High This issue blocks a user from building or impacts a lot of users Needs More Info Needs additional information Needs Triaging Needs attention from maintainers to triage ok-to-test Required label for CI Production QA Pod Issues under the QA Pod QA Needs QA attention Table Inline Edit Issues related to inline editing Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: incorrect Unix Timestamp value when updating a Date type column
3 participants