Skip to content

Commit

Permalink
fix: enable cloning and exporting of dashboards (#16614)
Browse files Browse the repository at this point in the history
  • Loading branch information
drdelambre authored Jan 22, 2020
1 parent 8b21093 commit 47b43bf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
12 changes: 6 additions & 6 deletions ui/src/dashboards/actions/thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,19 @@ export const createDashboard = () => async (
}
}

export const cloneDashboard = (dashboard: Dashboard) => async (
dispatch,
getState: GetState
): Promise<void> => {
export const cloneDashboard = (
dashboardID: string,
dashboardName: string
) => async (dispatch, getState: GetState): Promise<void> => {
try {
const state = getState()

const org = getOrg(state)
const dashboards = getAll<Dashboard>(state, ResourceType.Dashboards)
const allDashboardNames = dashboards.map(d => d.name)
const clonedName = incrementCloneName(allDashboardNames, dashboard.name)
const clonedName = incrementCloneName(allDashboardNames, dashboardName)

const getResp = await api.getDashboard({dashboardID: dashboard.id})
const getResp = await api.getDashboard({dashboardID})

if (getResp.status !== 200) {
throw new Error(getResp.data.message)
Expand Down
19 changes: 12 additions & 7 deletions ui/src/dashboards/components/dashboard_index/DashboardCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {createLabel as createLabelAsync} from 'src/labels/actions'
import {viewableLabels} from 'src/labels/selectors'

// Types
import {AppState, Dashboard, Label} from 'src/types'
import {AppState, Label} from 'src/types'

// Constants
import {DEFAULT_DASHBOARD_NAME} from 'src/dashboards/constants'
Expand All @@ -46,7 +46,7 @@ interface StateProps {

interface DispatchProps {
onDeleteDashboard: typeof deleteDashboard
onCloneDashboard: (dashboard: Dashboard) => void
onCloneDashboard: typeof cloneDashboard
onUpdateDashboard: typeof updateDashboard
onAddDashboardLabel: typeof addDashboardLabel
onRemoveDashboardLabel: typeof removeDashboardLabel
Expand Down Expand Up @@ -116,9 +116,13 @@ class DashboardCard extends PureComponent<Props> {
onUpdateDashboard(id, {name})
}

private get contextMenu(): JSX.Element {
const {onCloneDashboard} = this.props
private handleCloneDashboard = () => {
const {id, name, onCloneDashboard} = this.props

onCloneDashboard(id, name)
}

private get contextMenu(): JSX.Element {
return (
<Context>
<Context.Menu icon={IconFont.CogThick}>
Expand All @@ -128,7 +132,7 @@ class DashboardCard extends PureComponent<Props> {
icon={IconFont.Duplicate}
color={ComponentColor.Secondary}
>
<Context.Item label="Clone" action={onCloneDashboard} />
<Context.Item label="Clone" action={this.handleCloneDashboard} />
</Context.Menu>
<Context.Menu
icon={IconFont.Trash}
Expand Down Expand Up @@ -188,10 +192,11 @@ class DashboardCard extends PureComponent<Props> {
private handleExport = () => {
const {
router,
params: {orgID, dashboardID},
params: {orgID},
id,
} = this.props

router.push(`/orgs/${orgID}/dashboards/${dashboardID}/export`)
router.push(`/orgs/${orgID}/dashboards/${id}/export`)
}
}

Expand Down

0 comments on commit 47b43bf

Please sign in to comment.