Browse Source

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 <anbarasun123@gmail.com>
nc-fix/duplicate-code
Raju Udava 6 months ago committed by GitHub
parent
commit
2e46dcb476
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 19
      packages/nc-gui/composables/useSharedView.ts
  2. 29
      packages/nocodb/src/services/public-metas.service.ts

19
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)
// Required for Calendar View
const rangeFields: Array<string> = []
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)

29
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;

Loading…
Cancel
Save