diff --git a/ui/src/dashboards/containers/DashboardPage.tsx b/ui/src/dashboards/containers/DashboardPage.tsx index 11b4d6a48d..5e8716426e 100644 --- a/ui/src/dashboards/containers/DashboardPage.tsx +++ b/ui/src/dashboards/containers/DashboardPage.tsx @@ -24,7 +24,10 @@ import * as notifyActions from 'src/shared/actions/notifications' import idNormalizer, {TYPE_ID} from 'src/normalizers/id' import {millisecondTimeRange} from 'src/dashboards/utils/time' import {getDeep} from 'src/utils/wrappers' -import {updateActiveDashboardLink} from 'src/dashboards/utils/dashboardSwitcherLinks' +import { + updateActiveDashboardLink, + updateDashboadLinkName, +} from 'src/dashboards/utils/dashboardSwitcherLinks' // APIs import {loadDashboardLinks} from 'src/dashboards/apis' @@ -442,7 +445,17 @@ class DashboardPage extends Component { this.props.updateDashboard(newDashboard) await this.props.putDashboard(newDashboard) - await this.getDashboardLinks() + this.updateLinkName() + } + + private updateLinkName = () => { + this.setState((prevState, props) => ({ + ...prevState, + dashboardLinks: updateDashboadLinkName( + prevState.dashboardLinks, + props.dashboard + ), + })) } private handleDeleteDashboardCell = (cell: DashboardsModels.Cell): void => { diff --git a/ui/src/dashboards/utils/dashboardSwitcherLinks.ts b/ui/src/dashboards/utils/dashboardSwitcherLinks.ts index 6538fcfb3a..7bab002ada 100644 --- a/ui/src/dashboards/utils/dashboardSwitcherLinks.ts +++ b/ui/src/dashboards/utils/dashboardSwitcherLinks.ts @@ -35,3 +35,27 @@ export const updateActiveDashboardLink = ( return {...dashboardLinks, active} } + +export const updateDashboadLinkName = ( + dashboardLinks: DashboardSwitcherLinks, + dashboard: Dashboard +): DashboardSwitcherLinks => { + const {name} = dashboard + let active = dashboardLinks.active + + const links = dashboardLinks.links.map(link => { + if (link.key === String(dashboard.id)) { + const newLink = {...link, text: name} + + if (link === active) { + active = newLink + } + + return newLink + } + + return link + }) + + return {links, active} +}