Browse Source

fix: add context in response and test correction

pull/8281/head
Pranav C 7 months ago
parent
commit
388e2505eb
  1. 6
      packages/nocodb-sdk/src/lib/enums.ts
  2. 10
      packages/nocodb/src/controllers/view-columns.controller.ts
  3. 161
      packages/nocodb/src/schema/swagger-v3.json
  4. 14
      packages/nocodb/src/services/view-columns.service.ts
  5. 3
      packages/nocodb/tests/unit/factory/viewColumns.ts
  6. 16
      packages/nocodb/tests/unit/rest/tests/viewRow.test.ts

6
packages/nocodb-sdk/src/lib/enums.ts

@ -296,3 +296,9 @@ export enum PlanLimitTypes {
FILTER_LIMIT = 'FILTER_LIMIT', FILTER_LIMIT = 'FILTER_LIMIT',
SORT_LIMIT = 'SORT_LIMIT', SORT_LIMIT = 'SORT_LIMIT',
} }
export enum APIContext {
VIEW_COLUMNS = 'fields',
FILTERS = 'filters',
SORTS = 'sorts',
}

10
packages/nocodb/src/controllers/view-columns.controller.ts

@ -9,7 +9,7 @@ import {
Req, Req,
UseGuards, UseGuards,
} from '@nestjs/common'; } from '@nestjs/common';
import { ViewColumnReqType } from 'nocodb-sdk'; import { APIContext, ViewColumnReqType } from 'nocodb-sdk'
import { GlobalGuard } from '~/guards/global/global.guard'; import { GlobalGuard } from '~/guards/global/global.guard';
import { PagedResponseImpl } from '~/helpers/PagedResponse'; import { PagedResponseImpl } from '~/helpers/PagedResponse';
import { ViewColumnsService } from '~/services/view-columns.service'; import { ViewColumnsService } from '~/services/view-columns.service';
@ -79,7 +79,7 @@ export class ViewColumnsController {
async viewColumnUpdate( async viewColumnUpdate(
@Req() req, @Req() req,
@Param('viewId') viewId: string, @Param('viewId') viewId: string,
@Body() body: ViewColumnReqType[] | Record<string, ViewColumnReqType>, @Body() body: ViewColumnReqType[] | Record<APIContext.VIEW_COLUMNS, Record<string, ViewColumnReqType>>,
) { ) {
return new PagedResponseImpl( return new PagedResponseImpl(
await this.viewColumnsService.columnsUpdate({ await this.viewColumnsService.columnsUpdate({
@ -93,9 +93,11 @@ export class ViewColumnsController {
@Get('/api/v3/meta/views/:viewId/columns') @Get('/api/v3/meta/views/:viewId/columns')
@Acl('columnList') @Acl('columnList')
async viewColumnList(@Req() req, @Param('viewId') viewId: string) { async viewColumnList(@Req() req, @Param('viewId') viewId: string) {
return await this.viewColumnsService.viewColumnList({ return {
[APIContext.VIEW_COLUMNS]: await this.viewColumnsService.viewColumnList({
viewId, viewId,
req, req,
}); })
};
} }
} }

161
packages/nocodb/src/schema/swagger-v3.json

@ -98,6 +98,9 @@
"content": { "content": {
"application/json": { "application/json": {
"schema": { "schema": {
"type": "object",
"properties": {
"fields": {
"type": "object", "type": "object",
"additionalProperties": { "additionalProperties": {
"oneOf": [ "oneOf": [
@ -124,6 +127,7 @@
} }
} }
} }
}
}, },
"description": "Copy links from the one cell and paste them into another cell or delete all records from cell", "description": "Copy links from the one cell and paste them into another cell or delete all records from cell",
"parameters": [ "parameters": [
@ -144,6 +148,9 @@
"content": { "content": {
"application/json": { "application/json": {
"schema": { "schema": {
"type": "object",
"properties": {
"fields": {
"type": "object", "type": "object",
"additionalProperties": { "additionalProperties": {
"oneOf": [ "oneOf": [
@ -170,6 +177,7 @@
} }
} }
} }
}
}, },
"400": { "400": {
"$ref": "#/components/responses/BadRequest" "$ref": "#/components/responses/BadRequest"
@ -663,6 +671,159 @@
"example": 1 "example": 1
} }
} }
},
"CalendarColumn": {
"description": "Model for Calendar Column",
"examples": [
{
"id": "kvc_2skkg5mi1eb37f",
"fk_column_id": "cl_hzos4ghyncqi4k",
"fk_view_id": "vw_wqs4zheuo5lgdy",
"source_id": "ds_hd4ojj0xpquaam",
"base_id": "p_kzfl5lb0t3tcok",
"title": "string",
"show": 0,
"bold": 0,
"italic": 0,
"underline": 0,
"order": "1"
}
],
"title": "Calendar Column Model",
"type": "object",
"properties": {
"id": {
"$ref": "#/components/schemas/Id",
"description": "Unique ID"
},
"fk_column_id": {
"$ref": "#/components/schemas/Id",
"description": "Foreign Key to Column"
},
"fk_view_id": {
"$ref": "#/components/schemas/Id",
"x-stoplight": {
"id": "t1fy4zy561ih8"
},
"description": "Foreign Key to View"
},
"source_id": {
"$ref": "#/components/schemas/Id",
"x-stoplight": {
"id": "uqq8xmyz97t1u"
},
"description": "Baes ID\n"
},
"base_id": {
"$ref": "#/components/schemas/Id",
"x-stoplight": {
"id": "uqq8xmyz97t1u"
},
"description": "Base ID"
},
"title": {
"x-stoplight": {
"id": "uqq8xmyz97t1u"
},
"description": "Base ID",
"type": "string"
},
"show": {
"$ref": "#/components/schemas/Bool",
"x-stoplight": {
"id": "uqq8xmyz97t1u"
},
"description": "Is this column shown?"
},
"bold": {
"$ref": "#/components/schemas/Bool",
"x-stoplight": {
"id": "uqq8xmyz97t1u"
},
"description": "Is this column shown as bold?"
},
"italic": {
"$ref": "#/components/schemas/Bool",
"x-stoplight": {
"id": "uqq8xmyz97t1u"
},
"description": "Is this column shown as italic?"
},
"underline": {
"$ref": "#/components/schemas/Bool",
"x-stoplight": {
"id": "uqq8xmyz97t1u"
},
"description": "Is this column shown underlines?"
},
"order": {
"type": "number",
"x-stoplight": {
"id": "pbnchzgci5dwa"
},
"example": 1,
"description": "Column Order"
}
},
"x-stoplight": {
"id": "psbv6c6y9qvbu"
}
},
"CalendarColumnReq": {
"description": "Model for Calendar Column Request",
"examples": [
{
"title": "string",
"show": 0,
"bold": 0,
"italic": 0,
"underline": 0,
"order": "1"
}
],
"title": "Calendar Column Model",
"type": "object",
"properties": {
"show": {
"$ref": "#/components/schemas/Bool",
"x-stoplight": {
"id": "uqq8xmyz97t1u"
},
"description": "Is this column shown?"
},
"bold": {
"$ref": "#/components/schemas/Bool",
"x-stoplight": {
"id": "uqq8xmyz97t1u"
},
"description": "Is this column shown as bold?"
},
"italic": {
"$ref": "#/components/schemas/Bool",
"x-stoplight": {
"id": "uqq8xmyz97t1u"
},
"description": "Is this column shown as italic?"
},
"underline": {
"$ref": "#/components/schemas/Bool",
"x-stoplight": {
"id": "uqq8xmyz97t1u"
},
"description": "Is this column shown underlines?"
},
"order": {
"type": "number",
"x-stoplight": {
"id": "pbnchzgci5dwa"
},
"example": 1,
"description": "Column Order"
}
},
"x-stoplight": {
"id": "psbv6c6y9qvbu"
}
} }
}, },
"responses": { "responses": {

14
packages/nocodb/src/services/view-columns.service.ts

@ -1,5 +1,5 @@
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { AppEvents, ViewTypes } from 'nocodb-sdk'; import { APIContext, AppEvents, ViewTypes } from 'nocodb-sdk';
import GridViewColumn from '../models/GridViewColumn'; import GridViewColumn from '../models/GridViewColumn';
import GalleryViewColumn from '../models/GalleryViewColumn'; import GalleryViewColumn from '../models/GalleryViewColumn';
import KanbanViewColumn from '../models/KanbanViewColumn'; import KanbanViewColumn from '../models/KanbanViewColumn';
@ -74,10 +74,16 @@ export class ViewColumnsService {
async columnsUpdate(param: { async columnsUpdate(param: {
viewId: string; viewId: string;
columns: ViewColumnReqType[] | Record<string, ViewColumnReqType>; columns:
| ViewColumnReqType[]
| Record<APIContext.VIEW_COLUMNS, Record<string, ViewColumnReqType>>;
req: any; req: any;
}) { }) {
const { viewId, columns } = param; const { viewId } = param;
const columns = Array.isArray(param.columns)
? param.columns
: param.columns[APIContext.VIEW_COLUMNS];
const view = await View.get(viewId); const view = await View.get(viewId);
@ -120,7 +126,7 @@ export class ViewColumnsService {
), ),
); );
} }
break break;
case ViewTypes.GALLERY: case ViewTypes.GALLERY:
if (existingCol) { if (existingCol) {
updateOrInsertOptions.push( updateOrInsertOptions.push(

3
packages/nocodb/tests/unit/factory/viewColumns.ts

@ -1,5 +1,6 @@
import request from 'supertest'; import request from 'supertest';
import type View from '../../../src/models/View'; import type View from '../../../src/models/View';
import { APIContext } from 'nocodb-sdk'
const updateViewColumns = async ( const updateViewColumns = async (
context, context,
@ -23,7 +24,7 @@ const updateViewColumns = async (
await request(context.app) await request(context.app)
.patch(`/api/v3/meta/views/${view.id}/columns`) .patch(`/api/v3/meta/views/${view.id}/columns`)
.set('xc-auth', context.token) .set('xc-auth', context.token)
.send(fields) .send({ [APIContext.VIEW_COLUMNS]: fields })
.expect(200); .expect(200);
}; };

16
packages/nocodb/tests/unit/rest/tests/viewRow.test.ts

@ -2,7 +2,7 @@ import 'mocha';
// @ts-ignore // @ts-ignore
import assert from 'assert'; import assert from 'assert';
import request from 'supertest'; import request from 'supertest';
import { UITypes, ViewTypes } from 'nocodb-sdk'; import { APIContext, UITypes, ViewTypes } from 'nocodb-sdk';
import { expect } from 'chai'; import { expect } from 'chai';
import init from '../../init'; import init from '../../init';
import { createProject, createSakilaProject } from '../../factory/base'; import { createProject, createSakilaProject } from '../../factory/base';
@ -1766,14 +1766,20 @@ function viewRowTests() {
} }
// get view columns and verify hidden columns // get view columns and verify hidden columns
const viewColumnsViaApi: any = await getViewColumns(context, { const viewColApiRes: any = await getViewColumns(context, {
view, view,
}); });
for (const colId of Object.keys(viewColumnsViaApi)) { for (const colId of Object.keys(viewColApiRes[APIContext.VIEW_COLUMNS])) {
const column = columns.find((c) => c.id === colId); const column = columns.find((c) => c.id === colId);
if (columnsToHide.includes(column.title)) if (columnsToHide.includes(column.title)) {
expect(!!viewColumnsViaApi[colId]).to.have.property('show', false); expect(viewColApiRes[APIContext.VIEW_COLUMNS][colId]).to.have.property(
'show',
);
expect(!!viewColApiRes[APIContext.VIEW_COLUMNS][colId].show).to.be.eq(
false,
);
}
} }
}); });
} }

Loading…
Cancel
Save