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 let order = 1
meta.value!.columns = [...viewMeta.model.columns] // Required for Calendar View
.filter((c) => c.show) 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++ })) .map((c) => ({ ...c, order: order++ }))
.sort((a, b) => a.order - b.order) .sort((a, b) => a.order - b.order)
}
await setMeta(viewMeta.model) await setMeta(viewMeta.model)

29
packages/nocodb/src/services/public-metas.service.ts

@ -1,13 +1,18 @@
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { import {
isCreatedOrLastModifiedByCol, isCreatedOrLastModifiedByCol,
isLinksOrLTAR,
RelationTypes, RelationTypes,
UITypes, UITypes,
ViewTypes,
} from 'nocodb-sdk'; } from 'nocodb-sdk';
import { isLinksOrLTAR } from 'nocodb-sdk'; import type {
import type { LinkToAnotherRecordColumn, LookupColumn } from '~/models'; CalendarView,
import { NcError } from '~/helpers/catchError'; LinkToAnotherRecordColumn,
LookupColumn,
} from '~/models';
import { Base, BaseUser, Column, Model, Source, View } from '~/models'; import { Base, BaseUser, Column, Model, Source, View } from '~/models';
import { NcError } from '~/helpers/catchError';
@Injectable() @Injectable()
export class PublicMetasService { export class PublicMetasService {
@ -36,12 +41,28 @@ export class PublicMetasService {
view.client = source.type; view.client = source.type;
// todo: return only required props // 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 view.model.columns = view.columns
.filter((c) => { .filter((c) => {
const column = view.model.columnsById[c.fk_column_id]; 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 // Check if column exists to prevent processing non-existent columns
if (!column) return false; if (!column) return false;

Loading…
Cancel
Save