Browse Source

refactor(nocodb): revise update props for views

pull/5269/head
Wing-Kam Wong 2 years ago
parent
commit
f9686bd021
  1. 3
      packages/nocodb/src/lib/models/FormView.ts
  2. 19
      packages/nocodb/src/lib/models/GalleryView.ts
  3. 9
      packages/nocodb/src/lib/models/GridView.ts
  4. 1
      packages/nocodb/src/lib/models/KanbanView.ts
  5. 15
      packages/nocodb/src/lib/models/MapView.ts

3
packages/nocodb/src/lib/models/FormView.ts

@ -6,6 +6,7 @@ import { extractProps } from '../meta/helpers/extractProps';
import FormViewColumn from './FormViewColumn';
import View from './View';
import type { BoolType, FormType } from 'nocodb-sdk';
import { MetaType } from 'nocodb-sdk';
export default class FormView implements FormType {
show: BoolType;
@ -27,7 +28,7 @@ export default class FormView implements FormType {
columns?: FormViewColumn[];
project_id?: string;
base_id?: string;
meta?: string | Record<string, any>;
meta?: MetaType;
constructor(data: FormView) {
Object.assign(this, data);

19
packages/nocodb/src/lib/models/GalleryView.ts

@ -1,4 +1,4 @@
import { UITypes } from 'nocodb-sdk';
import { MetaType, UITypes } from 'nocodb-sdk';
import Noco from '../Noco';
import { CacheGetType, CacheScope, MetaTable } from '../utils/globals';
import NocoCache from '../cache/NocoCache';
@ -26,6 +26,7 @@ export default class GalleryView implements GalleryType {
base_id?: string;
columns?: GalleryColumnType[];
meta?: MetaType;
constructor(data: GalleryView) {
Object.assign(this, data);
@ -95,16 +96,12 @@ export default class GalleryView implements GalleryType {
// get existing cache
const key = `${CacheScope.GALLERY_VIEW}:${galleryId}`;
let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
const updateObj = extractProps(body, [
'next_enabled',
'prev_enabled',
'cover_image_idx',
'cover_image',
'restrict_types',
'restrict_size',
'restrict_number',
'fk_cover_image_col_id',
]);
const updateObj = extractProps(body, ['fk_cover_image_col_id', 'meta']);
if (updateObj.meta && typeof updateObj.meta === 'object') {
updateObj.meta = JSON.stringify(updateObj.meta ?? {});
}
if (o) {
o = { ...o, ...updateObj };
// set cache

9
packages/nocodb/src/lib/models/GridView.ts

@ -10,10 +10,8 @@ export default class GridView implements GridType {
fk_view_id: string;
project_id?: string;
base_id?: string;
meta?: MetaType;
row_height?: number;
columns?: GridViewColumn[];
constructor(data: GridView) {
@ -73,7 +71,12 @@ export default class GridView implements GridType {
// get existing cache
const key = `${CacheScope.GRID_VIEW}:${viewId}`;
let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
const updateObj = extractProps(body, ['row_height']);
const updateObj = extractProps(body, ['row_height', 'meta']);
if (updateObj.meta && typeof updateObj.meta === 'object') {
updateObj.meta = JSON.stringify(updateObj.meta ?? {});
}
if (o) {
o = { ...o, ...updateObj };
// set cache

1
packages/nocodb/src/lib/models/KanbanView.ts

@ -104,7 +104,6 @@ export default class KanbanView implements KanbanType {
let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
const updateObj = extractProps(body, [
'title',
'fk_cover_image_col_id',
'fk_grp_col_id',
'meta',

15
packages/nocodb/src/lib/models/MapView.ts

@ -4,6 +4,7 @@ import NocoCache from '../cache/NocoCache';
import View from './View';
import MapViewColumn from './MapViewColumn';
import type { MapType } from 'nocodb-sdk';
import { extractProps } from '../meta/helpers/extractProps';
export default class MapView implements MapType {
fk_view_id: string;
@ -71,13 +72,13 @@ export default class MapView implements MapType {
// get existing cache
const key = `${CacheScope.MAP_VIEW}:${mapId}`;
let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
const updateObj = {
...body,
meta:
typeof body.meta === 'string'
? body.meta
: JSON.stringify(body.meta ?? {}),
};
const updateObj = extractProps(body, ['fk_geo_data_col_id', 'meta']);
if (updateObj.meta && typeof updateObj.meta === 'object') {
updateObj.meta = JSON.stringify(updateObj.meta ?? {});
}
if (o) {
o = { ...o, ...updateObj };
// set cache

Loading…
Cancel
Save