Browse Source

fix(nc-gui): misc fixes

pull/7611/head
DarkPhoenix2704 9 months ago
parent
commit
e2ef73f151
  1. 25
      packages/nc-gui/components/smartsheet/calendar/DayView/DateTimeField.vue
  2. 101
      packages/nc-gui/components/smartsheet/calendar/DayView/RecordCard.vue
  3. 75
      packages/nc-gui/components/smartsheet/calendar/MonthView.vue
  4. 6
      packages/nc-gui/components/smartsheet/calendar/WeekView/DateField.vue
  5. 8
      packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue
  6. 2
      packages/nc-gui/components/smartsheet/calendar/YearView.vue
  7. 4
      packages/nc-gui/components/smartsheet/calendar/index.vue
  8. 10
      packages/nc-gui/composables/useCalendarViewStore.ts

25
packages/nc-gui/components/smartsheet/calendar/DayView/DateTimeField.vue

@ -2,7 +2,7 @@
import dayjs from 'dayjs'
import { type Row, computed, ref } from '#imports'
const emit = defineEmits(['expand-record', 'new-record'])
const emit = defineEmits(['expandRecord', 'new-record'])
const meta = inject(MetaInj, ref())
const fields = inject(FieldsInj, ref([]))
@ -201,7 +201,7 @@ const resizeDirection = ref<'right' | 'left' | null>()
const resizeInProgress = ref(false)
const resizeRecord = ref<Row | null>()
const dragTimeout = ref(null)
const dragTimeout = ref<ReturnType<typeof setTimeout>>()
const useDebouncedRowUpdate = useDebounceFn((row: Row, updateProperty: string[], isDelete: boolean) => {
updateRowProperty(row, updateProperty, isDelete)
@ -210,7 +210,7 @@ const useDebouncedRowUpdate = useDebounceFn((row: Row, updateProperty: string[],
const onResize = (event: MouseEvent) => {
if (!isUIAllowed('dataEdit')) return
if (!container.value || !resizeRecord.value) return
const { width, left, top, bottom } = container.value.getBoundingClientRect()
const { top, bottom } = container.value.getBoundingClientRect()
const { scrollHeight } = container.value
@ -294,7 +294,7 @@ const onResizeEnd = () => {
document.removeEventListener('mousemove', onResize)
document.removeEventListener('mouseup', onResizeEnd)
}
const onResizeStart = (direction: 'right' | 'left', event: MouseEvent, record: Row) => {
const onResizeStart = (direction: 'right' | 'left', _event: MouseEvent, record: Row) => {
if (!isUIAllowed('dataEdit')) return
resizeInProgress.value = true
resizeDirection.value = direction
@ -369,7 +369,7 @@ const onDrag = (event: MouseEvent) => {
const stopDrag = (event: MouseEvent) => {
event.preventDefault()
clearTimeout(dragTimeout.value)
clearTimeout(dragTimeout.value!)
if (!isUIAllowed('dataEdit')) return
if (!isDragging.value || !container.value || !dragRecord.value) return
@ -490,10 +490,10 @@ const dragStart = (event: MouseEvent, record: Row) => {
}, 200)
const onMouseUp = () => {
clearTimeout(dragTimeout.value)
clearTimeout(dragTimeout.value!)
document.removeEventListener('mouseup', onMouseUp)
if (!isDragging.value) {
emit('expand-record', record)
emit('expandRecord', record)
}
}
@ -636,11 +636,10 @@ const dragStart = (event: MouseEvent, record: Row) => {
<style lang="scss" scoped>
.no-selection {
-webkit-touch-callout: none; /* iOS Safari */
-webkit-user-select: none; /* Safari */
-khtml-user-select: none; /* Konqueror HTML */
-moz-user-select: none; /* Old versions of Firefox */
-ms-user-select: none; /* Internet Explorer/Edge */
user-select: none; /* Non-prefixed version, currently supported by Chrome, Edge, Opera and Firefox */
-webkit-touch-callout: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
</style>

101
packages/nc-gui/components/smartsheet/calendar/DayView/RecordCard.vue

@ -1,101 +0,0 @@
<script lang="ts" setup>
interface Props {
record: Record<string, string>
name: string
date?: string
color?: string
resize?: boolean
selected?: boolean
size?: 'small' | 'medium' | 'large' | 'auto'
showDate?: boolean
position?: 'leftRounded' | 'rightRounded' | 'rounded' | 'none'
}
withDefaults(defineProps<Props>(), {
name: '',
date: '',
resize: true,
selected: false,
color: 'blue',
size: 'small',
showDate: true,
position: 'rounded',
})
const emit = defineEmits(['resize-start'])
</script>
<template>
<div
:class="{
'min-h-9': size === 'small',
'min-h-10': size === 'medium',
'min-h-12': size === 'large',
'h-full': size === 'auto',
'rounded-l-lg ml-3': position === 'leftRounded',
'rounded-r-lg mr-3': position === 'rightRounded',
'rounded-lg mx-3': position === 'rounded',
'rounded-none': position === 'none',
'bg-maroon-50': color === 'maroon',
'bg-blue-50': color === 'blue',
'bg-green-50': color === 'green',
'bg-yellow-50': color === 'yellow',
'bg-pink-50': color === 'pink',
'bg-purple-50': color === 'purple',
'group-hover:(border-brand-500 border-2)': resize,
'border-brand-500 border-2': selected,
}"
class="relative group"
>
<div class="h-full absolute py-2">
<div
v-if="position === 'leftRounded' || position === 'rounded'"
:class="{
'bg-maroon-500': color === 'maroon',
'bg-blue-500': color === 'blue',
'bg-green-500': color === 'green',
'bg-yellow-500': color === 'yellow',
'bg-pink-500': color === 'pink',
'bg-purple-500': color === 'purple',
}"
class="block h-full min-h-5 ml-1 w-1 rounded mr-2"
></div>
</div>
<div
v-if="(position === 'leftRounded' || position === 'rounded') && resize"
:class="{
'!block border-2 rounded-lg border-brand-500': selected,
}"
class="absolute mt-0.6 h-7.1 hidden -left-3 resize !group-hover:(border-brand-500 block border-2 rounded-lg)"
>
<NcButton size="xsmall" type="secondary" @mousedown.stop="emit('resize-start', 'left', $event, record)">
<component :is="iconMap.drag" class="text-gray-400"></component>
</NcButton>
</div>
<div class="ml-3 mt-2 pr-3 text-ellipsis overflow-hidden w-full h-6 absolute">
<span v-if="position === 'rightRounded' || position === 'none'"> .... </span>
<span class="text-sm text-gray-800">{{ name }}</span>
<span v-if="showDate" class="text-xs ml-1 text-gray-600">{{ date }}</span>
<span v-if="position === 'leftRounded' || position === 'none'" class="absolute my-0 right-5"> .... </span>
</div>
<div
v-if="(position === 'rightRounded' || position === 'rounded') && resize"
:class="{
'!block border-2 rounded-lg border-brand-500': selected,
}"
class="absolute mt-0.6 hidden h-7.1 -right-3 border-1 resize !group-hover:(border-brand-500 border-2 block rounded-lg)"
>
<NcButton size="xsmall" type="secondary" @mousedown.stop="emit('resize-start', 'right', $event, record)">
<component :is="iconMap.drag" class="text-gray-400"></component>
</NcButton>
</div>
</div>
</template>
<style lang="scss" scoped>
.resize {
cursor: ew-resize;
}
</style>

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

@ -47,7 +47,7 @@ const resizeInProgress = ref(false)
const isDragging = ref(false)
const dragRecord = ref<Row>()
const dragTimeout = ref(null)
const dragTimeout = ref<ReturnType<typeof setTimeout>>()
const focusedDate = ref<Date | null>(null)
@ -85,18 +85,7 @@ function getRandomNumbers() {
return randomValues.join('')
}
const recordsToDisplay = computed<{
records: Array<Row>
count: {
[key: string]:
| {
overflow: boolean
count: number
overflowCount: number
}
| undefined
}
}>(() => {
const recordsToDisplay = computed(() => {
if (!dates.value || !calendarRange.value) return []
const perWidth = gridContainerWidth.value / 7
@ -121,11 +110,11 @@ const recordsToDisplay = computed<{
const endCol = range.fk_to_col
const sortedFormattedData = [...formattedData.value].filter((record) => {
const fromDate = record.row[startCol?.title] ? dayjs(record.row[startCol.title]) : null
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
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
@ -135,7 +124,7 @@ const recordsToDisplay = computed<{
sortedFormattedData.forEach((record: Row) => {
if (!endCol && startCol) {
const startDate = dayjs(record.row[startCol.title])
const startDate = dayjs(record.row[startCol!.title!])
const dateKey = startDate.format('YYYY-MM-DD')
if (!recordsInDay[dateKey]) {
@ -179,8 +168,8 @@ const recordsToDisplay = computed<{
},
})
} else if (startCol && endCol) {
const startDate = dayjs(record.row[startCol.title])
const endDate = dayjs(record.row[endCol.title])
const startDate = dayjs(record.row[startCol!.title!])
const endDate = dayjs(record.row[endCol!.title!])
let currentWeekStart = startDate.startOf('week')
const id = record.rowMeta.id ?? getRandomNumbers()
@ -292,20 +281,23 @@ const recordsToDisplay = computed<{
}
})
})
return {
const result: { records: Row[]; count: { [p: string]: { overflow: boolean; count: number; overflowCount: number } } } = {
records: recordsToDisplay,
count: recordsInDay,
}
return result
})
const onDrag = (event: MouseEvent) => {
if (!isUIAllowed('dataEdit') || !dragRecord.value) return
const { top, height, width, left } = calendarGridContainer.value.getBoundingClientRect()
const percentY = (event.clientY - top - window.scrollY) / height
const percentX = (event.clientX - left - window.scrollX) / width
const fromCol = dragRecord.value!.rowMeta.range?.fk_from_col
const toCol = dragRecord.value!.rowMeta.range?.fk_to_col
const fromCol = dragRecord.value.rowMeta.range?.fk_from_col
const toCol = dragRecord.value.rowMeta.range?.fk_to_col
const week = Math.floor(percentY * dates.value.length)
const day = Math.floor(percentX * 7)
@ -359,15 +351,15 @@ const useDebouncedRowUpdate = useDebounceFn((row: Row, updateProperty: string[],
}, 500)
const onResize = (event: MouseEvent) => {
if (!isUIAllowed('dataEdit')) return
if (!isUIAllowed('dataEdit') || !resizeRecord.value) return
const { top, height, width, left } = calendarGridContainer.value.getBoundingClientRect()
const percentY = (event.clientY - top - window.scrollY) / height
const percentX = (event.clientX - left - window.scrollX) / width
const ogEndDate = resizeRecord.value.row[resizeRecord.value.rowMeta.range?.fk_to_col.title]
const ogStartDate = resizeRecord.value.row[resizeRecord.value.rowMeta.range?.fk_from_col.title]
const ogEndDate = resizeRecord.value.row[resizeRecord.value.rowMeta!.range!.fk_to_col!.title!]
const ogStartDate = resizeRecord.value.row[resizeRecord.value.rowMeta!.range!.fk_from_col!.title!]
const fromCol = resizeRecord.value.rowMeta.range?.fk_from_col
const toCol = resizeRecord.value.rowMeta.range?.fk_to_col
@ -435,8 +427,8 @@ const onResize = (event: MouseEvent) => {
const onResizeEnd = () => {
resizeInProgress.value = false
resizeDirection.value = null
resizeRecord.value = null
resizeDirection.value = undefined
resizeRecord.value = undefined
document.removeEventListener('mousemove', onResize)
document.removeEventListener('mouseup', onResizeEnd)
}
@ -453,14 +445,14 @@ const onResizeStart = (direction: 'right' | 'left', event: MouseEvent, record: R
}
const stopDrag = (event: MouseEvent) => {
if (!isUIAllowed('dataEdit')) return
if (!isUIAllowed('dataEdit') || !dragRecord.value) return
event.preventDefault()
clearTimeout(dragTimeout.value)
if (!isDragging.value) return
dragElement.value.style.boxShadow = 'none'
dragElement.value!.style.boxShadow = 'none'
const { top, height, width, left } = calendarGridContainer.value.getBoundingClientRect()
@ -502,7 +494,7 @@ const stopDrag = (event: MouseEvent) => {
endDate = newStartDate.clone()
}
dragRecord.value = null
dragRecord.value = undefined
newRow.row[toCol!.title!] = dayjs(endDate).format('YYYY-MM-DD HH:mm:ssZ')
updateProperty.push(toCol!.title!)
@ -512,9 +504,9 @@ const stopDrag = (event: MouseEvent) => {
if (dragElement.value) {
formattedData.value = formattedData.value.map((r) => {
const pk = extractPkFromRow(r.row, meta.value.columns)
const pk = extractPkFromRow(r.row, meta.value!.columns!)
if (pk === extractPkFromRow(newRow.row, meta.value.columns)) {
if (pk === extractPkFromRow(newRow.row, meta.value!.columns!)) {
return newRow
}
return r
@ -522,9 +514,9 @@ const stopDrag = (event: MouseEvent) => {
} else {
formattedData.value = [...formattedData.value, newRow]
formattedSideBarData.value = formattedSideBarData.value.filter((r) => {
const pk = extractPkFromRow(r.row, meta.value.columns)
const pk = extractPkFromRow(r.row, meta.value!.columns!)
return pk !== extractPkFromRow(newRow.row, meta.value.columns)
return pk !== extractPkFromRow(newRow.row, meta.value!.columns!)
})
}
@ -550,8 +542,7 @@ const stopDrag = (event: MouseEvent) => {
}
const dragStart = (event: MouseEvent, record: Row) => {
if (!isUIAllowed('dataEdit')) return
if (resizeInProgress.value) return
if (!isUIAllowed('dataEdit') || resizeInProgress.value || !record.rowMeta.id) return
let target = event.target as HTMLElement
isDragging.value = false
@ -562,7 +553,7 @@ const dragStart = (event: MouseEvent, record: Row) => {
const allRecords = document.querySelectorAll('.draggable-record')
allRecords.forEach((el) => {
if (!el.getAttribute('data-unique-id').includes(record.rowMeta.id)) {
if (!el.getAttribute('data-unique-id').includes(record.rowMeta.id!)) {
// el.style.visibility = 'hidden'
el.style.opacity = '30%'
}
@ -583,7 +574,7 @@ const dragStart = (event: MouseEvent, record: Row) => {
clearTimeout(dragTimeout.value)
document.removeEventListener('mouseup', onMouseUp)
if (!isDragging.value) {
emit('expand-record', record)
emit('expandRecord', record)
}
}
@ -757,7 +748,7 @@ onBeforeUnmount(() => {
() => {
const record = {
row: {
[range.fk_from_col.title]: dayjs(day).format('YYYY-MM-DD HH:mm:ssZ'),
[range.fk_from_col!.title!]: dayjs(day).format('YYYY-MM-DD HH:mm:ssZ'),
},
}
emit('new-record', record)
@ -766,7 +757,7 @@ onBeforeUnmount(() => {
>
<div class="flex items-center gap-1">
<LazySmartsheetHeaderCellIcon :column-meta="range.fk_from_col" />
<span class="ml-1">{{ range.fk_from_col.title }}</span>
<span class="ml-1">{{ range.fk_from_col!.title }}</span>
</div>
</NcMenuItem>
</NcMenu>
@ -784,7 +775,7 @@ onBeforeUnmount(() => {
() => {
const record = {
row: {
[calendarRange[0].fk_from_col.title]: dayjs(day).format('YYYY-MM-DD HH:mm:ssZ'),
[calendarRange[0].fk_from_col!.title!]: dayjs(day).format('YYYY-MM-DD HH:mm:ssZ'),
},
}
emit('new-record', record)
@ -833,7 +824,7 @@ onBeforeUnmount(() => {
? dayjs(record.row[record.rowMeta.range?.fk_from_col.title]).format('YYYY-MM-DD HH:mm')
: dayjs(record.row[record.rowMeta.range?.fk_from_col.title]).format('YYYY-MM-DD')
"
:name="record.row[displayField.title]"
:name="record.row[displayField!.title!]"
:position="record.rowMeta.position"
:record="record"
:resize="!!record.rowMeta.range?.fk_to_col && isUIAllowed('dataEdit')"

6
packages/nc-gui/components/smartsheet/calendar/WeekView/DateField.vue

@ -3,7 +3,7 @@ import dayjs from 'dayjs'
import type { Row } from '~/lib'
import { ref } from '#imports'
const emits = defineEmits(['expand-record'])
const emits = defineEmits(['expandRecord'])
const { selectedDateRange, formattedData, formattedSideBarData, calendarRange, selectedDate, displayField, updateRowProperty } =
useCalendarViewStoreOrThrow()
@ -203,7 +203,7 @@ const draggingId = ref<string | null>(null)
const resizeInProgress = ref(false)
const dragTimeout = ref<string | number | null | NodeJS.Timeout>(null)
const dragTimeout = ref<ReturnType<typeof setTimeout>>()
const isDragging = ref(false)
const dragRecord = ref<Row>()
@ -484,7 +484,7 @@ const dragStart = (event: MouseEvent, record: Row) => {
clearTimeout(dragTimeout.value!)
document.removeEventListener('mouseup', onMouseUp)
if (!isDragging.value) {
emits('expand-record', record)
emits('expandRecord', record)
}
}

8
packages/nc-gui/components/smartsheet/calendar/WeekView/DateTimeField.vue

@ -3,7 +3,7 @@ import dayjs from 'dayjs'
import type { Row } from '~/lib'
import { computed, ref } from '#imports'
const emits = defineEmits(['expand-record'])
const emits = defineEmits(['expandRecord'])
const { selectedDateRange, formattedData, formattedSideBarData, calendarRange, displayField, selectedTime, updateRowProperty } =
useCalendarViewStoreOrThrow()
@ -229,7 +229,7 @@ const recordsAcrossAllRange = computed(() => {
recordsToDisplay = recordsToDisplay.map((record) => {
let maxOverlaps = 1
let overlapIndex = 0
const dayIndex = record.rowMeta.dayIndex
const dayIndex = record.rowMeta.dayIndex as number
const dateKey = dayjs(selectedDateRange.value.start).add(dayIndex, 'day').format('YYYY-MM-DD')
@ -261,7 +261,7 @@ const draggingId = ref<string | null>(null)
const resizeInProgress = ref(false)
const dragTimeout = ref<string | number | null | NodeJS.Timeout>(null)
const dragTimeout = ref<ReturnType<typeof setTimeout>>()
const resizeDirection = ref<'right' | 'left' | null>()
const resizeRecord = ref<Row | null>()
@ -565,7 +565,7 @@ const dragStart = (event: MouseEvent, record: Row) => {
clearTimeout(dragTimeout.value!)
document.removeEventListener('mouseup', onMouseUp)
if (!isDragging.value) {
emits('expand-record', record)
emits('expandRecord', record)
}
}

2
packages/nc-gui/components/smartsheet/calendar/YearView.vue

@ -13,7 +13,7 @@ const months = computed(() => {
<template>
<div class="flex flex-wrap gap-6 pb-4 items-center justify-center overflow-auto nc-scrollbar-md">
<NcDateWeekSelector
v-for="(month, index) in months"
v-for="(_, index) in months"
:key="index"
v-model:active-dates="activeDates"
v-model:page-date="months[index]"

4
packages/nc-gui/components/smartsheet/calendar/index.vue

@ -58,8 +58,6 @@ const showSideMenu = ref(true)
const calendarRangeDropdown = ref(false)
const isPublic = inject(IsPublicInj, ref(false))
const router = useRouter()
const route = useRoute()
@ -99,7 +97,7 @@ const expandRecord = (row: RowType, state?: Record<string, any>) => {
}
}
const newRecord = (row: Row) => {
const newRecord = (row: RowType) => {
// TODO: The default values has to be filled based on the active calendar view
// and selected sidebar filter option
expandRecord({

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

@ -1,13 +1,5 @@
import type { ComputedRef, Ref } from 'vue'
import {
type Api,
type CalendarType,
type ColumnType,
type PaginatedType,
type TableType,
UITypes,
type ViewType,
} from 'nocodb-sdk'
import { type Api, type CalendarType, type ColumnType, type PaginatedType, type TableType, type ViewType } from 'nocodb-sdk'
import dayjs from 'dayjs'
import { addDays, addMonths, addYears, extractPkFromRow, extractSdkResponseErrorMsg, rowPkData } from '~/utils'
import { IsPublicInj, type Row, ref, storeToRefs, useBase, useInjectionState, useUndoRedo } from '#imports'

Loading…
Cancel
Save