From d7d179a7e704c4b658592ee858f2b2ec539dc506 Mon Sep 17 00:00:00 2001 From: DarkPhoenix2704 Date: Tue, 20 Feb 2024 07:16:19 +0000 Subject: [PATCH] fix(cal): some more fixes --- .../nc-gui/components/smartsheet/Toolbar.vue | 2 +- .../calendar/DayView/DateTimeField.vue | 22 +- .../smartsheet/calendar/MonthView.vue | 4 +- .../smartsheet/calendar/SideMenu.vue | 5 +- .../calendar/WeekView/DateTimeField.vue | 13 +- .../components/smartsheet/calendar/index.vue | 2 +- .../smartsheet/toolbar/CalendarRange.vue | 21 +- packages/nc-gui/composables/useSharedView.ts | 2 +- packages/nocodb/src/services/datas.service.ts | 2 +- .../pages/Dashboard/ViewSidebar/index.ts | 19 +- .../Dashboard/common/Toolbar/CalendarRange.ts | 9 +- tests/playwright/pages/Dashboard/index.ts | 54 +-- .../tests/db/views/viewCalendar.spec.ts | 320 ++++++++++++++++++ 13 files changed, 416 insertions(+), 59 deletions(-) create mode 100644 tests/playwright/tests/db/views/viewCalendar.spec.ts diff --git a/packages/nc-gui/components/smartsheet/Toolbar.vue b/packages/nc-gui/components/smartsheet/Toolbar.vue index 08f9ac852c..e72673ea85 100644 --- a/packages/nc-gui/components/smartsheet/Toolbar.vue +++ b/packages/nc-gui/components/smartsheet/Toolbar.vue @@ -51,7 +51,7 @@ const { allowCSVDownload } = useSharedView() diff --git a/packages/nc-gui/components/smartsheet/calendar/DayView/DateTimeField.vue b/packages/nc-gui/components/smartsheet/calendar/DayView/DateTimeField.vue index 69c1d4757b..4eca5b8bd3 100644 --- a/packages/nc-gui/components/smartsheet/calendar/DayView/DateTimeField.vue +++ b/packages/nc-gui/components/smartsheet/calendar/DayView/DateTimeField.vue @@ -43,6 +43,8 @@ const recordsAcrossAllRange = computed<{ } } }>(() => { + if (!calendarRange.value || !formattedData.value) return { record: [], count: {} } + const scheduleStart = dayjs(selectedDate.value).startOf('day') const scheduleEnd = dayjs(selectedDate.value).endOf('day') @@ -56,8 +58,6 @@ const recordsAcrossAllRange = computed<{ const perRecordHeight = 80 - if (!calendarRange.value) return { record: [], count: {} } - let recordsByRange: Array = [] calendarRange.value.forEach((range) => { @@ -170,7 +170,7 @@ const recordsAcrossAllRange = computed<{ let _startDate = startDate.clone() while (_startDate.isBefore(endDate)) { - const timeKey = _startDate.format('HH:mm') + const timeKey = _startDate.startOf('hour').format('HH:mm') if (!overlaps[timeKey]) { overlaps[timeKey] = { @@ -192,10 +192,10 @@ const recordsAcrossAllRange = computed<{ _startDate = _startDate.add(15, 'minutes') } - const topInPixels = (startDate.hour() + startDate.minute() / 60) * 80 + const topInPixels = (startDate.hour() + startDate.startOf('hour').minute() / 60) * 80 const heightInPixels = Math.max((endDate.diff(startDate, 'minute') / 60) * 80, perRecordHeight) - const finalTopInPixels = topInPixels + startHour + const finalTopInPixels = topInPixels + startHour * 2 style = { ...style, @@ -227,7 +227,7 @@ const recordsAcrossAllRange = computed<{ } } - const spacing = 1 + const spacing = 0.25 const widthPerRecord = (100 - spacing * (maxOverlaps - 1)) / maxOverlaps const leftPerRecord = (widthPerRecord + spacing) * overlapIndex @@ -282,7 +282,7 @@ const onResize = (event: MouseEvent) => { const ogEndDate = dayjs(resizeRecord.value.row[toCol.title!]) const ogStartDate = dayjs(resizeRecord.value.row[fromCol.title!]) - const hour = Math.floor(percentY * 24) + const hour = Math.max(Math.min(Math.floor(percentY * 24), 23), 0) if (resizeDirection.value === 'right') { let newEndDate = dayjs(selectedDate.value).add(hour, 'hour') @@ -377,9 +377,9 @@ const onDrag = (event: MouseEvent) => { if (!fromCol) return - const hour = Math.floor(percentY * 24) + const hour = Math.max(Math.min(Math.floor(percentY * 24), 23), 0) - const newStartDate = dayjs(selectedDate.value).add(hour, 'hour') + const newStartDate = dayjs(selectedDate.value).startOf('day').add(hour, 'hour') if (!newStartDate) return @@ -435,9 +435,9 @@ const stopDrag = (event: MouseEvent) => { const fromCol = dragRecord.value.rowMeta.range?.fk_from_col const toCol = dragRecord.value.rowMeta.range?.fk_to_col - const hour = Math.floor(percentY * 24) + const hour = Math.max(Math.min(Math.floor(percentY * 24), 23), 0) - const newStartDate = dayjs(selectedDate.value).add(hour, 'hour') + const newStartDate = dayjs(selectedDate.value).startOf('day').add(hour, 'hour') if (!newStartDate || !fromCol) return let endDate diff --git a/packages/nc-gui/components/smartsheet/calendar/MonthView.vue b/packages/nc-gui/components/smartsheet/calendar/MonthView.vue index e6bd8df472..8f2286dd01 100644 --- a/packages/nc-gui/components/smartsheet/calendar/MonthView.vue +++ b/packages/nc-gui/components/smartsheet/calendar/MonthView.vue @@ -720,11 +720,11 @@ const isDateSelected = (date: dayjs.Dayjs) => { v-for="(day, dateIndex) in week" :key="`${weekIndex}-${dateIndex}`" :class="{ - 'border-brand-500 border-1 border-r-1 border-b-1': + 'border-brand-500 border-1 !border-r-1 border-b-1': isDateSelected(day) || (focusedDate && dayjs(day).isSame(focusedDate, 'day')), '!text-gray-400': !isDayInPagedMonth(day), }" - class="text-right relative group text-sm h-full border-r-1 border-b-1 border-gray-200 font-medium hover:bg-gray-50 text-gray-800 bg-white" + class="text-right relative group last:border-r-0 text-sm h-full border-r-1 border-b-1 border-gray-200 font-medium hover:bg-gray-50 text-gray-800 bg-white" @click="selectDate(day)" >
diff --git a/packages/nc-gui/components/smartsheet/calendar/SideMenu.vue b/packages/nc-gui/components/smartsheet/calendar/SideMenu.vue index e1058a9111..eb55180f2b 100644 --- a/packages/nc-gui/components/smartsheet/calendar/SideMenu.vue +++ b/packages/nc-gui/components/smartsheet/calendar/SideMenu.vue @@ -209,6 +209,7 @@ const options = computed(() => { return [ { label: 'In selected date', value: 'selectedDate' }, { label: 'Without dates', value: 'withoutDates' }, + { label: 'In selected week', value: 'week' }, { label: 'All records', value: 'allRecords' }, ] } else { @@ -323,8 +324,8 @@ onUnmounted(() => { - - + + {{ option.label }} diff --git a/packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue b/packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue index 35f460cf6d..08c41ada1a 100644 --- a/packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue +++ b/packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue @@ -450,7 +450,7 @@ const onDrag = (event: MouseEvent) => { if (!fromCol) return const day = Math.floor(percentX * 7) - const hour = Math.floor(percentY * 24) + const hour = Math.max(Math.min(Math.floor(percentY * 24), 23), 0) const newStartDate = dayjs(selectedDateRange.value.start).add(day, 'day').add(hour, 'hour') if (!newStartDate) return @@ -510,7 +510,7 @@ const stopDrag = (event: MouseEvent) => { const toCol = dragRecord.value.rowMeta.range?.fk_to_col const day = Math.floor(percentX * 7) - const hour = Math.floor(percentY * 24) + const hour = Math.max(Math.min(Math.floor(percentY * 24), 24), 0) const newStartDate = dayjs(selectedDateRange.value.start).add(day, 'day').add(hour, 'hour') if (!newStartDate || !fromCol) return @@ -729,6 +729,9 @@ const viewMore = (hour: dayjs.Dayjs) => {
{{ dayjs(date[0]).format('DD ddd') }} @@ -740,10 +743,10 @@ const viewMore = (hour: dayjs.Dayjs) => { v-for="(hour, hourIndex) in date" :key="hourIndex" :class="{ - 'border-1 !border-brand-500': hour.isSame(selectedTime, 'hour'), + 'border-1 !border-brand-500 bg-gray-50': hour.isSame(selectedTime, 'hour'), '!border-l-0': date[0].day() === selectedDateRange.start?.day(), }" - class="text-center relative h-20 text-sm text-gray-500 w-full py-1 border-gray-200 first:border-l-none border-1 border-r-gray-50 border-t-gray-50 bg-gray-50" + class="text-center relative h-20 text-sm text-gray-500 w-full py-1 border-gray-200 first:border-l-none border-1 border-r-gray-50 border-t-gray-50" @click=" () => { selectedTime = hour @@ -751,7 +754,7 @@ const viewMore = (hour: dayjs.Dayjs) => { } " > - + {{ hour.format('h A') }} { - +
{{ headerText }} diff --git a/packages/nc-gui/components/smartsheet/toolbar/CalendarRange.vue b/packages/nc-gui/components/smartsheet/toolbar/CalendarRange.vue index 827cb8ccbe..5067f03a70 100644 --- a/packages/nc-gui/components/smartsheet/toolbar/CalendarRange.vue +++ b/packages/nc-gui/components/smartsheet/toolbar/CalendarRange.vue @@ -125,14 +125,20 @@ const removeRange = async (id: number) => {