Skip to content

Commit

Permalink
Merge pull request #1605 from merico-dev/1603-validation_error-when-i…
Browse files Browse the repository at this point in the history
…mporting-a-dashboard-of-an-older-version

1603 validation error when importing a dashboard of an older version
  • Loading branch information
GerilLeto authored Jan 17, 2025
2 parents c2bab85 + 7447e1f commit d940648
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/api",
"version": "14.5.0",
"version": "14.5.1",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
12 changes: 8 additions & 4 deletions api/src/api_models/dashboard_content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,16 @@ export class DashboardContentCreateRequest {
name: string;

@IsObject()
@Type(() => Content)
// Don't validate content when creating a content,
// so legacy content could have a chance to migrate.
// @Type(() => Content)
@ValidateNested({ each: true })
@ApiModelProperty({
description: 'content stored in json object format',
required: true,
model: 'Content',
})
content: Content;
content: Record<string, any>;

@IsOptional()
@Type(() => Authentication)
Expand Down Expand Up @@ -330,14 +332,16 @@ export class DashboardContentUpdateRequest {

@IsOptional()
@IsObject()
@Type(() => Content)
// Don't validate content when updating a content,
// so legacy content from 'Overwrite with JSON file' could have a chance to migrate.
// @Type(() => Content)
@ValidateNested({ each: true })
@ApiModelProperty({
description: 'content of the dashboard stored in json object format',
required: false,
model: 'Content',
})
content?: Content;
content?: Record<string, any>;

@IsOptional()
@Type(() => Authentication)
Expand Down
5 changes: 3 additions & 2 deletions api/src/controller/dashboard_content.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Account } from '../api_models/account';
import { DashboardPermissionService } from '../services/dashboard_permission.service';
import { channelBuilder, SERVER_CHANNELS, socketEmit } from '../utils/websocket';
import {
Content,
DashboardContentCreateRequest,
DashboardContentIDRequest,
DashboardContentListRequest,
Expand Down Expand Up @@ -118,7 +119,7 @@ export class DashboardContentController implements interfaces.Controller {
auth_role_id,
auth_permissions,
);
const result = await this.dashboardContentService.create(dashboard_id, name, content, req.locale);
const result = await this.dashboardContentService.create(dashboard_id, name, content as Content, req.locale);
res.json(result);
} catch (err) {
next(err);
Expand Down Expand Up @@ -193,7 +194,7 @@ export class DashboardContentController implements interfaces.Controller {
try {
const auth: Account | ApiKey | undefined = req.body.auth;
const { id, name, content } = req.body as DashboardContentUpdateRequest;
const result = await this.dashboardContentService.update(id, name, content, req.locale, auth);
const result = await this.dashboardContentService.update(id, name, content as Content, req.locale, auth);
let auth_id: string | null = null;
let auth_type: 'APIKEY' | 'ACCOUNT' | null = null;
if (auth) {
Expand Down
2 changes: 1 addition & 1 deletion dashboard/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/dashboard",
"version": "14.5.0",
"version": "14.5.1",
"license": "Apache-2.0",
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/root",
"version": "14.5.0",
"version": "14.5.1",
"private": true,
"workspaces": [
"api",
Expand Down
2 changes: 1 addition & 1 deletion settings-form/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/settings-form",
"version": "14.5.0",
"version": "14.5.1",
"license": "Apache-2.0",
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@devtable/website",
"private": true,
"license": "Apache-2.0",
"version": "14.5.0",
"version": "14.5.1",
"scripts": {
"dev": "vite",
"preview": "vite preview"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export function OverwriteWithJSONForm({
title: 'Successful',
message: 'Dashboard is updated',
color: 'green',
loading: false,
autoClose: true,
});
postSubmit();
Expand All @@ -79,6 +80,7 @@ export function OverwriteWithJSONForm({
title: 'Failed',
message: error.message,
color: 'red',
loading: false,
autoClose: true,
});
} finally {
Expand Down
2 changes: 2 additions & 0 deletions website/src/frames/app/navbar/import-dashboard/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const ImportDashboardForm = observer(({ postSubmit }: { postSubmit: () =>
title: 'Successful',
message: 'A new dashboard is created',
color: 'green',
loading: false,
autoClose: true,
});
postSubmit();
Expand All @@ -78,6 +79,7 @@ export const ImportDashboardForm = observer(({ postSubmit }: { postSubmit: () =>
title: 'Failed',
message: error.message,
color: 'red',
loading: false,
autoClose: true,
});
}
Expand Down

0 comments on commit d940648

Please sign in to comment.