[8.11] [Dashboard] Add Dashboard title to browser tab title (#171255) (#171454)

# Backport

This will backport the following commits from `main` to `8.11`:
- [[Dashboard] Add Dashboard title to browser tab title
(#171255)](https://github.com/elastic/kibana/pull/171255)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Hannah
Mudge","email":"Heenawter@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-11-16T23:23:22Z","message":"[Dashboard]
Add Dashboard title to browser tab title (#171255)\n\nCloses
https://github.com/elastic/kibana/issues/162800\r\n\r\n##
Summary\r\n\r\nThis PR re-adds dashboard titles to the browser tab
title, which was\r\naccidentally removed as part of the
[portable\r\ndashboards](https://github.com/elastic/kibana/pull/144332)
work. For\r\nexample, if I'm on the sample Logs dashboard, the title of
that\r\ndashboard will now be reflected in the tab title like it was
prior to\r\n`v8.7.0`:\r\n\r\n\r\n| Before | After
|\r\n|--------|--------|\r\n|\r\n![image](e82740a8-b4ef-488e-981a-57b5ef39948a)\r\n|\r\n\r\n\r\nThe
tab title should stay up-to-date with Dashboard title changes,
as\r\ndemonstrated in this
video:\r\n\r\n\r\n651fff50-70f7-46ff-af47-b274fe6b0a19\r\n\r\n\r\n\r\n\r\nNote
that this will **only apply** to dashboards in the dashboard app
-\r\ndashboards outside of the dashboard app should not change the
browser\r\ntab title, unless the consumer does this on their
own.\r\n\r\n### [Flaky
Test\r\nRunner](aec4100b-9e76-4154-b20b-a7054f7f46a1)\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] This was
checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n###
For maintainers\r\n\r\n- [ ] This was checked for breaking API changes
and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"6150f76abae664856a976bc230b9e90dbd844621","branchLabelMapping":{"^v8.12.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","Feature:Dashboard","release_note:fix","Team:Presentation","loe:small","impact:high","backport:prev-minor","ci:cloud-deploy","v8.12.0"],"number":171255,"url":"https://github.com/elastic/kibana/pull/171255","mergeCommit":{"message":"[Dashboard]
Add Dashboard title to browser tab title (#171255)\n\nCloses
https://github.com/elastic/kibana/issues/162800\r\n\r\n##
Summary\r\n\r\nThis PR re-adds dashboard titles to the browser tab
title, which was\r\naccidentally removed as part of the
[portable\r\ndashboards](https://github.com/elastic/kibana/pull/144332)
work. For\r\nexample, if I'm on the sample Logs dashboard, the title of
that\r\ndashboard will now be reflected in the tab title like it was
prior to\r\n`v8.7.0`:\r\n\r\n\r\n| Before | After
|\r\n|--------|--------|\r\n|\r\n![image](e82740a8-b4ef-488e-981a-57b5ef39948a)\r\n|\r\n\r\n\r\nThe
tab title should stay up-to-date with Dashboard title changes,
as\r\ndemonstrated in this
video:\r\n\r\n\r\n651fff50-70f7-46ff-af47-b274fe6b0a19\r\n\r\n\r\n\r\n\r\nNote
that this will **only apply** to dashboards in the dashboard app
-\r\ndashboards outside of the dashboard app should not change the
browser\r\ntab title, unless the consumer does this on their
own.\r\n\r\n### [Flaky
Test\r\nRunner](aec4100b-9e76-4154-b20b-a7054f7f46a1)\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] This was
checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n###
For maintainers\r\n\r\n- [ ] This was checked for breaking API changes
and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"6150f76abae664856a976bc230b9e90dbd844621"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.12.0","labelRegex":"^v8.12.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/171255","number":171255,"mergeCommit":{"message":"[Dashboard]
Add Dashboard title to browser tab title (#171255)\n\nCloses
https://github.com/elastic/kibana/issues/162800\r\n\r\n##
Summary\r\n\r\nThis PR re-adds dashboard titles to the browser tab
title, which was\r\naccidentally removed as part of the
[portable\r\ndashboards](https://github.com/elastic/kibana/pull/144332)
work. For\r\nexample, if I'm on the sample Logs dashboard, the title of
that\r\ndashboard will now be reflected in the tab title like it was
prior to\r\n`v8.7.0`:\r\n\r\n\r\n| Before | After
|\r\n|--------|--------|\r\n|\r\n![image](e82740a8-b4ef-488e-981a-57b5ef39948a)\r\n|\r\n\r\n\r\nThe
tab title should stay up-to-date with Dashboard title changes,
as\r\ndemonstrated in this
video:\r\n\r\n\r\n651fff50-70f7-46ff-af47-b274fe6b0a19\r\n\r\n\r\n\r\n\r\nNote
that this will **only apply** to dashboards in the dashboard app
-\r\ndashboards outside of the dashboard app should not change the
browser\r\ntab title, unless the consumer does this on their
own.\r\n\r\n### [Flaky
Test\r\nRunner](aec4100b-9e76-4154-b20b-a7054f7f46a1)\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] This was
checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n###
For maintainers\r\n\r\n- [ ] This was checked for breaking API changes
and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"6150f76abae664856a976bc230b9e90dbd844621"}}]}]
BACKPORT-->

Co-authored-by: Hannah Mudge <Heenawter@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2023-11-16 19:33:13 -05:00 committed by GitHub
parent 7d33d5a8e6
commit faef45f16e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 12 deletions

View file

@ -40,6 +40,7 @@ import { useDashboardOutcomeValidation } from './hooks/use_dashboard_outcome_val
import { loadDashboardHistoryLocationState } from './locator/load_dashboard_history_location_state';
import type { DashboardCreationOptions } from '../dashboard_container/embeddable/dashboard_container_factory';
import { DashboardTopNav } from '../dashboard_top_nav';
import { DashboardTabTitleSetter } from './tab_title_setter/dashboard_tab_title_setter';
export interface DashboardAppProps {
history: History;
@ -196,15 +197,17 @@ export function DashboardApp({
{!showNoDataPage && (
<>
{dashboardAPI && (
<DashboardTopNav
redirectTo={redirectTo}
embedSettings={embedSettings}
dashboardContainer={dashboardAPI}
/>
<>
<DashboardTabTitleSetter dashboardContainer={dashboardAPI} />
<DashboardTopNav
redirectTo={redirectTo}
embedSettings={embedSettings}
dashboardContainer={dashboardAPI}
/>
</>
)}
{getLegacyConflictWarning?.()}
<DashboardRenderer
ref={setDashboardAPI}
dashboardRedirect={redirectTo}

View file

@ -0,0 +1,37 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { useEffect } from 'react';
import { ViewMode } from '@kbn/embeddable-plugin/common';
import { pluginServices } from '../../services/plugin_services';
import { DashboardAPI } from '../..';
import { getDashboardTitle } from '../_dashboard_app_strings';
export const DashboardTabTitleSetter = ({
dashboardContainer,
}: {
dashboardContainer: DashboardAPI;
}) => {
const {
chrome: { docTitle: chromeDocTitle },
} = pluginServices.getServices();
const title = dashboardContainer.select((state) => state.explicitInput.title);
const lastSavedId = dashboardContainer.select((state) => state.componentState.lastSavedId);
/**
* Set chrome tab title when dashboard's title changes
*/
useEffect(() => {
/** We do not want the tab title to include the "Editing" prefix, so always send in view mode */
chromeDocTitle.change(getDashboardTitle(title, ViewMode.VIEW, !lastSavedId));
}, [title, chromeDocTitle, lastSavedId]);
return null;
};

View file

@ -12,6 +12,7 @@ import { FtrProviderContext } from '../../../ftr_provider_context';
export default function ({ getService, getPageObjects }: FtrProviderContext) {
const retry = getService('retry');
const browser = getService('browser');
const globalNav = getService('globalNav');
const kibanaServer = getService('kibanaServer');
const dashboardSettings = getService('dashboardSettings');
@ -20,6 +21,14 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
describe('dashboard settings', () => {
let originalTitles: string[] = [];
const checkDashboardTitle = async (expectedTitle: string) => {
expect(await browser.getTitle()).to.equal(`${expectedTitle} - Elastic`);
await retry.try(async () => {
const breadcrumb = await globalNav.getLastBreadcrumb();
expect(breadcrumb).to.equal(`Editing ${expectedTitle}`);
});
};
before(async () => {
await kibanaServer.savedObjects.cleanStandardList();
await kibanaServer.importExport.load(
@ -60,13 +69,14 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
});
it('should update the title of the dashboard', async () => {
await checkDashboardTitle('few panels');
const newTitle = 'My awesome dashboard!!1';
await PageObjects.dashboard.openSettingsFlyout();
await dashboardSettings.setCustomPanelTitle(newTitle);
await dashboardSettings.clickApplyButton();
await retry.try(async () => {
expect((await globalNav.getLastBreadcrumb()) === newTitle);
});
await checkDashboardTitle(newTitle);
});
it('should disable quick save when the settings are open', async () => {
@ -106,9 +116,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await dashboardSettings.expectDuplicateTitleWarningDisplayed();
});
await dashboardSettings.clickApplyButton();
await retry.try(async () => {
expect((await globalNav.getLastBreadcrumb()) === newTitle);
});
await checkDashboardTitle(newTitle);
});
});
}