@@ -79,7 +79,7 @@ export class DashboardComponent
7979 private generatedTiles = 0 ;
8080
8181 // === DASHBOARD NAME EDITION ===
82- public canEditName = false ;
82+ public canUpdate = false ;
8383 public formActive = false ;
8484
8585 // === STEP CHANGE FOR WORKFLOW ===
@@ -99,8 +99,17 @@ export class DashboardComponent
9999 public refDataValueField = '' ;
100100 public contextRecord : Record | null = null ;
101101
102+ /** @returns type of context element */
103+ get contextType ( ) {
104+ if ( this . dashboard ?. page ?. context ) {
105+ return 'resource' in this . dashboard . page . context ? 'record' : 'element' ;
106+ } else {
107+ return ;
108+ }
109+ }
110+
102111 // === BUTTON ACTIONS ===
103- public buttonActions : ( ButtonActionT & { isHovered : boolean } ) [ ] = [ ] ;
112+ public buttonActions : ButtonActionT [ ] = [ ] ;
104113
105114 // === ROUTE ===
106115 /** @returns is dashboard a step or a page */
@@ -163,28 +172,25 @@ export class DashboardComponent
163172 this . route . queryParams
164173 . pipe ( takeUntil ( this . destroy$ ) )
165174 . subscribe ( ( queryParams ) => {
166- const type : 'record' | 'element' =
167- 'record' in queryParams ? 'record' : 'element' ;
168-
169- // if neither 'record' nor 'element' are in the query params, we are not on a contextual dashboard
170- // and contextualDashboardId will be undefined
171- const resourceId = queryParams [ type ] ;
175+ // If we don't find the view element in the queryParams, then we are not using contextual view
176+ const viewId = queryParams . id ;
172177
173178 // if there is an id, we need to find the contextual dashboard id and load it
174- if ( resourceId ) {
179+ if ( viewId ) {
175180 // load the main dashboard
176181 this . initDashboardWithId ( params . id ) . then ( ( ) => {
177182 // Find the id of the contextual dashboard and load it
178183 const dashboardsWithContext =
179184 this . dashboard ?. page ?. contentWithContext ;
180185
186+ const type = this . contextType ;
181187 // find the contextual dashboard id in the list of dashboards from the parent dashboard
182188 // it's the one where the element or record id matches the one in the query params
183189 const dashboardWithContext = dashboardsWithContext ?. find ( ( d ) => {
184190 if ( type === 'element' )
185- return 'element' in d && d . element === resourceId ;
191+ return 'element' in d && d . element === viewId ;
186192 else if ( type === 'record' )
187- return 'record' in d && d . record === resourceId ;
193+ return 'record' in d && d . record === viewId ;
188194 return false ;
189195 } ) ;
190196
@@ -194,19 +200,23 @@ export class DashboardComponent
194200 } else {
195201 // if we didn't find the contextual dashboard, create it
196202 if ( ! this . dashboard ?. page ?. id ) return ;
197- this . dashboardService
198- . createDashboardWithContext (
199- this . dashboard ?. page ?. id , // parent dashboard page id
200- type , // type of context
201- resourceId // id of the context
202- )
203- . then ( ( res ) => {
204- if ( ! res . data ?. addDashboardWithContext ?. id ) return ;
205- // load the contextual dashboard
206- this . initDashboardWithId (
207- res . data . addDashboardWithContext . id
208- ) ;
209- } ) ;
203+ if ( type ) {
204+ this . dashboardService
205+ . createDashboardWithContext (
206+ this . dashboard ?. page ?. id , // parent dashboard page id
207+ type , // type of context
208+ viewId // id of the context
209+ )
210+ . then ( ( res ) => {
211+ if ( ! res . data ?. addDashboardWithContext ?. id ) return ;
212+ // load the contextual dashboard
213+ this . initDashboardWithId (
214+ res . data . addDashboardWithContext . id
215+ ) ;
216+ } ) ;
217+ } else {
218+ return ;
219+ }
210220 }
211221 } ) ;
212222 } else {
@@ -244,7 +254,7 @@ export class DashboardComponent
244254 this . dashboard = res . data . dashboard ;
245255 this . initContext ( ) ;
246256 this . updateContextOptions ( ) ;
247- this . canEditName =
257+ this . canUpdate =
248258 ( this . dashboard ?. page
249259 ? this . dashboard ?. page ?. canUpdate
250260 : this . dashboard ?. step ?. canUpdate ) || false ;
@@ -262,11 +272,7 @@ export class DashboardComponent
262272 : this . dashboard . step
263273 ? this . dashboard . step . workflow ?. page ?. application ?. id
264274 : '' ;
265- this . buttonActions =
266- this . dashboard . buttons ?. map ( ( b ) => ( {
267- ...b ,
268- isHovered : false ,
269- } ) ) || [ ] ;
275+ this . buttonActions = this . dashboard . buttons || [ ] ;
270276 this . loading = res . loading ;
271277 this . showFilter = this . dashboard . showFilter ;
272278 } else {
@@ -706,7 +712,7 @@ export class DashboardComponent
706712 [ ] ;
707713
708714 this . dashboardService . saveDashboardButtons ( [ ...currButtons , button ] ) ;
709- this . buttonActions . push ( { ... button , isHovered : false } ) ;
715+ this . buttonActions . push ( button ) ;
710716 } ) ;
711717 }
712718
@@ -802,29 +808,30 @@ export class DashboardComponent
802808
803809 // Check if there is a dashboard with the same context
804810 const dashboardsWithContext = this . dashboard ?. page ?. contentWithContext ;
805- const type : 'record' | 'element' =
806- 'resource' in this . dashboard . page . context ? 'record' : 'element' ;
807- const dashboardWithContext = dashboardsWithContext ?. find ( ( d ) => {
808- if ( type === 'element' ) return 'element' in d && d . element === value ;
809- else if ( type === 'record' ) return 'record' in d && d . record === value ;
810- return false ;
811- } ) ;
811+ const type = this . contextType ;
812+ if ( type ) {
813+ const dashboardWithContext = dashboardsWithContext ?. find ( ( d ) => {
814+ if ( type === 'element' ) return 'element' in d && d . element === value ;
815+ else if ( type === 'record' ) return 'record' in d && d . record === value ;
816+ return false ;
817+ } ) ;
812818
813- const urlArr = this . router . url . split ( '/' ) ;
819+ const urlArr = this . router . url . split ( '/' ) ;
814820
815- if ( dashboardWithContext ) {
816- urlArr [ urlArr . length - 1 ] = `${ parentDashboardId } ?${ type } =${ value } ` ;
817- this . router . navigateByUrl ( urlArr . join ( '/' ) ) ;
818- } else {
819- const { data } = await this . dashboardService . createDashboardWithContext (
820- this . dashboard ?. page ?. id ,
821- type ,
822- value
823- ) ;
824- if ( ! data ?. addDashboardWithContext ?. id ) return ;
825- urlArr [ urlArr . length - 1 ] = `${ parentDashboardId } ?${ type } =${ value } ` ;
826- console . log ( 'navigating to url' , urlArr . join ( '/' ) ) ;
827- this . router . navigateByUrl ( urlArr . join ( '/' ) ) ;
821+ if ( dashboardWithContext ) {
822+ urlArr [ urlArr . length - 1 ] = `${ parentDashboardId } ?id=${ value } ` ;
823+ this . router . navigateByUrl ( urlArr . join ( '/' ) ) ;
824+ } else {
825+ const { data } = await this . dashboardService . createDashboardWithContext (
826+ this . dashboard ?. page ?. id ,
827+ type ,
828+ value
829+ ) ;
830+ if ( ! data ?. addDashboardWithContext ?. id ) return ;
831+ urlArr [ urlArr . length - 1 ] = `${ parentDashboardId } ?id=${ value } ` ;
832+ console . log ( 'navigating to url' , urlArr . join ( '/' ) ) ;
833+ this . router . navigateByUrl ( urlArr . join ( '/' ) ) ;
834+ }
828835 }
829836 }
830837
@@ -872,13 +879,7 @@ export class DashboardComponent
872879 event . currentIndex
873880 ) ;
874881
875- this . dashboardService . saveDashboardButtons (
876- this . buttonActions . map ( ( b ) => {
877- // eslint-disable-next-line @typescript-eslint/no-unused-vars
878- const { isHovered, ...button } = b ;
879- return button ;
880- } )
881- ) ;
882+ this . dashboardService . saveDashboardButtons ( this . buttonActions ) ;
882883 }
883884
884885 /**
0 commit comments