Browse Source

fix: add context in response and test correction

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

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

@ -98,6 +98,9 @@
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"fields": {
"type": "object",
"additionalProperties": {
"oneOf": [
@ -124,6 +127,7 @@
}
}
}
}
},
"description": "Copy links from the one cell and paste them into another cell or delete all records from cell",
"parameters": [
@ -144,6 +148,9 @@
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"fields": {
"type": "object",
"additionalProperties": {
"oneOf": [
@ -170,6 +177,7 @@
}
}
}
}
},
"400": {
"$ref": "#/components/responses/BadRequest"
@ -663,6 +671,159 @@
"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": {
@ -1130,4 +1291,4 @@
}
}
}
}
}

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

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

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

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

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

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

Loading…
Cancel
Save