From b22c7c191955603baaea1bc8aea5ab09c3f2a61c Mon Sep 17 00:00:00 2001 From: "Qingyang(Abby) Hu" Date: Thu, 29 Jun 2023 16:12:11 -0700 Subject: [PATCH] Add embed mode and other URL param options (#4407) UI should render based on URL param options Signed-off-by: abbyhu2000 --- .../components/dashboard_top_nav.tsx | 24 ++++++++++--------- .../application/utils/get_nav_actions.tsx | 9 +------ .../utils/use/use_dashboard_container.tsx | 1 - 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/plugins/dashboard/public/application/components/dashboard_top_nav.tsx b/src/plugins/dashboard/public/application/components/dashboard_top_nav.tsx index 6ce4e394baf7..01fb0c9b91f8 100644 --- a/src/plugins/dashboard/public/application/components/dashboard_top_nav.tsx +++ b/src/plugins/dashboard/public/application/components/dashboard_top_nav.tsx @@ -7,6 +7,7 @@ import { uniqBy } from 'lodash'; import React, { memo, useState, useEffect } from 'react'; import { Filter, IndexPattern } from 'src/plugins/data/public'; import { useCallback } from 'react'; +import { useLocation } from 'react-router-dom'; import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public'; import { getTopNavConfig } from '../top_nav/get_top_nav_config'; import { DashboardAppStateContainer, DashboardAppState, DashboardServices } from '../../types'; @@ -23,7 +24,7 @@ interface DashboardTopNavProps { dashboardContainer?: DashboardContainer; } -enum UrlParams { +export enum UrlParams { SHOW_TOP_MENU = 'show-top-menu', SHOW_QUERY_INPUT = 'show-query-input', SHOW_TIME_FILTER = 'show-time-filter', @@ -49,6 +50,9 @@ const TopNav = ({ const { data, dashboardConfig, setHeaderActionMenu } = services; const { query: queryService } = data; + const location = useLocation(); + const queryParameters = new URLSearchParams(location.search); + const handleRefresh = useCallback( (_payload: any, isUpdate?: boolean) => { if (!isUpdate && dashboardContainer) { @@ -58,15 +62,14 @@ const TopNav = ({ [dashboardContainer] ); - // TODO: this should base on URL - const isEmbeddedExternally = false; + const isEmbeddedExternally = Boolean(queryParameters.get('embed')); - // TODO: should use URL params - const shouldForceDisplay = (param: string): boolean => { - // const [searchParams] = useSearchParams(); - return false; - }; + // url param rules should only apply when embedded (e.g. url?embed=true) + const shouldForceDisplay = (param: string): boolean => + isEmbeddedExternally && Boolean(queryParameters.get(param)); + // When in full screen mode, none of the nav bar components can be forced show + // Only in embed mode, the nav bar components can be forced show base on URL params const shouldShowNavBarComponent = (forceShow: boolean): boolean => (forceShow || isChromeVisible) && !currentAppState?.fullScreenMode; @@ -145,14 +148,13 @@ const TopNav = ({ const showFilterBar = shouldShowFilterBar(forceHideFilterBar); const showSearchBar = showQueryBar || showFilterBar; - return isChromeVisible ? ( + return ( - ) : null; + ); }; export const DashboardTopNav = memo(TopNav); diff --git a/src/plugins/dashboard/public/application/utils/get_nav_actions.tsx b/src/plugins/dashboard/public/application/utils/get_nav_actions.tsx index d3ae06c4ba6a..a36dcad0d785 100644 --- a/src/plugins/dashboard/public/application/utils/get_nav_actions.tsx +++ b/src/plugins/dashboard/public/application/utils/get_nav_actions.tsx @@ -29,14 +29,7 @@ import { saveDashboard } from '../lib'; import { DashboardContainer } from '../embeddable/dashboard_container'; import { DashboardConstants, createDashboardEditUrl } from '../../dashboard_constants'; import { unhashUrl } from '../../../../opensearch_dashboards_utils/public'; - -enum UrlParams { - SHOW_TOP_MENU = 'show-top-menu', - SHOW_QUERY_INPUT = 'show-query-input', - SHOW_TIME_FILTER = 'show-time-filter', - SHOW_FILTER_BAR = 'show-filter-bar', - HIDE_FILTER_BAR = 'hide-filter-bar', -} +import { UrlParams } from '../components/dashboard_top_nav'; interface UrlParamsSelectedMap { [UrlParams.SHOW_TOP_MENU]: boolean; diff --git a/src/plugins/dashboard/public/application/utils/use/use_dashboard_container.tsx b/src/plugins/dashboard/public/application/utils/use/use_dashboard_container.tsx index 583a59ec2ffc..a84e01a4e6eb 100644 --- a/src/plugins/dashboard/public/application/utils/use/use_dashboard_container.tsx +++ b/src/plugins/dashboard/public/application/utils/use/use_dashboard_container.tsx @@ -223,7 +223,6 @@ const createDashboardEmbeddable = ( viewMode: appStateData.viewMode, panels: embeddablesMap, isFullScreenMode: appStateData.fullScreenMode, - isEmbeddedExternally: false, // TODO isEmptyState: getShouldShowEditHelp(appStateData) || getShouldShowViewHelp(appStateData) ||