From 2d222baa47748d9499686e4a42aacb4a443a7ba3 Mon Sep 17 00:00:00 2001
From: Henry Liu <645599166@qq.com>
Date: Fri, 25 Oct 2024 04:49:39 +0800
Subject: [PATCH] [Dashboard] show fullscreen mode when url has fullScreenMode
 param (#196275)

## Summary

Closes #174561

Show fullscreen mode when url has fullScreenMode param
`&_a=(fullScreenMode:!t)`

### Screenshot

![20241015-184503](https://github.com/user-attachments/assets/fae01dcc-f081-4314-84f9-3923adc76e5b)

---------

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: Hannah Mudge <Heenawter@users.noreply.github.com>
(cherry picked from commit 72c0b81994d28f3983c2d21d662bd025653054fa)
---
 .../dashboard/public/dashboard_api/get_dashboard_api.ts    | 3 ++-
 src/plugins/dashboard/public/dashboard_api/types.ts        | 1 +
 .../dashboard/public/dashboard_app/dashboard_app.tsx       | 3 +++
 .../embeddable/create/create_dashboard.ts                  | 1 +
 .../embeddable/dashboard_container.test.tsx                | 1 +
 .../dashboard_container/embeddable/dashboard_container.tsx | 1 +
 .../dashboard_top_nav/internal_dashboard_top_nav.tsx       | 7 -------
 src/plugins/dashboard/public/mocks.tsx                     | 1 +
 8 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/plugins/dashboard/public/dashboard_api/get_dashboard_api.ts b/src/plugins/dashboard/public/dashboard_api/get_dashboard_api.ts
index 3db6129c7c6f..2af37846eecd 100644
--- a/src/plugins/dashboard/public/dashboard_api/get_dashboard_api.ts
+++ b/src/plugins/dashboard/public/dashboard_api/get_dashboard_api.ts
@@ -19,6 +19,7 @@ export interface InitialComponentState {
   lastSavedInput: DashboardContainerInput;
   lastSavedId: string | undefined;
   managed: boolean;
+  fullScreenMode: boolean;
 }
 
 export function getDashboardApi(
@@ -26,7 +27,7 @@ export function getDashboardApi(
   untilEmbeddableLoaded: (id: string) => Promise<unknown>
 ) {
   const animatePanelTransforms$ = new BehaviorSubject(false); // set panel transforms to false initially to avoid panels animating on initial render.
-  const fullScreenMode$ = new BehaviorSubject(false);
+  const fullScreenMode$ = new BehaviorSubject(initialComponentState.fullScreenMode);
   const managed$ = new BehaviorSubject(initialComponentState.managed);
   const savedObjectId$ = new BehaviorSubject<string | undefined>(initialComponentState.lastSavedId);
 
diff --git a/src/plugins/dashboard/public/dashboard_api/types.ts b/src/plugins/dashboard/public/dashboard_api/types.ts
index e0b6b8d3e482..ec89a93dcd66 100644
--- a/src/plugins/dashboard/public/dashboard_api/types.ts
+++ b/src/plugins/dashboard/public/dashboard_api/types.ts
@@ -68,6 +68,7 @@ export interface DashboardCreationOptions {
 
   validateLoadedSavedObject?: (result: LoadDashboardReturn) => 'valid' | 'invalid' | 'redirected';
 
+  fullScreenMode?: boolean;
   isEmbeddedExternally?: boolean;
 
   getEmbeddableAppContext?: (dashboardId?: string) => EmbeddableAppContext;
diff --git a/src/plugins/dashboard/public/dashboard_app/dashboard_app.tsx b/src/plugins/dashboard/public/dashboard_app/dashboard_app.tsx
index f7ca6b552893..400d56e97df0 100644
--- a/src/plugins/dashboard/public/dashboard_app/dashboard_app.tsx
+++ b/src/plugins/dashboard/public/dashboard_app/dashboard_app.tsx
@@ -157,6 +157,9 @@ export function DashboardApp({
       },
       getInitialInput,
       validateLoadedSavedObject: validateOutcome,
+      fullScreenMode:
+        kbnUrlStateStorage.get<{ fullScreenMode?: boolean }>(DASHBOARD_STATE_STORAGE_KEY)
+          ?.fullScreenMode ?? false,
       isEmbeddedExternally: Boolean(embedSettings), // embed settings are only sent if the dashboard URL has `embed=true`
       getEmbeddableAppContext: (dashboardId) => ({
         currentAppId: DASHBOARD_APP_ID,
diff --git a/src/plugins/dashboard/public/dashboard_container/embeddable/create/create_dashboard.ts b/src/plugins/dashboard/public/dashboard_container/embeddable/create/create_dashboard.ts
index 3eab6c641ee8..2510f2e015df 100644
--- a/src/plugins/dashboard/public/dashboard_container/embeddable/create/create_dashboard.ts
+++ b/src/plugins/dashboard/public/dashboard_container/embeddable/create/create_dashboard.ts
@@ -110,6 +110,7 @@ export const createDashboard = async (
     },
     lastSavedId: savedObjectId,
     managed: savedObjectResult.managed ?? false,
+    fullScreenMode: creationOptions?.fullScreenMode ?? false,
   };
 
   const dashboardContainer = new DashboardContainer(
diff --git a/src/plugins/dashboard/public/dashboard_container/embeddable/dashboard_container.test.tsx b/src/plugins/dashboard/public/dashboard_container/embeddable/dashboard_container.test.tsx
index 4805c890f5e9..167ee2605516 100644
--- a/src/plugins/dashboard/public/dashboard_container/embeddable/dashboard_container.test.tsx
+++ b/src/plugins/dashboard/public/dashboard_container/embeddable/dashboard_container.test.tsx
@@ -178,6 +178,7 @@ test('searchSessionId propagates to children', async () => {
       lastSavedInput: sampleInput,
       lastSavedId: undefined,
       managed: false,
+      fullScreenMode: false,
     }
   );
   container?.setControlGroupApi(mockControlGroupApi);
diff --git a/src/plugins/dashboard/public/dashboard_container/embeddable/dashboard_container.tsx b/src/plugins/dashboard/public/dashboard_container/embeddable/dashboard_container.tsx
index e508e511d41c..a6765732c064 100644
--- a/src/plugins/dashboard/public/dashboard_container/embeddable/dashboard_container.tsx
+++ b/src/plugins/dashboard/public/dashboard_container/embeddable/dashboard_container.tsx
@@ -314,6 +314,7 @@ export class DashboardContainer
             isEmbeddedExternally: false,
             lastSavedInput: initialInput,
             lastSavedId: undefined,
+            fullScreenMode: false,
             managed: false,
           },
       (id: string) => this.untilEmbeddableLoaded(id)
diff --git a/src/plugins/dashboard/public/dashboard_top_nav/internal_dashboard_top_nav.tsx b/src/plugins/dashboard/public/dashboard_top_nav/internal_dashboard_top_nav.tsx
index 6ca2298272c0..bf2be799dcc1 100644
--- a/src/plugins/dashboard/public/dashboard_top_nav/internal_dashboard_top_nav.tsx
+++ b/src/plugins/dashboard/public/dashboard_top_nav/internal_dashboard_top_nav.tsx
@@ -123,13 +123,6 @@ export function InternalDashboardTopNav({
     dashboardTitleRef.current?.focus();
   }, [title, viewMode]);
 
-  /**
-   * Manage chrome visibility when dashboard is embedded.
-   */
-  useEffect(() => {
-    if (!embedSettings) coreServices.chrome.setIsVisible(viewMode !== 'print');
-  }, [embedSettings, viewMode]);
-
   /**
    * populate recently accessed, and set is chrome visible.
    */
diff --git a/src/plugins/dashboard/public/mocks.tsx b/src/plugins/dashboard/public/mocks.tsx
index 17081084d5de..2374788e60ea 100644
--- a/src/plugins/dashboard/public/mocks.tsx
+++ b/src/plugins/dashboard/public/mocks.tsx
@@ -99,6 +99,7 @@ export function buildMockDashboard({
       lastSavedInput: initialInput,
       lastSavedId: savedObjectId,
       managed: false,
+      fullScreenMode: false,
     }
   );
   dashboardContainer?.setControlGroupApi(mockControlGroupApi);