-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Update updatedat field on dashboards after edition #16964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
b78cb3b
ba2771e
7b4eac9
7388b29
8b71422
194506c
49a3059
7bf0ff4
f4dc983
e966054
2967248
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { Module } from '@nestjs/common'; | ||
|
|
||
| import { DashboardSyncService } from 'src/engine/metadata-modules/dashboard/services/dashboard-sync.service'; | ||
| import { WorkspaceManyOrAllFlatEntityMapsCacheModule } from 'src/engine/metadata-modules/flat-entity/services/workspace-many-or-all-flat-entity-maps-cache.module'; | ||
| import { TwentyORMModule } from 'src/engine/twenty-orm/twenty-orm.module'; | ||
|
|
||
| @Module({ | ||
| imports: [TwentyORMModule, WorkspaceManyOrAllFlatEntityMapsCacheModule], | ||
| providers: [DashboardSyncService], | ||
| exports: [DashboardSyncService], | ||
| }) | ||
| export class DashboardModule {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| import { Injectable, Logger } from '@nestjs/common'; | ||
|
|
||
| import { isDefined } from 'twenty-shared/utils'; | ||
|
|
||
| import { WorkspaceManyOrAllFlatEntityMapsCacheService } from 'src/engine/metadata-modules/flat-entity/services/workspace-many-or-all-flat-entity-maps-cache.service'; | ||
| import { GlobalWorkspaceOrmManager } from 'src/engine/twenty-orm/global-workspace-datasource/global-workspace-orm.manager'; | ||
| import { buildSystemAuthContext } from 'src/engine/twenty-orm/utils/build-system-auth-context.util'; | ||
|
|
||
| @Injectable() | ||
| export class DashboardSyncService { | ||
| private readonly logger = new Logger(DashboardSyncService.name); | ||
|
|
||
| constructor( | ||
| private readonly globalWorkspaceOrmManager: GlobalWorkspaceOrmManager, | ||
| private readonly workspaceManyOrAllFlatEntityMapsCacheService: WorkspaceManyOrAllFlatEntityMapsCacheService, | ||
| ) {} | ||
|
|
||
| async updateLinkedDashboardsUpdatedAtByPageLayoutId({ | ||
| pageLayoutId, | ||
| workspaceId, | ||
| }: { | ||
| pageLayoutId: string; | ||
| workspaceId: string; | ||
| }): Promise<void> { | ||
| const authContext = buildSystemAuthContext(workspaceId); | ||
|
|
||
| try { | ||
| await this.globalWorkspaceOrmManager.executeInWorkspaceContext( | ||
| authContext, | ||
| async () => { | ||
| const dashboardRepository = | ||
| await this.globalWorkspaceOrmManager.getRepository( | ||
| workspaceId, | ||
| 'dashboard', | ||
| { shouldBypassPermissionChecks: true }, | ||
| ); | ||
|
|
||
| await dashboardRepository.update( | ||
| { pageLayoutId }, | ||
| { updatedAt: new Date() }, | ||
| ); | ||
| }, | ||
| ); | ||
| } catch (error) { | ||
| this.logger.error( | ||
| `Failed to update dashboard updatedAt for page layout ${pageLayoutId}: ${error}`, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Error logging loses stack trace. When concatenating Prompt for AI agents |
||
| ); | ||
| } | ||
| } | ||
|
|
||
| async updateLinkedDashboardsUpdatedAtByTabId({ | ||
| tabId, | ||
| workspaceId, | ||
| }: { | ||
| tabId: string; | ||
| workspaceId: string; | ||
| }): Promise<void> { | ||
| const { flatPageLayoutTabMaps } = | ||
bosiraphael marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| await this.workspaceManyOrAllFlatEntityMapsCacheService.getOrRecomputeManyOrAllFlatEntityMaps( | ||
| { | ||
| workspaceId, | ||
| flatMapsKeys: ['flatPageLayoutTabMaps'], | ||
| }, | ||
| ); | ||
|
|
||
| const tab = flatPageLayoutTabMaps.byId[tabId]; | ||
|
|
||
| if (!isDefined(tab)) { | ||
| return; | ||
| } | ||
|
|
||
| await this.updateLinkedDashboardsUpdatedAtByPageLayoutId({ | ||
| pageLayoutId: tab.pageLayoutId, | ||
| workspaceId, | ||
| }); | ||
| } | ||
|
|
||
| async updateLinkedDashboardsUpdatedAtByWidgetId({ | ||
| widgetId, | ||
| workspaceId, | ||
| }: { | ||
| widgetId: string; | ||
| workspaceId: string; | ||
| }): Promise<void> { | ||
| const { flatPageLayoutWidgetMaps, flatPageLayoutTabMaps } = | ||
| await this.workspaceManyOrAllFlatEntityMapsCacheService.getOrRecomputeManyOrAllFlatEntityMaps( | ||
| { | ||
| workspaceId, | ||
| flatMapsKeys: ['flatPageLayoutWidgetMaps', 'flatPageLayoutTabMaps'], | ||
| }, | ||
| ); | ||
|
|
||
| const widget = flatPageLayoutWidgetMaps.byId[widgetId]; | ||
|
|
||
| if (!isDefined(widget)) { | ||
| return; | ||
| } | ||
|
|
||
| const tab = flatPageLayoutTabMaps.byId[widget.pageLayoutTabId]; | ||
|
|
||
| if (!isDefined(tab)) { | ||
| return; | ||
| } | ||
|
|
||
| await this.updateLinkedDashboardsUpdatedAtByPageLayoutId({ | ||
| pageLayoutId: tab.pageLayoutId, | ||
| workspaceId, | ||
| }); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ import { Injectable } from '@nestjs/common'; | |
| import { isDefined } from 'twenty-shared/utils'; | ||
|
|
||
| import { ApplicationService } from 'src/engine/core-modules/application/application.service'; | ||
| import { DashboardSyncService } from 'src/engine/metadata-modules/dashboard/services/dashboard-sync.service'; | ||
| import { WorkspaceManyOrAllFlatEntityMapsCacheService } from 'src/engine/metadata-modules/flat-entity/services/workspace-many-or-all-flat-entity-maps-cache.service'; | ||
| import { findFlatEntityByIdInFlatEntityMapsOrThrow } from 'src/engine/metadata-modules/flat-entity/utils/find-flat-entity-by-id-in-flat-entity-maps-or-throw.util'; | ||
| import { FlatPageLayoutTabMaps } from 'src/engine/metadata-modules/flat-page-layout-tab/types/flat-page-layout-tab-maps.type'; | ||
|
|
@@ -36,6 +37,7 @@ export class PageLayoutTabService { | |
| private readonly workspaceMigrationValidateBuildAndRunService: WorkspaceMigrationValidateBuildAndRunService, | ||
| private readonly workspaceManyOrAllFlatEntityMapsCacheService: WorkspaceManyOrAllFlatEntityMapsCacheService, | ||
| private readonly applicationService: ApplicationService, | ||
| private readonly dashboardSyncService: DashboardSyncService, | ||
| ) {} | ||
|
|
||
| async findByPageLayoutId( | ||
|
|
@@ -156,6 +158,11 @@ export class PageLayoutTabService { | |
| ); | ||
| } | ||
|
|
||
| await this.dashboardSyncService.updateLinkedDashboardsUpdatedAtByTabId({ | ||
| tabId: flatPageLayoutTabToCreate.id, | ||
| workspaceId, | ||
| }); | ||
|
|
||
| const { flatPageLayoutTabMaps: recomputedFlatPageLayoutTabMaps } = | ||
| await this.workspaceManyOrAllFlatEntityMapsCacheService.getOrRecomputeManyOrAllFlatEntityMaps( | ||
| { | ||
|
|
@@ -218,6 +225,11 @@ export class PageLayoutTabService { | |
| ); | ||
| } | ||
|
|
||
| await this.dashboardSyncService.updateLinkedDashboardsUpdatedAtByTabId({ | ||
| tabId: id, | ||
| workspaceId, | ||
| }); | ||
|
|
||
| const { flatPageLayoutTabMaps: recomputedFlatPageLayoutTabMaps } = | ||
| await this.workspaceManyOrAllFlatEntityMapsCacheService.getOrRecomputeManyOrAllFlatEntityMaps( | ||
| { | ||
|
|
@@ -274,6 +286,11 @@ export class PageLayoutTabService { | |
| ); | ||
| } | ||
|
|
||
| await this.dashboardSyncService.updateLinkedDashboardsUpdatedAtByTabId({ | ||
bosiraphael marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| tabId: id, | ||
| workspaceId, | ||
| }); | ||
|
|
||
| const { flatPageLayoutTabMaps: recomputedFlatPageLayoutTabMaps } = | ||
| await this.workspaceManyOrAllFlatEntityMapsCacheService.getOrRecomputeManyOrAllFlatEntityMaps( | ||
| { | ||
|
|
@@ -327,6 +344,11 @@ export class PageLayoutTabService { | |
| ); | ||
| } | ||
|
|
||
| await this.dashboardSyncService.updateLinkedDashboardsUpdatedAtByTabId({ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we want to actually destroy the dashboard in this case?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is already handled: in the page layout service |
||
| tabId: id, | ||
bosiraphael marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| workspaceId, | ||
| }); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
|
|
@@ -370,6 +392,11 @@ export class PageLayoutTabService { | |
| ); | ||
| } | ||
|
|
||
| await this.dashboardSyncService.updateLinkedDashboardsUpdatedAtByTabId({ | ||
| tabId: id, | ||
| workspaceId, | ||
| }); | ||
|
|
||
| const { flatPageLayoutTabMaps: recomputedFlatPageLayoutTabMaps } = | ||
| await this.workspaceManyOrAllFlatEntityMapsCacheService.getOrRecomputeManyOrAllFlatEntityMaps( | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.