Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

fix: reltime related issues

DarkPhoenix2704165a231abb88
diff --git a/packages/nc-gui/components/smartsheet/calendar/DateTimeSpanningContainer.vue b/packages/nc-gui/components/smartsheet/calendar/DateTimeSpanningContainer.vue
index 224d6f4ea2..9c2075b9a3 100644
--- a/packages/nc-gui/components/smartsheet/calendar/DateTimeSpanningContainer.vue
+++ b/packages/nc-gui/components/smartsheet/calendar/DateTimeSpanningContainer.vue
@@ -121,7 +121,9 @@ const calendarData = computed(() => {
const id = record.rowMeta.id ?? generateRandomNumber()
const startDate = timezoneDayjs.timezonize(record.row[fk_from_col.title!])
- const endDate = timezoneDayjs.timezonize(record.row[fk_to_col.title!])
+ const endDate = record.row[fk_to_col.title!]
+ ? timezoneDayjs.timezonize(record.row[fk_to_col.title!])
+ : startDate.endOf('day')
const startDayIndex = Math.max(startDate.diff(viewStartDate.value, 'day'), 0)
const endDayIndex = Math.min(endDate.diff(viewStartDate.value, 'day'), maxVisibleDays.value - 1)
diff --git a/packages/nc-gui/components/smartsheet/calendar/SideMenu.vue b/packages/nc-gui/components/smartsheet/calendar/SideMenu.vue
index d1845f54f4..2e6432bc0c 100644
--- a/packages/nc-gui/components/smartsheet/calendar/SideMenu.vue
+++ b/packages/nc-gui/components/smartsheet/calendar/SideMenu.vue
@@ -525,27 +525,8 @@ const selectOption = (option) => {
<LazySmartsheetRow v-for="(record, rowIndex) in renderData" :key="rowIndex" :row="record">
<LazySmartsheetCalendarSideRecordCard
:draggable="sideBarFilterOption === 'withoutDates' && activeCalendarView !== 'year'"
- :from-date="
- record.rowMeta.range?.fk_from_col
- ? calDataType === UITypes.Date
- ? timezoneDayjs.timezonize(record.row[record.rowMeta.range.fk_from_col.title!]).format('D MMM')
- : timezoneDayjs.timezonize(record.row[record.rowMeta.range.fk_from_col.title!]).format('D MMM β€’ h:mm A')
- : null
- "
- :invalid="
- record.rowMeta.range!.fk_to_col &&
- timezoneDayjs.timezonize(record.row[record.rowMeta.range!.fk_from_col.title!]).isAfter(
- timezoneDayjs.timezonize(record.row[record.rowMeta.range!.fk_to_col.title!]),
- )
- "
:row="record"
- :to-date="
- record.rowMeta.range!.fk_to_col && dayjs(record.row[record.rowMeta.range!.fk_to_col.title!])?.isValid()
- ? calDataType === UITypes.Date
- ? timezoneDayjs.timezonize(record.row[record.rowMeta.range!.fk_to_col.title!]).format('DD MMM')
- : timezoneDayjs.timezonize(record.row[record.rowMeta.range!.fk_to_col.title!]).format('DD MMM β€’ HH:mm A')
- : null
- "
+ :cal-data-type="calDataType"
data-testid="nc-sidebar-record-card"
@click="emit('expandRecord', record)"
@dragstart="dragStart($event, record)"
diff --git a/packages/nc-gui/components/smartsheet/calendar/SideRecordCard.vue b/packages/nc-gui/components/smartsheet/calendar/SideRecordCard.vue
index 23e793d0d8..b37b72623c 100644
--- a/packages/nc-gui/components/smartsheet/calendar/SideRecordCard.vue
+++ b/packages/nc-gui/components/smartsheet/calendar/SideRecordCard.vue
@@ -1,23 +1,104 @@
<script lang="ts" setup>
+import dayjs from 'dayjs'
+
interface Props {
row?: Record<string, any>
- fromDate?: string
- toDate?: string
color?: string
showDate?: boolean
- invalid?: boolean
+ calDataType?: string // UITypes.Date or other
}
const props = withDefaults(defineProps<Props>(), {
- fromDate: '',
color: 'gray',
showDate: true,
- invalid: false,
})
const rowColorInfo = computed(() => {
return extractRowBackgroundColorStyle(props.row as Row)
})
+
+const { timezoneDayjs } = useCalendarViewStoreOrThrow()
+
+// Extract range configuration
+const range = computed(() => props.row?.rowMeta?.range)
+const fromCol = computed(() => range.value?.fk_from_col)
+const toCol = computed(() => range.value?.fk_to_col)
+
+// Extract raw date values
+const fromDateRaw = computed(() => (fromCol.value ? props.row?.row?.[fromCol.value.title!] : null))
+const toDateRaw = computed(() => (toCol.value ? props.row?.row?.[toCol.value.title!] : null))
+
+// Format dates for display
+const fromDate = computed(() => {
+ if (!fromDateRaw.value || !fromCol.value) return null
+
+ const format = props.calDataType === 'Date' ? 'D MMM' : 'D MMM β€’ h:mm A'
+ return timezoneDayjs.timezonize(fromDateRaw.value).format(format)
+})
+
+const toDate = computed(() => {
+ if (!toDateRaw.value || !toCol.value || !dayjs(toDateRaw.value)?.isValid()) return null
+
+ const format = props.calDataType === 'Date' ? 'DD MMM' : 'DD MMM β€’ HH:mm A'
+ return timezoneDayjs.timezonize(toDateRaw.value).format(format)
+})
+
+// Validation logic
+const missingFromDate = computed(() => fromCol.value && !fromDateRaw.value)
+const missingToDate = computed(() => toCol.value && !toDateRaw.value)
+const dateOrderError = computed(() => {
+ if (!fromCol.value || !toCol.value || !fromDateRaw.value || !toDateRaw.value) return false
+ return timezoneDayjs.timezonize(fromDateRaw.value).isAfter(timezoneDayjs.timezonize(toDateRaw.value))
+})
+
+const invalid = computed(() => missingFromDate.value || missingToDate.value || dateOrderError.value)
+
+const errorInfo = computed(() => {
+ const missingFromDate = fromCol.value && !fromDateRaw.value
+
+ const missingToDate = toCol.value && !toDateRaw.value
+
+ const dateOrderError =
+ fromCol.value &&
+ toCol.value &&
+ fromDateRaw.value &&
+ toDateRaw.value &&
+ timezoneDayjs.timezonize(fromDateRaw.value).isAfter(timezoneDayjs.timezonize(toDateRaw.value))
+
+ if (dateOrderError) {
+ return {
+ message: 'Date Error',
+ tooltip:
+ "Record with end date before the start date won't be displayed in the calendar. Update the end date to display the record.",
+ }
+ }
+
+ if (missingFromDate && missingToDate) {
+ return {
+ message: 'Missing Dates',
+ tooltip: 'Both start date and end date are required for this record to be displayed in the calendar.',
+ }
+ }
+
+ if (missingFromDate) {
+ return {
+ message: 'Missing Start Date',
+ tooltip: 'Start date is required for this record to be displayed in the calendar.',
+ }
+ }
+
+ if (missingToDate) {
+ return {
+ message: 'Missing End Date',
+ tooltip: 'End date is required for this record to be displayed properly in the calendar.',
+ }
+ }
+
+ return {
+ message: 'Invalid Record',
+ tooltip: 'This record has errors and may not display correctly in the calendar.',
+ }
+})
</script>
<template>
@@ -34,7 +115,7 @@ const rowColorInfo = computed(() => {
'bg-yellow-500': props.color === 'yellow',
'bg-pink-500': props.color === 'pink',
'bg-purple-500': props.color === 'purple',
- 'bg-gray-900': color === 'gray',
+ 'bg-gray-900': props.color === 'gray',
}"
class="block h-12 w-1"
:style="rowColorInfo.rowLeftBorderColor"
@@ -53,23 +134,16 @@ const rowColorInfo = computed(() => {
<NcBadge color="red" :border="false" class="!h-5">
<div class="flex items-center gap-1">
<GeneralIcon icon="warning" class="text-nc-content-red-medium !h-4 !w-4" />
-
- <span class="font-normal text-xs"> Date Error </span>
+ <span class="font-normal text-xs">{{ errorInfo.message }}</span>
</div>
</NcBadge>
<template #title>
- Record with end date before the start date won't be displayed in the calendar. Update the end date to display the
- record.
+ {{ errorInfo.tooltip }}
</template>
</NcTooltip>
- <NcTooltip
- v-if="showDate"
- show-on-truncate-only
- class="text-xs font-medium truncate max-w-58 leading-4 text-nc-content-gray-subtle2"
- >
- {{ fromDate }} {{ toDate ? ` - ${toDate}` : '' }}
- <template #title> {{ fromDate }} {{ toDate ? ` - ${toDate}` : '' }} </template>
- </NcTooltip>
+ <div v-if="showDate" class="text-xs font-medium truncate max-w-58 leading-4 text-nc-content-gray-subtle2">
+ {{ fromDate }}{{ toDate ? ` - ${toDate}` : '' }}
+ </div>
</div>
</div>
</div>
diff --git a/packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue b/packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue
index 659399224a..7dcb8c2e3e 100644
--- a/packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue
+++ b/packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue
@@ -336,7 +336,7 @@ const recordsAcrossAllRange = computed<{
.filter((record) => {
if (fromCol && toCol) {
const fromDate = timezoneDayjs.timezonize(record.row[fromCol.title!])
- const toDate = timezoneDayjs.timezonize(record.row[toCol.title!])
+ const toDate = record.row[toCol.title!] ? timezoneDayjs.timezonize(record.row[toCol.title!]) : fromDate.add(1, 'hour')
if (fromDate.isValid() && toDate.isValid()) {
const isMultiDay = !fromDate.isSame(toDate, 'day')
@@ -359,7 +359,9 @@ const recordsAcrossAllRange = computed<{
if (fromCol && toCol) {
const { startDate, endDate } = calculateNewDates({
startDate: timezoneDayjs.timezonize(record.row[fromCol.title!]),
- endDate: timezoneDayjs.timezonize(record.row[toCol.title!]),
+ endDate: record.row[toCol.title!]
+ ? timezoneDayjs.timezonize(record.row[toCol.title!])
+ : timezoneDayjs.timezonize(record.row[fromCol.title!]).add(1, 'hour'),
scheduleStart,
scheduleEnd,
})
diff --git a/packages/nc-gui/utils/calendarUtils.ts b/packages/nc-gui/utils/calendarUtils.ts
index 43ff581642..efc1d9bdf5 100644
--- a/packages/nc-gui/utils/calendarUtils.ts
+++ b/packages/nc-gui/utils/calendarUtils.ts
@@ -30,7 +30,7 @@ const isRowInDateRange = (
const rowEndDate = toDate ? timezoneDayjs.timezonize(toDate) : rowStartDate
// Check if row's date range intersects with given range
- if (rowStartDate.isBefore(rangeEnd) && rowEndDate.isAfter(rangeStart)) {
+ if (rowStartDate.isSameOrBefore(rangeEnd) && rowEndDate.isSameOrAfter(rangeStart)) {
return true
}
}
@@ -130,7 +130,6 @@ const isRowMatchingSidebarFilter = (
return true
case 'withoutDates':
- // Check if row has no dates in any calendar range
for (const range of calendarRange) {
const fromCol = range.fk_from_col
const toCol = range.fk_to_col
@@ -138,7 +137,13 @@ const isRowMatchingSidebarFilter = (
const fromDate = fromCol ? rowData[fromCol.title!] : null
const toDate = toCol ? rowData[toCol.title!] : null
- if (!fromDate && !toDate) {
+ // If both columns exist, both dates must be present
+ if (fromCol && toCol && (!fromDate || !toDate)) {
+ return true
+ }
+
+ // If only fromCol exists, fromDate must be present
+ if (fromCol && !toCol && !fromDate) {
return true
}
}