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. 14
      packages/nocodb/src/controllers/view-columns.controller.ts
  3. 2025
      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',
}

14
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({
viewId,
req,
});
return {
[APIContext.VIEW_COLUMNS]: await this.viewColumnsService.viewColumnList({
viewId,
req,
})
};
}
}

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

File diff suppressed because it is too large Load Diff

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