From 560cf9fc62eacc9ee1048549f182346f2f125d15 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Sat, 3 Dec 2022 14:20:52 +0800 Subject: [PATCH 01/29] feat(nc-gui): add time formats --- packages/nc-gui/utils/dateTimeUtils.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/nc-gui/utils/dateTimeUtils.ts b/packages/nc-gui/utils/dateTimeUtils.ts index 8736221840..6f58db18c5 100644 --- a/packages/nc-gui/utils/dateTimeUtils.ts +++ b/packages/nc-gui/utils/dateTimeUtils.ts @@ -5,17 +5,19 @@ export const timeAgo = (date: any) => { } export const dateFormats = [ + 'YYYY-MM-DD', + 'YYYY/MM/DD', 'DD-MM-YYYY', 'MM-DD-YYYY', - 'YYYY-MM-DD', 'DD/MM/YYYY', 'MM/DD/YYYY', - 'YYYY/MM/DD', 'DD MM YYYY', 'MM DD YYYY', 'YYYY MM DD', ] +export const timeFormats = ['HH:mm', 'HH:mm:ss', 'HH:mm:ss.SSS'] + export const handleTZ = (val: any) => { if (!val) { return @@ -60,7 +62,7 @@ export function getDateFormat(v: string) { export function getDateTimeFormat(v: string) { for (const format of dateFormats) { - for (const timeFormat of ['HH:mm', 'HH:mm:ss', 'HH:mm:ss.SSS']) { + for (const timeFormat of timeFormats) { const dateTimeFormat = `${format} ${timeFormat}` if (dayjs(v, dateTimeFormat, true).isValid() as any) { return dateTimeFormat From 0295f4ca7163a93972173efdaed447439a7e02e2 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Sat, 3 Dec 2022 14:21:04 +0800 Subject: [PATCH 02/29] feat(nc-gui): add LazySmartsheetColumnDateTimeOptions for DateTime --- packages/nc-gui/components/smartsheet/column/EditOrAdd.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/nc-gui/components/smartsheet/column/EditOrAdd.vue b/packages/nc-gui/components/smartsheet/column/EditOrAdd.vue index f7a63fe1de..cfe70bae07 100644 --- a/packages/nc-gui/components/smartsheet/column/EditOrAdd.vue +++ b/packages/nc-gui/components/smartsheet/column/EditOrAdd.vue @@ -177,6 +177,7 @@ useEventListener('keydown', (e: KeyboardEvent) => { + Date: Sat, 3 Dec 2022 14:21:41 +0800 Subject: [PATCH 03/29] feat(nc-gui): add DateTimeOptions --- .../smartsheet/column/DateTimeOptions.vue | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 packages/nc-gui/components/smartsheet/column/DateTimeOptions.vue diff --git a/packages/nc-gui/components/smartsheet/column/DateTimeOptions.vue b/packages/nc-gui/components/smartsheet/column/DateTimeOptions.vue new file mode 100644 index 0000000000..6b0f8e25e6 --- /dev/null +++ b/packages/nc-gui/components/smartsheet/column/DateTimeOptions.vue @@ -0,0 +1,46 @@ + + + From 55fd0fee74ce814cb0a4ea42a741182433b57f15 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Sat, 3 Dec 2022 14:22:09 +0800 Subject: [PATCH 04/29] feat(nc-gui): format DateTime data --- .../nc-gui/components/cell/DateTimePicker.vue | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/nc-gui/components/cell/DateTimePicker.vue b/packages/nc-gui/components/cell/DateTimePicker.vue index 8819d23ce7..ffd88acc0c 100644 --- a/packages/nc-gui/components/cell/DateTimePicker.vue +++ b/packages/nc-gui/components/cell/DateTimePicker.vue @@ -2,10 +2,13 @@ import dayjs from 'dayjs' import { ActiveCellInj, + ColumnInj, ReadonlyInj, + dateFormats, inject, isDrawerOrModalExist, ref, + timeFormats, useProject, useSelectedCellKeyupListener, watch, @@ -28,9 +31,15 @@ const active = inject(ActiveCellInj, ref(false)) const editable = inject(EditModeInj, ref(false)) +const columnMeta = inject(ColumnInj, null)! + let isDateInvalid = $ref(false) -const dateFormat = isMysql ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD HH:mm:ssZ' +const dateTimeFormat = $computed(() => { + const dateFormat = columnMeta?.value?.meta?.date_format ?? dateFormats[0] + const timeFormat = columnMeta?.value?.meta?.time_format ?? timeFormats[0] + return `${dateFormat} ${timeFormat}${!isMysql ? 'Z' : ''}` +}) let localState = $computed({ get() { @@ -52,7 +61,7 @@ let localState = $computed({ } if (val.isValid()) { - emit('update:modelValue', val?.format(dateFormat)) + emit('update:modelValue', val?.format(dateTimeFormat)) } }, }) @@ -163,7 +172,7 @@ useSelectedCellKeyupListener(active, (e: KeyboardEvent) => { :show-time="true" :bordered="false" class="!w-full !px-0 !border-none" - format="YYYY-MM-DD HH:mm" + :format="dateTimeFormat" :placeholder="isDateInvalid ? 'Invalid date' : ''" :allow-clear="!readOnly && !localState && !isPk" :input-read-only="true" From 164f0c9f8eb82024cd95cfabfe24ea648c3c9273 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Sat, 3 Dec 2022 16:27:53 +0800 Subject: [PATCH 05/29] feat(playwrights): add DateTimeCell.ts --- .../Dashboard/common/Cell/DateTimeCell.ts | 36 +++++++++++++++++++ .../pages/Dashboard/common/Cell/index.ts | 3 ++ 2 files changed, 39 insertions(+) create mode 100644 tests/playwright/pages/Dashboard/common/Cell/DateTimeCell.ts diff --git a/tests/playwright/pages/Dashboard/common/Cell/DateTimeCell.ts b/tests/playwright/pages/Dashboard/common/Cell/DateTimeCell.ts new file mode 100644 index 0000000000..9d876726cb --- /dev/null +++ b/tests/playwright/pages/Dashboard/common/Cell/DateTimeCell.ts @@ -0,0 +1,36 @@ +import { CellPageObject } from '.'; +import BasePage from '../../../Base'; + +export class DateTimeCellPageObject extends BasePage { + readonly cell: CellPageObject; + + constructor(cell: CellPageObject) { + super(cell.rootPage); + this.cell = cell; + } + + get({ index, columnHeader }: { index?: number; columnHeader: string }) { + return this.cell.get({ index, columnHeader }); + } + + async open({ index, columnHeader }: { index: number; columnHeader: string }) { + await this.cell.dblclick({ + index, + columnHeader, + }); + } + + async selectDateTime({ + // date in format `YYYY-MM-DD` + // time in format 'HH:mm' + dateTime, + }: { + dateTime: string; + }) { + await this.rootPage.locator(`td[title="${dateTime}"]`).click(); + } + + async close() { + await this.rootPage.keyboard.press('Escape'); + } +} diff --git a/tests/playwright/pages/Dashboard/common/Cell/index.ts b/tests/playwright/pages/Dashboard/common/Cell/index.ts index 22052a2ca6..92fdf7a2f2 100644 --- a/tests/playwright/pages/Dashboard/common/Cell/index.ts +++ b/tests/playwright/pages/Dashboard/common/Cell/index.ts @@ -7,6 +7,7 @@ import { SharedFormPage } from '../../../SharedForm'; import { CheckboxCellPageObject } from './CheckboxCell'; import { RatingCellPageObject } from './RatingCell'; import { DateCellPageObject } from './DateCell'; +import { DateTimeCellPageObject } from './DateTimeCell'; export class CellPageObject extends BasePage { readonly parent: GridPage | SharedFormPage; @@ -15,6 +16,7 @@ export class CellPageObject extends BasePage { readonly checkbox: CheckboxCellPageObject; readonly rating: RatingCellPageObject; readonly date: DateCellPageObject; + readonly dateTime: DateTimeCellPageObject; constructor(parent: GridPage | SharedFormPage) { super(parent.rootPage); @@ -24,6 +26,7 @@ export class CellPageObject extends BasePage { this.checkbox = new CheckboxCellPageObject(this); this.rating = new RatingCellPageObject(this); this.date = new DateCellPageObject(this); + this.dateTime = new DateTimeCellPageObject(this); } get({ index, columnHeader }: { index?: number; columnHeader: string }): Locator { From beb9c3bbf2e73ed211667e59ca91d9c8a0e07115 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Sat, 3 Dec 2022 20:07:01 +0800 Subject: [PATCH 06/29] refactor(nc-gui): add class to select and remove unnecessary div --- .../smartsheet/column/DateTimeOptions.vue | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/column/DateTimeOptions.vue b/packages/nc-gui/components/smartsheet/column/DateTimeOptions.vue index 6b0f8e25e6..152b504fd4 100644 --- a/packages/nc-gui/components/smartsheet/column/DateTimeOptions.vue +++ b/packages/nc-gui/components/smartsheet/column/DateTimeOptions.vue @@ -22,24 +22,16 @@ if (!vModel.value.meta?.time_format) {