-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
jacquesikot
merged 22 commits into
release
from
fix/incorrect-selected-date-in-table-date-cell
Sep 30, 2024
+440
−8
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
5ab2834
adjust moment inputFormat for Unix ms + allow validate unix ms in tra…
jacquesikot 1a4ebe9
add enum for MomentDateInputFormat
jacquesikot c97031f
Merge branch 'release' of https://github.com/appsmithorg/appsmith int…
jacquesikot 6b6b7a8
add base test
jacquesikot 94ef32d
improve test
jacquesikot da89194
improve Date_column_editing_2_spec
jacquesikot 2621b9a
complete test
jacquesikot 877f4ce
extract helper and fixtures in test case
jacquesikot 68facfb
improve transformDataPureFn - remove redundant !isNumber(value) check…
jacquesikot 33da955
improve transformDataPureFn - remove redundant !isNumber(value) check…
jacquesikot d6ec6ae
add base test for transformDataPureFn
jacquesikot 2ec53d1
complete transformDataPureFn unit test
jacquesikot 4b5f373
extract test fixtures
jacquesikot aca19a8
remove TODO comment
jacquesikot 36c32d6
add formattedDate to isNewRow
jacquesikot d8701f2
fix: extract momentAdjustedInputFormat into a function in DateCell
jacquesikot 17fa7e9
extend test to cover all table column date types
jacquesikot 2abc737
fix test case and move fixtures
jacquesikot 17e8f41
remove .only from test
jacquesikot dfe7b65
check unit test
jacquesikot b13f966
add helper in Table.ts
jacquesikot 6a3cae7
fix lint errors
jacquesikot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
149 changes: 149 additions & 0 deletions
149
...nt/cypress/e2e/Regression/ClientSide/Widgets/TableV2/Date_column_types_validation_spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import { tableDateColumnTypes } from "../../../../../fixtures/tableDateColumnTypes"; | ||
import { | ||
agHelper, | ||
entityExplorer, | ||
propPane, | ||
table, | ||
} from "../../../../../support/Objects/ObjectsCore"; | ||
|
||
import EditorNavigation, { | ||
EntityType, | ||
} from "../../../../../support/Pages/EditorNavigation"; | ||
|
||
describe( | ||
"Table widget date column type validation", | ||
{ tags: ["@tag.Widget", "@tag.Table"] }, | ||
() => { | ||
before(() => { | ||
entityExplorer.DragNDropWidget("tablewidgetv2", 350, 500); | ||
EditorNavigation.SelectEntityByName("Table1", EntityType.Widget); | ||
propPane.ToggleJSMode("Table data", true); | ||
propPane.UpdatePropertyFieldValue("Table data", tableDateColumnTypes); | ||
table.EditColumn("unixs", "v2"); | ||
}); | ||
|
||
beforeEach(() => { | ||
propPane.NavigateBackToPropertyPane(false); | ||
}); | ||
|
||
const setEditableDateFormats = (format: string) => { | ||
// Update date format property | ||
propPane.ToggleJSMode("Date format", true); | ||
propPane.UpdatePropertyFieldValue("Date format", format); | ||
|
||
// Update display format property | ||
propPane.ToggleJSMode("Display format", true); | ||
propPane.UpdatePropertyFieldValue("Display format", "YYYY-MM-DD"); | ||
|
||
// Toggle editable | ||
propPane.TogglePropertyState("Editable", "On"); | ||
}; | ||
|
||
const clickAndValidateDateCell = (row: number, column: number) => { | ||
// Click unix cell edit | ||
table.ClickOnEditIcon(row, column); | ||
|
||
// Click on specific date within | ||
agHelper.GetNClick( | ||
`${table._dateInputPopover} [aria-label='${table.getFormattedTomorrowDates().verboseFormat}']`, | ||
); | ||
|
||
// Check that date is set in column | ||
table | ||
.ReadTableRowColumnData(row, column, "v2") | ||
.then((val) => | ||
expect(val).to.equal(table.getFormattedTomorrowDates().isoFormat), | ||
); | ||
}; | ||
|
||
it("1. should allow inline editing of Unix Timestamp in seconds (unix/s)", () => { | ||
table.ChangeColumnType("unixs", "Date"); | ||
setEditableDateFormats("Epoch"); | ||
clickAndValidateDateCell(0, 0); | ||
}); | ||
|
||
it("2. should allow inline editing of Unix Timestamp in milliseconds (unix/ms)", () => { | ||
table.ChangeColumnType("unixms", "Date"); | ||
setEditableDateFormats("Milliseconds"); | ||
clickAndValidateDateCell(0, 1); | ||
}); | ||
|
||
it("3. should allow inline editing of date in YYYY-MM-DD format", () => { | ||
table.EditColumn("yyyymmdd", "v2"); | ||
setEditableDateFormats("YYYY-MM-DD"); | ||
clickAndValidateDateCell(0, 2); | ||
}); | ||
|
||
it("4. should allow inline editing of date in YYYY-MM-DD HH:mm format", () => { | ||
table.EditColumn("yyyymmddhhmm", "v2"); | ||
setEditableDateFormats("YYYY-MM-DD HH:mm"); | ||
clickAndValidateDateCell(0, 3); | ||
}); | ||
|
||
it("5. should allow inline editing of date in ISO 8601 format (YYYY-MM-DDTHH:mm:ss)", () => { | ||
table.EditColumn("iso8601", "v2"); | ||
setEditableDateFormats("YYYY-MM-DDTHH:mm:ss"); | ||
clickAndValidateDateCell(0, 4); | ||
}); | ||
|
||
it("6. should allow inline editing of date in YYYY-MM-DD HH:mm format", () => { | ||
table.EditColumn("yyyymmddTHHmmss", "v2"); | ||
setEditableDateFormats("YYYY-MM-DD HH:mm"); | ||
clickAndValidateDateCell(0, 5); | ||
}); | ||
|
||
it("7. should allow inline editing of date in 'do MMM yyyy' format", () => { | ||
table.ChangeColumnType("yyyymmddhhmmss", "Date"); | ||
setEditableDateFormats("YYYY-MM-DDTHH:mm:ss"); | ||
clickAndValidateDateCell(0, 6); | ||
}); | ||
|
||
it("8. should allow inline editing of date in DD/MM/YYYY format", () => { | ||
table.ChangeColumnType("doMMMyyyy", "Date"); | ||
setEditableDateFormats("Do MMM YYYY"); | ||
clickAndValidateDateCell(0, 7); | ||
}); | ||
|
||
it("9. should allow inline editing of date in DD/MM/YYYY HH:mm format", () => { | ||
table.EditColumn("ddmmyyyy", "v2"); | ||
setEditableDateFormats("DD/MM/YYYY"); | ||
clickAndValidateDateCell(0, 8); | ||
}); | ||
|
||
it("10. should allow inline editing of date in LLL (Month Day, Year Time) format", () => { | ||
table.EditColumn("ddmmyyyyhhmm", "v2"); | ||
setEditableDateFormats("DD/MM/YYYY HH:mm"); | ||
clickAndValidateDateCell(0, 9); | ||
}); | ||
|
||
it("11. should allow inline editing of date in LL (Month Day, Year) format", () => { | ||
table.EditColumn("lll", "v2"); | ||
setEditableDateFormats("LLL"); | ||
clickAndValidateDateCell(0, 10); | ||
}); | ||
|
||
it("12. should allow inline editing of date in 'D MMMM, YYYY' format", () => { | ||
table.EditColumn("ll", "v2"); | ||
setEditableDateFormats("LL"); | ||
clickAndValidateDateCell(0, 11); | ||
}); | ||
|
||
it("13. should allow inline editing of date in 'h:mm A D MMMM, YYYY' format", () => { | ||
table.EditColumn("dmmmmyyyy", "v2"); | ||
setEditableDateFormats("D MMMM, YYYY"); | ||
clickAndValidateDateCell(0, 12); | ||
}); | ||
|
||
it("14. should allow inline editing of date in MM-DD-YYYY format", () => { | ||
table.EditColumn("hmmAdmmmmyyyy", "v2"); | ||
setEditableDateFormats("H:mm A D MMMM, YYYY"); | ||
clickAndValidateDateCell(0, 13); | ||
}); | ||
|
||
it("15. should allow inline editing of date in DD-MM-YYYY format", () => { | ||
table.EditColumn("mm1dd1yyyy", "v2"); | ||
setEditableDateFormats("MM-DD-YYYY"); | ||
clickAndValidateDateCell(0, 14); | ||
}); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export const tableDateColumnTypes = ` | ||
{{ | ||
[ | ||
{ | ||
"unixs": 1727212200, | ||
"unixms": 1727212200000, | ||
"yyyymmdd": "2024-09-25", | ||
"yyyymmddhhmm": "2024-09-25 14:30", | ||
iso8601: "2024-09-25T14:30:00.000Z", | ||
"yyyymmddTHHmmss": "2024-09-25T14:30:00", | ||
"yyyymmddhhmmss": "2024-09-25 02: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", | ||
"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", | ||
}, | ||
] | ||
}} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
app/client/src/widgets/TableWidgetV2/widget/reactTableUtils/TransformDataPureFn.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import type { ReactTableColumnProps } from "widgets/TableWidgetV2/component/Constants"; | ||
import { | ||
columns, | ||
columnsNonDate, | ||
expectedDataNonDate, | ||
tableDataNonDate, | ||
} from "./fixtures"; | ||
import { transformDataPureFn } from "./transformDataPureFn"; | ||
|
||
describe("transformDataPureFn", () => { | ||
it("should handle invalid date values", () => { | ||
const invalidTableData = [ | ||
{ | ||
epoch: "invalid_epoch", | ||
milliseconds: "invalid_milliseconds", | ||
iso_8601: "invalid_iso_8601", | ||
yyyy_mm_dd: "invalid_date", | ||
lll: "invalid_date", | ||
}, | ||
]; | ||
|
||
const expectedInvalidData = [ | ||
{ | ||
epoch: "Invalid date", | ||
milliseconds: "Invalid date", | ||
iso_8601: "8601-01-01", | ||
yyyy_mm_dd: "Invalid date", | ||
lll: "Invalid date", | ||
}, | ||
]; | ||
|
||
const result = transformDataPureFn( | ||
invalidTableData, | ||
columns as ReactTableColumnProps[], | ||
); | ||
|
||
expect(result).toEqual(expectedInvalidData); | ||
}); | ||
|
||
it("should return an empty array when tableData is empty", () => { | ||
const result = transformDataPureFn([], columns as ReactTableColumnProps[]); | ||
|
||
expect(result).toEqual([]); | ||
}); | ||
|
||
it("should not transform non-date data", () => { | ||
const result = transformDataPureFn( | ||
tableDataNonDate, | ||
columnsNonDate as ReactTableColumnProps[], | ||
); | ||
|
||
expect(result).toEqual(expectedDataNonDate); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:Let's rename it to
getFormattedTomorrowDateStrings
to be more specific about returning multiple formats.We should use JSDoc comments for better documentation. Here's an example:
padStart
for consistent day formatting:Now, who would like to come to the board and implement these improvements?