Refactor link rename to update without fetching
parent
b16b8a27e1
commit
77491fad71
|
@ -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<Props, State> {
|
|||
|
||||
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 => {
|
||||
|
|
|
@ -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}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue