From 2e46dcb476b427422f58843aea61ab0c8baa3bbf Mon Sep 17 00:00:00 2001 From: Raju Udava <86527202+dstala@users.noreply.github.com> Date: Thu, 30 May 2024 11:26:26 +0530 Subject: [PATCH] fix: include the range fields as columns in sharedView Meta (#8599) * fix: include the range fields as columns in sharedView Meta * fix: coderabbit comments --------- Co-authored-by: DarkPhoenix2704 --- packages/nc-gui/composables/useSharedView.ts | 23 ++++++++++++--- .../src/services/public-metas.service.ts | 29 ++++++++++++++++--- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/packages/nc-gui/composables/useSharedView.ts b/packages/nc-gui/composables/useSharedView.ts index 9f93227c46..b7177c5941 100644 --- a/packages/nc-gui/composables/useSharedView.ts +++ b/packages/nc-gui/composables/useSharedView.ts @@ -82,10 +82,25 @@ export function useSharedView() { let order = 1 - meta.value!.columns = [...viewMeta.model.columns] - .filter((c) => c.show) - .map((c) => ({ ...c, order: order++ })) - .sort((a, b) => a.order - b.order) + // Required for Calendar View + const rangeFields: Array = [] + if ((sharedView.value?.view as CalendarType)?.calendar_range?.length) { + for (const range of (sharedView.value?.view as CalendarType)?.calendar_range ?? []) { + if (range.fk_from_column_id) { + rangeFields.push(range.fk_from_column_id) + } + if ((range as any).fk_to_column_id) { + rangeFields.push((range as any).fk_to_column_id) + } + } + } + + if (meta.value) { + meta.value.columns = [...viewMeta.model.columns] + .filter((c) => c.show || rangeFields.includes(c.id)) + .map((c) => ({ ...c, order: order++ })) + .sort((a, b) => a.order - b.order) + } await setMeta(viewMeta.model) diff --git a/packages/nocodb/src/services/public-metas.service.ts b/packages/nocodb/src/services/public-metas.service.ts index ce9d2e1c3f..02db9589ad 100644 --- a/packages/nocodb/src/services/public-metas.service.ts +++ b/packages/nocodb/src/services/public-metas.service.ts @@ -1,13 +1,18 @@ import { Injectable } from '@nestjs/common'; import { isCreatedOrLastModifiedByCol, + isLinksOrLTAR, RelationTypes, UITypes, + ViewTypes, } from 'nocodb-sdk'; -import { isLinksOrLTAR } from 'nocodb-sdk'; -import type { LinkToAnotherRecordColumn, LookupColumn } from '~/models'; -import { NcError } from '~/helpers/catchError'; +import type { + CalendarView, + LinkToAnotherRecordColumn, + LookupColumn, +} from '~/models'; import { Base, BaseUser, Column, Model, Source, View } from '~/models'; +import { NcError } from '~/helpers/catchError'; @Injectable() export class PublicMetasService { @@ -36,12 +41,28 @@ export class PublicMetasService { view.client = source.type; // todo: return only required props - delete view['password']; + view.password = undefined; + + // Required for Calendar Views + const rangeColumns = []; + + if (view.type === ViewTypes.CALENDAR) { + for (const c of (view.view as CalendarView).calendar_range) { + if (c.fk_from_column_id) { + rangeColumns.push(c.fk_from_column_id); + } else if ((c as any).fk_to_column_id) { + rangeColumns.push((c as any).fk_to_column_id); + } + } + } view.model.columns = view.columns .filter((c) => { const column = view.model.columnsById[c.fk_column_id]; + if (rangeColumns.includes(c.fk_column_id)) { + return true; + } // Check if column exists to prevent processing non-existent columns if (!column) return false;