Browse Source

fix(nc-gui): type errors

pull/7611/head
DarkPhoenix2704 10 months ago
parent
commit
abd68898a0
  1. 5
      packages/nc-gui/components/smartsheet/calendar/WeekView.vue
  2. 45
      packages/nc-gui/composables/useCalendarViewStore.ts

5
packages/nc-gui/components/smartsheet/calendar/WeekView.vue

@ -16,6 +16,7 @@ const weekDates = computed(() => {
const getData = (date: Date) => { const getData = (date: Date) => {
const range = calendarRange.value[0] const range = calendarRange.value[0]
if (!range) return []
if (!filteredData.value) return [] if (!filteredData.value) return []
return filteredData.value.filter((record) => dayjs(date).isSame(dayjs(record.row[range.fk_from_col.title]))) return filteredData.value.filter((record) => dayjs(date).isSame(dayjs(record.row[range.fk_from_col.title])))
} }
@ -26,14 +27,14 @@ const getData = (date: Date) => {
<div class="flex"> <div class="flex">
<div <div
v-for="date in weekDates" v-for="date in weekDates"
:key="date" :key="date.toISOString()"
class="w-1/7 text-center text-sm text-gray-500 w-full py-1 !last:mr-2.5 border-gray-200 border-b-1 border-r-1 bg-gray-50" class="w-1/7 text-center text-sm text-gray-500 w-full py-1 !last:mr-2.5 border-gray-200 border-b-1 border-r-1 bg-gray-50"
> >
{{ dayjs(date).format('DD ddd') }} {{ dayjs(date).format('DD ddd') }}
</div> </div>
</div> </div>
<div class="flex overflow-auto nc-scrollbar-md h-[calc(100vh-12rem)]"> <div class="flex overflow-auto nc-scrollbar-md h-[calc(100vh-12rem)]">
<div v-for="date in weekDates" :key="date" class="flex flex-col items-center w-1/7"> <div v-for="date in weekDates" :key="date.toISOString()" class="flex flex-col items-center w-1/7">
<LazySmartsheetCalendarDayView :data="getData(date)" :is-embed="true" /> <LazySmartsheetCalendarDayView :data="getData(date)" :is-embed="true" />
</div> </div>
</div> </div>

45
packages/nc-gui/composables/useCalendarViewStore.ts

@ -91,7 +91,7 @@ const [useProvideCalendarViewStore, useCalendarViewStore] = useInjectionState(
}) })
const sideBarxWhere = computed(() => { const sideBarxWhere = computed(() => {
if (!calendarRange.value) return '' if (!calendarRange.value || !calendarRange.value[0].fk_from_col) return ''
let whereClause = '' let whereClause = ''
if (activeCalendarView.value === 'day') { if (activeCalendarView.value === 'day') {
switch (sideBarFilterOption.value) { switch (sideBarFilterOption.value) {
@ -202,7 +202,7 @@ const [useProvideCalendarViewStore, useCalendarViewStore] = useInjectionState(
} }
const xWhere = computed(() => { const xWhere = computed(() => {
if (!meta.value || !meta.value.columns || !calendarMetaData.value || !calendarMetaData.value.calendar_range) return '' if (!meta.value || !meta.value.columns || !calendarRange.value || !calendarRange.value[0].fk_from_col) return ''
// If CalendarView, then we need to add the date filter to the where clause // If CalendarView, then we need to add the date filter to the where clause
let whereClause = where?.value ?? '' let whereClause = where?.value ?? ''
if (whereClause.length > 0) { if (whereClause.length > 0) {
@ -236,11 +236,12 @@ const [useProvideCalendarViewStore, useCalendarViewStore] = useInjectionState(
// Set of Dates that have data // Set of Dates that have data
const activeDates = computed(() => { const activeDates = computed(() => {
const dates = new Set<Date>() const dates = new Set<Date>()
if (!formattedData.value || !calendarRange.value || !calendarRange.value[0].fk_from_col) return []
formattedData.value.forEach((row) => { formattedData.value.forEach((row) => {
const start = row.row[calendarRange.value[0].fk_from_col.title] const start = row.row[calendarRange.value[0].fk_from_col?.title ?? '']
let end let end
if (calendarRange.value[0].fk_to_col) { if (calendarRange.value[0].fk_to_col) {
end = row.row[calendarRange.value[0].fk_to_col.title] end = row.row[calendarRange.value[0].fk_to_col.title ?? '']
} }
if (start && end) { if (start && end) {
const startDate = dayjs(start) const startDate = dayjs(start)
@ -262,7 +263,9 @@ const [useProvideCalendarViewStore, useCalendarViewStore] = useInjectionState(
activeCalendarView.value = view activeCalendarView.value = view
await updateCalendarMeta({ await updateCalendarMeta({
meta: { meta: {
...JSON.parse(calendarMetaData.value?.meta ?? '{}'), ...(typeof calendarMetaData.value.meta === 'string'
? JSON.parse(calendarMetaData.value.meta)
: calendarMetaData.value.meta),
active_view: view, active_view: view,
}, },
}) })
@ -275,10 +278,10 @@ const [useProvideCalendarViewStore, useCalendarViewStore] = useInjectionState(
async function loadCalendarMeta() { async function loadCalendarMeta() {
if (!viewMeta?.value?.id || !meta?.value?.columns) return if (!viewMeta?.value?.id || !meta?.value?.columns) return
// TODO: Fetch Calendar Meta // TODO: Fetch Calendar Meta
calendarMetaData.value = isPublic.value const res = isPublic.value ? (sharedView.value?.view as CalendarType) : await $api.dbView.calendarRead(viewMeta.value.id)
? (sharedView.value?.view as CalendarType) calendarMetaData.value = res
: await $api.dbView.calendarRead(viewMeta.value.id) activeCalendarView.value =
activeCalendarView.value = JSON.parse(calendarMetaData.value?.meta ?? '{}')?.active_view ?? 'month' typeof res.meta === 'string' ? JSON.parse(res.meta)?.active_view : res.meta?.active_view ?? 'month'
calDataType.value = calendarRange.value[0].fk_from_col.uidt calDataType.value = calendarRange.value[0].fk_from_col.uidt
} }
@ -297,23 +300,31 @@ const [useProvideCalendarViewStore, useCalendarViewStore] = useInjectionState(
} }
const filteredData = computed(() => { const filteredData = computed(() => {
if (!formattedData.value) return [] if (!formattedData.value || !calendarRange.value) return []
const startField = calendarRange.value[0].fk_from_col?.title ?? ''
const endField = calendarRange.value[0].fk_to_col?.title
if (activeCalendarView.value === 'week') { if (activeCalendarView.value === 'week') {
return formattedData.value.filter((row) => { return formattedData.value.filter((row) => {
const startDate = dayjs(row.row[calendarRange.value[0].fk_from_col.title]) const startDate = dayjs(row.row[startField])
const endDate = dayjs(row.row[calendarRange.value[0].fk_to_col.title]) let endDate
return startDate.isSameOrBefore(selectedDateRange.value.end) && endDate.isSameOrAfter(selectedDateRange.value.start) if (endField) {
endDate = dayjs(row.row[endField])
}
return startDate.isSameOrBefore(selectedDateRange.value.end) && endDate?.isSameOrAfter(selectedDateRange.value.start)
}) })
} else if (activeCalendarView.value === 'day') { } else if (activeCalendarView.value === 'day') {
return formattedData.value.filter((row) => { return formattedData.value.filter((row) => {
const startDate = dayjs(row.row[calendarRange.value[0].fk_from_col.title]) const startDate = dayjs(row.row[startField])
return startDate.isSame(selectedDate.value) return startDate.isSame(selectedDate.value)
}) })
} else if (activeCalendarView.value === 'month') { } else if (activeCalendarView.value === 'month') {
return formattedData.value.filter((row) => { return formattedData.value.filter((row) => {
const startDate = dayjs(row.row[calendarRange.value[0].fk_from_col.title]) const startDate = dayjs(row.row[startField])
const endDate = dayjs(row.row[calendarRange.value[0].fk_to_col.title]) let endDate
return startDate.isSameOrBefore(selectedDate.value) && endDate.isSameOrAfter(selectedDate.value) if (endField) {
endDate = dayjs(row.row[endField])
}
return startDate.isSameOrBefore(selectedDate.value) && endDate?.isSameOrAfter(selectedDate.value)
}) })
} }
}) })

Loading…
Cancel
Save