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 FormViewColumn from './FormViewColumn';
import View from './View'; import View from './View';
import type { BoolType, FormType } from 'nocodb-sdk'; import type { BoolType, FormType } from 'nocodb-sdk';
import { MetaType } from 'nocodb-sdk';
export default class FormView implements FormType { export default class FormView implements FormType {
show: BoolType; show: BoolType;
@ -27,7 +28,7 @@ export default class FormView implements FormType {
columns?: FormViewColumn[]; columns?: FormViewColumn[];
project_id?: string; project_id?: string;
base_id?: string; base_id?: string;
meta?: string | Record<string, any>; meta?: MetaType;
constructor(data: FormView) { constructor(data: FormView) {
Object.assign(this, data); 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 Noco from '../Noco';
import { CacheGetType, CacheScope, MetaTable } from '../utils/globals'; import { CacheGetType, CacheScope, MetaTable } from '../utils/globals';
import NocoCache from '../cache/NocoCache'; import NocoCache from '../cache/NocoCache';
@ -26,6 +26,7 @@ export default class GalleryView implements GalleryType {
base_id?: string; base_id?: string;
columns?: GalleryColumnType[]; columns?: GalleryColumnType[];
meta?: MetaType;
constructor(data: GalleryView) { constructor(data: GalleryView) {
Object.assign(this, data); Object.assign(this, data);
@ -95,16 +96,12 @@ export default class GalleryView implements GalleryType {
// get existing cache // get existing cache
const key = `${CacheScope.GALLERY_VIEW}:${galleryId}`; const key = `${CacheScope.GALLERY_VIEW}:${galleryId}`;
let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
const updateObj = extractProps(body, [
'next_enabled', const updateObj = extractProps(body, ['fk_cover_image_col_id', 'meta']);
'prev_enabled', if (updateObj.meta && typeof updateObj.meta === 'object') {
'cover_image_idx', updateObj.meta = JSON.stringify(updateObj.meta ?? {});
'cover_image', }
'restrict_types',
'restrict_size',
'restrict_number',
'fk_cover_image_col_id',
]);
if (o) { if (o) {
o = { ...o, ...updateObj }; o = { ...o, ...updateObj };
// set cache // set cache

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

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

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

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

Loading…
Cancel
Save