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

Open
wants to merge 7 commits into
base: release
Choose a base branch
from

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/10960871756
Commit: 2621b9a
Cypress dashboard.
Tags: @tag.Sanity, @tag.Binding, @tag.Table, @tag.Datepicker
Spec:


Fri, 20 Sep 2024 15:30:27 UTC

Communication

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

  • Yes
  • No

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.
  • Bug Fixes

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

    • Added clarity on date formatting capabilities and input handling in the table widget.

@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 Added a test case to validate Unix timestamps in milliseconds for date column editing.
app/client/src/widgets/TableWidgetV2/component/cellComponents/DateCell.tsx Modified date formatting logic to handle millisecond input formats more flexibly.
app/client/src/widgets/TableWidgetV2/constants.ts Introduced a new enumeration MomentDateInputFormat with a member for milliseconds.
app/client/src/widgets/TableWidgetV2/widget/reactTableUtils/transformDataPureFn.tsx Refined validation logic for date inputs, specifically handling non-millisecond formats.

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

Bug

Poem

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! 🌟


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/src/widgets/TableWidgetV2/constants.ts (1)

222-224: New enum MomentDateInputFormat added for Moment.js timestamp format

Alright class, let's take a look at this new enum that's been introduced. It seems we have a MomentDateInputFormat enum with a MILLISECONDS member assigned the value "x".

Now, it's important to note that we already have a DateInputFormat enum with a MILLISECONDS member, but with a different string value. While this new enum itself doesn't change any existing code, we need to be cautious about the potential for confusion due to the similar naming.

Can you explain the specific use case for introducing this new enum and constant? It would be helpful for the class to understand the context and how it fits into the overall solution.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1cf043c and 2621b9a.

Files selected for processing (4)
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/Date_column_editing_2_spec.ts (1 hunks)
  • app/client/src/widgets/TableWidgetV2/component/cellComponents/DateCell.tsx (3 hunks)
  • app/client/src/widgets/TableWidgetV2/constants.ts (1 hunks)
  • app/client/src/widgets/TableWidgetV2/widget/reactTableUtils/transformDataPureFn.tsx (1 hunks)
Additional context used
Path-based instructions (1)
app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/Date_column_editing_2_spec.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 not posted (4)
app/client/src/widgets/TableWidgetV2/widget/reactTableUtils/transformDataPureFn.tsx (1)

47-50: Great work on refining the date validation logic! 👍

Class, let's take a closer look at this code segment. The condition !isNumber(value) && type !== DateInputFormat.MILLISECONDS is checking if the value is not a number and the type is not DateInputFormat.MILLISECONDS. If both conditions are true, it sets isValidDate to false.

This change ensures that only non-millisecond date formats are subjected to the number check, enhancing the specificity of the validation logic for different date formats. It prevents incorrect validation of millisecond date formats.

Keep up the excellent work in improving the accuracy of date validation! 🎉

app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/Date_column_editing_2_spec.ts (1)

96-203: Great job on this new test case, class! 👏

The test case is well-structured and follows a logical sequence of steps to verify the handling of Unix timestamps in milliseconds for the date column editing functionality. It covers all the essential aspects, including updating the table data, changing the column type, configuring the date format properties, and performing inline editing.

I appreciate that you've used appropriate locators and assertions to interact with the table widget and validate the expected behavior. The code also adheres to the Cypress best practices and coding guidelines, such as using locator variables, avoiding unnecessary waits, and performing assertions.

Keep up the excellent work! 🌟

app/client/src/widgets/TableWidgetV2/component/cellComponents/DateCell.tsx (2)

12-16: Excellent work importing the necessary constants! 👍

The DateInputFormat and MomentDateInputFormat imports from the widgets/TableWidgetV2/constants module are essential for the changes made in the onDateSelected function. Keep up the good work!


Line range hint 225-247: Great job enhancing the date formatting logic! 🎉

The introduction of the momentAdjustedInputFormat variable and the conditional assignment based on the inputFormat value is a clever way to handle specific formatting requirements for millisecond input formats. By mapping DateInputFormat.MILLISECONDS to MomentDateInputFormat.MILLISECONDS, you ensure that the date is formatted correctly using the appropriate moment format string.

Using momentAdjustedInputFormat in the date formatting logic instead of directly using inputFormat provides flexibility and allows for proper handling of different input format types. This change will definitely improve the accuracy and consistency of date formatting in the DateCell component.

Well done on implementing this enhancement! Your attention to detail and understanding of the formatting requirements is commendable. Keep up the excellent work! 👏

// Get string format for tomorrow date - Sat Sep 21 2024 format
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
const formattedTomorrowDateVerbose = tomorrow
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we please add this in helper function with better parameters to make a good usage of it?

propPane.UpdatePropertyFieldValue(
"Table data",
`
{{
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we please existing fixture here? or atleast add this in fixture folder and update in test.

momentAdjustedInputFormat = MomentDateInputFormat.MILLISECONDS;
const formattedDate = date
? moment(date).format(momentAdjustedInputFormat)
: "";
Copy link
Contributor

Choose a reason for hiding this comment

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

Query : Blank value return means error will come or what will be the output?

Copy link
Contributor

Choose a reason for hiding this comment

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

empty value will come. essentially, the date itself is not provided, it is a falsey value(null/undefined/""/0)

if (
type !== DateInputFormat.EPOCH &&
type !== DateInputFormat.MILLISECONDS
) {
inputFormat = type;
moment(value as MomentInput, inputFormat);
} else if (!isNumber(value)) {
} else if (
Copy link
Contributor

Choose a reason for hiding this comment

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

This condition and the condition above is confusing, can we simplify this logic?
Also, the top of this function there is a comment stating the need to unit test this, while we are at it, lets take care of that as well.
One suggestion, right now the variable type is of any, which is not ideal, either declare an interface for it, or explain in comments what all values can it assume.

Comment on lines +243 to +244
if (inputFormat === DateInputFormat.MILLISECONDS)
momentAdjustedInputFormat = MomentDateInputFormat.MILLISECONDS;
Copy link
Contributor

Choose a reason for hiding this comment

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

What is rationale behind this condition? Its unclear; add comment.
also, we have an if statement, lets put it inside block scope {}.

@jacquesikot jacquesikot added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Sep 20, 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 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