Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

fix tests

Fendy Heryantoaa912f6f7429
diff --git a/packages/nocodb/src/schema/swagger-v3.json b/packages/nocodb/src/schema/swagger-v3.json
index 8327391dc6..38ee1cdd87 100644
--- a/packages/nocodb/src/schema/swagger-v3.json
+++ b/packages/nocodb/src/schema/swagger-v3.json
@@ -5264,82 +5264,136 @@
}
}
},
- "ViewBaseOptions": {
- "oneOf": [
- {
+ "ViewColumnOption": {
+ "fieldsById": {
+ "type": "object",
+ "additionalProperties": {
"type": "object",
"properties": {
- "type": {
- "type": "string",
- "enum": [
- "GRID"
- ]
+ "alias": {
+ "type": "string"
},
- "options": {
- "$ref": "#/components/schemas/ViewOptionsGrid"
- }
- }
- },
- {
- "type": "object",
- "properties": {
- "type": {
- "type": "string",
- "enum": [
- "KANBAN"
- ]
+ "description": {
+ "type": "string"
},
- "options": {
- "$ref": "#/components/schemas/ViewOptionsKanban"
- }
- }
- },
- {
- "type": "object",
- "properties": {
- "type": {
- "type": "string",
- "enum": [
- "CALENDAR"
- ]
+ "required": {
+ "type": "boolean"
},
- "options": {
- "$ref": "#/components/schemas/ViewOptionsCalendar"
- }
- }
- },
- {
- "type": "object",
- "properties": {
- "type": {
- "type": "string",
- "enum": [
- "GALLERY"
- ]
+ "allowScannerInput": {
+ "type": "boolean"
+ },
+ "isList": {
+ "type": "boolean"
+ },
+ "isLimitOption": {
+ "type": "boolean"
},
- "options": {
- "$ref": "#/components/schemas/ViewOptionsGallery"
+ "validators": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "type": {
+ "type": "string"
+ },
+ "value": {},
+ "message": {
+ "type": "string"
+ },
+ "regex": {
+ "type": "string",
+ "nullable": true
+ }
+ }
+ }
}
}
+ }
+ }
+ },
+ "ViewBaseOptions": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/ViewColumnOption"
},
{
- "type": "object",
- "properties": {
- "type": {
- "type": "string",
- "enum": [
- "FORM"
- ]
+ "oneOf": [
+ {
+ "type": "object",
+ "properties": {
+ "type": {
+ "type": "string",
+ "enum": [
+ "GRID"
+ ]
+ },
+ "options": {
+ "$ref": "#/components/schemas/ViewOptionsGrid"
+ }
+ }
},
- "options": {
- "$ref": "#/components/schemas/ViewOptionsForm"
+ {
+ "type": "object",
+ "properties": {
+ "type": {
+ "type": "string",
+ "enum": [
+ "KANBAN"
+ ]
+ },
+ "options": {
+ "$ref": "#/components/schemas/ViewOptionsKanban"
+ }
+ }
+ },
+ {
+ "type": "object",
+ "properties": {
+ "type": {
+ "type": "string",
+ "enum": [
+ "CALENDAR"
+ ]
+ },
+ "options": {
+ "$ref": "#/components/schemas/ViewOptionsCalendar"
+ }
+ }
+ },
+ {
+ "type": "object",
+ "properties": {
+ "type": {
+ "type": "string",
+ "enum": [
+ "GALLERY"
+ ]
+ },
+ "options": {
+ "$ref": "#/components/schemas/ViewOptionsGallery"
+ }
+ }
+ },
+ {
+ "type": "object",
+ "properties": {
+ "type": {
+ "type": "string",
+ "enum": [
+ "FORM"
+ ]
+ },
+ "options": {
+ "$ref": "#/components/schemas/ViewOptionsForm"
+ }
+ }
}
+ ],
+ "discriminator": {
+ "propertyName": "type"
}
}
- ],
- "discriminator": {
- "propertyName": "type"
- }
+ ]
},
"ViewCreate": {
"type": "object",
diff --git a/packages/nocodb/src/services/v3/views-v3.service.ts b/packages/nocodb/src/services/v3/views-v3.service.ts
index ba9763e26a..cfe38c63f8 100644
--- a/packages/nocodb/src/services/v3/views-v3.service.ts
+++ b/packages/nocodb/src/services/v3/views-v3.service.ts
@@ -342,7 +342,7 @@ export class ViewsV3Service {
const formattedView = this.viewBuilder().build(view);
- if (viewTypeMap[view.type] !== ViewTypes.FORM) {
+ if (view.type !== ViewTypes.FORM) {
// get filters
const filters = await this.filtersV3Service.filterList(context, {
viewId: view.id,
@@ -366,7 +366,7 @@ export class ViewsV3Service {
: formattedView.is_default;
// extract the view specific infos
- switch (viewTypeMap[view.type]) {
+ switch (view.type) {
case ViewTypes.GRID:
{
// extract grid specific group by info
@@ -393,12 +393,6 @@ export class ViewsV3Service {
break;
case ViewTypes.KANBAN:
{
- if (formattedView.options?.stackBy) {
- formattedView.options?.stackBy.meta[
- formattedView.options?.stackBy.fieldId
- ];
- delete formattedView.options?.stackBy.meta;
- }
}
break;
case ViewTypes.FORM:
@@ -436,6 +430,17 @@ export class ViewsV3Service {
true,
context,
);
+ if (
+ viewTypeMap[body.type] === ViewTypes.FORM &&
+ body.options.fieldsById
+ ) {
+ validatePayload(
+ `swagger-v3.json#/components/schemas/ViewColumnOption`,
+ body.options,
+ true,
+ context,
+ );
+ }
}
let requestBody = this.v3Tov2ViewBuilders.view().build(body);
diff --git a/packages/nocodb/tests/unit/rest/tests/metaApiV3/view.test.ts b/packages/nocodb/tests/unit/rest/tests/metaApiV3/view.test.ts
index 2ed8d344ac..dc71ba3fcc 100644
--- a/packages/nocodb/tests/unit/rest/tests/metaApiV3/view.test.ts
+++ b/packages/nocodb/tests/unit/rest/tests/metaApiV3/view.test.ts
@@ -153,7 +153,7 @@ export default function () {
sorts: [],
});
expect(updateResponse.body.name).to.eq('MyView32');
- expect((updateResponse.body.options.groups ?? []).length).to.eq(0);
+ expect((updateResponse.body.options?.groups ?? []).length).to.eq(0);
expect((updateResponse.body.sorts ?? []).length).to.eq(0);
const updateResponse2 = await request(context.app)