Skip to content

Commit

Permalink
migrate all global presales/app builder dashboards
Browse files Browse the repository at this point in the history
  • Loading branch information
reey committed Nov 6, 2024
1 parent 95f56e8 commit a01d6b7
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,48 @@ import { IManagedObject, InventoryService } from '@c8y/client';
})
export class AppBuilderDashboardMigrationService {
readonly reportPrefix = 'c8y_Dashboard!name!report_';
readonly identifier = 'migratedAppBuilderDashboardsToReport';

constructor(private inventory: InventoryService) {}

async getNotMigratedAppBuilderDashboards() {
const { data: dashboards } = await this.inventory.list({
fragmentType: 'c8y_Dashboard!name!app-builder-db',
fragmentType: 'c8y_Dashboard',
pageSize: 2000,
});

return dashboards.filter(
const noReportDashboards = dashboards.filter(
(dashboard) =>
!Object.keys(dashboard).some((key) => key.startsWith(this.reportPrefix))
);

const dashboardsWithMarker = noReportDashboards.filter((dashboard) =>
Object.keys(dashboard).some(
(key) =>
key.startsWith('global!presales!') ||
key === 'c8y_Dashboard!name!app-builder-db'
)
);
return dashboardsWithMarker;
}

async migrateDashboard(dashboard: IManagedObject) {
const { id, c8y_Dashboard: dashboardDetails } = dashboard;
const { name, icon, priority } = dashboardDetails;

const { data: reportObject } = await this.inventory.create({
name,
name: name || 'Unnamed app builder dashboard',
icon,
priority,
description: null,
c8y_Report: {},
[this.identifier]: {},
});

await this.inventory.update({
id,
[`${this.reportPrefix}${reportObject.id}`]: {},
[this.identifier]: {},
});
}
}

0 comments on commit a01d6b7

Please sign in to comment.