Browse Source

fix(nc-gui): month view some edge case fix

pull/7611/head
DarkPhoenix2704 9 months ago
parent
commit
06ae92a0df
  1. 35
      packages/nc-gui/components/smartsheet/calendar/MonthView.vue

35
packages/nc-gui/components/smartsheet/calendar/MonthView.vue

@ -85,7 +85,20 @@ const recordsToDisplay = computed<{
const startCol = range.fk_from_col const startCol = range.fk_from_col
const endCol = range.fk_to_col const endCol = range.fk_to_col
const sortedFormattedData = [...formattedData.value].sort((a, b) => { const sortedFormattedData = [...formattedData.value]
.filter((record) => {
const fromDate = record.row[startCol?.title] ? dayjs(record.row[startCol.title]) : null
if (startCol && endCol) {
const fromDate = record.row[startCol.title] ? dayjs(record.row[startCol.title]) : null
const toDate = record.row[endCol.title] ? dayjs(record.row[endCol.title]) : null
return fromDate && toDate && !toDate.isBefore(fromDate)
} else if (startCol && !endCol) {
return !!fromDate
}
return false
})
.sort((a, b) => {
if (startCol && endCol) { if (startCol && endCol) {
const startA = dayjs(a.row[startCol.title]) const startA = dayjs(a.row[startCol.title])
const endA = dayjs(a.row[endCol.title]) const endA = dayjs(a.row[endCol.title])
@ -113,7 +126,7 @@ const recordsToDisplay = computed<{
const weekIndex = dates.value.findIndex((week) => week.some((day) => dayjs(day).isSame(startDate, 'day'))) const weekIndex = dates.value.findIndex((week) => week.some((day) => dayjs(day).isSame(startDate, 'day')))
const dayIndex = dates.value[weekIndex].findIndex((day) => { const dayIndex = (dates.value[weekIndex] ?? []).findIndex((day) => {
return dayjs(day).isSame(startDate, 'day') return dayjs(day).isSame(startDate, 'day')
}) })
@ -147,7 +160,6 @@ const recordsToDisplay = computed<{
} else if (startCol && endCol) { } else if (startCol && endCol) {
const startDate = dayjs(record.row[startCol.title]) const startDate = dayjs(record.row[startCol.title])
const endDate = dayjs(record.row[endCol.title]) const endDate = dayjs(record.row[endCol.title])
let currentWeekStart = startDate.startOf('week') let currentWeekStart = startDate.startOf('week')
while (currentWeekStart.isBefore(endDate)) { while (currentWeekStart.isBefore(endDate)) {
const currentWeekEnd = currentWeekStart.endOf('week') const currentWeekEnd = currentWeekStart.endOf('week')
@ -155,7 +167,7 @@ const recordsToDisplay = computed<{
const recordEnd = currentWeekEnd.isAfter(endDate) ? endDate : currentWeekEnd const recordEnd = currentWeekEnd.isAfter(endDate) ? endDate : currentWeekEnd
let day = recordStart.clone() let day = recordStart.clone()
while (day.isBefore(recordEnd) || day.isSame(recordEnd, 'day')) { while (day.isSameOrBefore(recordEnd)) {
const dateKey = day.format('YYYY-MM-DD') const dateKey = day.format('YYYY-MM-DD')
if (!recordsInDay[dateKey]) { if (!recordsInDay[dateKey]) {
@ -180,8 +192,15 @@ const recordsToDisplay = computed<{
for (let i = 0; i < (dates.value[weekIndex] ?? []).length; i++) { for (let i = 0; i < (dates.value[weekIndex] ?? []).length; i++) {
const day = dates.value[weekIndex][i] const day = dates.value[weekIndex][i]
const dateKey = dayjs(day).format('YYYY-MM-DD') const dateKey = dayjs(day).format('YYYY-MM-DD')
if (!recordsInDay[dateKey]) continue if (!recordsInDay[dateKey]) {
recordsInDay[dateKey] = {
count: 0,
overflow: false,
overflowCount: 0,
}
}
const recordIndex = recordsInDay[dateKey].count const recordIndex = recordsInDay[dateKey].count
maxRecordCount = Math.max(maxRecordCount, recordIndex) maxRecordCount = Math.max(maxRecordCount, recordIndex)
@ -206,10 +225,14 @@ const recordsToDisplay = computed<{
let position = 'rounded' let position = 'rounded'
const isStartMonthBeforeCurrentWeek = startDate.isBefore(selectedMonth.value, 'month')
if (startDate.isSame(currentWeekStart, 'week') && endDate.isSame(currentWeekEnd, 'week')) { if (startDate.isSame(currentWeekStart, 'week') && endDate.isSame(currentWeekEnd, 'week')) {
position = 'rounded' position = 'rounded'
} else if (startDate.isSame(recordStart, 'week')) { } else if (startDate.isSame(recordStart, 'week')) {
position = 'leftRounded' if (isStartMonthBeforeCurrentWeek) {
position = 'rightRounded'
} else position = 'leftRounded'
} else if (endDate.isSame(currentWeekEnd, 'week')) { } else if (endDate.isSame(currentWeekEnd, 'week')) {
position = 'rightRounded' position = 'rightRounded'
} else { } else {

Loading…
Cancel
Save