Browse Source

fix: keep settings open if calendar misses range (#8567)

pull/8570/head
Mert E 4 months ago committed by GitHub
parent
commit
74658d77bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 47
      packages/nc-gui/components/smartsheet/toolbar/Calendar/Range.vue

47
packages/nc-gui/components/smartsheet/toolbar/Calendar/Range.vue

@ -44,6 +44,26 @@ const calendarRange = computed<CalendarRangeType[]>(() => {
// We keep the calendar range here and update it when the user selects a new range // We keep the calendar range here and update it when the user selects a new range
const _calendar_ranges = ref<CalendarRangeType[]>(calendarRange.value) const _calendar_ranges = ref<CalendarRangeType[]>(calendarRange.value)
const isSetup = computed(() => {
return _calendar_ranges.value.length > 0 && _calendar_ranges.value[0].fk_from_column_id
})
watch(
calendarRangeDropdown,
(newVal) => {
if (!newVal && !isSetup.value) {
calendarRangeDropdown.value = true
if (_calendar_ranges.value.length === 0) {
_calendar_ranges.value.push({
fk_from_column_id: undefined,
fk_to_column_id: null,
})
}
}
},
{ immediate: true },
)
const saveCalendarRanges = async () => { const saveCalendarRanges = async () => {
if (activeView.value) { if (activeView.value) {
try { try {
@ -56,8 +76,12 @@ const saveCalendarRanges = async () => {
await $api.dbView.calendarUpdate(activeView.value?.id as string, { await $api.dbView.calendarUpdate(activeView.value?.id as string, {
calendar_range: calRanges as CalendarRangeType[], calendar_range: calRanges as CalendarRangeType[],
}) })
if (activeView.value.view) activeView.value.view.calendar_range = calRanges
await loadCalendarMeta() await loadCalendarMeta()
await Promise.all([loadCalendarData(), loadSidebarData(), fetchActiveDates()]) await Promise.all([loadCalendarData(), loadSidebarData(), fetchActiveDates()])
calendarRangeDropdown.value = false
} catch (e) { } catch (e) {
console.log(e) console.log(e)
message.error('There was an error while updating view!') message.error('There was an error while updating view!')
@ -78,13 +102,6 @@ const dateFieldOptions = computed<SelectProps['options']>(() => {
})) ?? [] })) ?? []
) )
}) })
const addCalendarRange = async () => {
_calendar_ranges.value.push({
fk_from_column_id: dateFieldOptions.value![0].value as string,
fk_to_column_id: null,
})
await saveCalendarRanges()
}
/* /*
const removeRange = async (id: number) => { const removeRange = async (id: number) => {
_calendar_ranges.value = _calendar_ranges.value.filter((_, i) => i !== id) _calendar_ranges.value = _calendar_ranges.value.filter((_, i) => i !== id)
@ -235,22 +252,14 @@ const saveCalendarRange = async (range: CalendarRangeType, value?) => {
</NcButton> </NcButton>
--> -->
</div> </div>
<div v-if="!isSetup" class="flex items-center gap-2 !mt-2">
<GeneralIcon icon="warning" class="text-sm mt-0.5 text-orange-500" />
<span class="text-sm text-gray-500"> Date field is required! </span>
</div>
<!-- <!--
<div class="text-[13px] text-gray-500 py-2">Records in this view will be based on the specified date field.</div> <div class="text-[13px] text-gray-500 py-2">Records in this view will be based on the specified date field.</div>
--> -->
<NcButton
v-if="_calendar_ranges.length === 0"
class="mt-2"
data-testid="nc-calendar-range-add-btn"
size="small"
type="secondary"
@click="addCalendarRange"
>
<component :is="iconMap.plus" />
Add date field
</NcButton>
</div> </div>
</template> </template>
</NcDropdown> </NcDropdown>

Loading…
Cancel
Save