diff --git a/ui/src/dashboards/actions/index.ts b/ui/src/dashboards/actions/index.ts index e21f7626e3..5971982029 100644 --- a/ui/src/dashboards/actions/index.ts +++ b/ui/src/dashboards/actions/index.ts @@ -488,7 +488,9 @@ export const convertToTemplate = (dashboardID: string) => async ( const variables = filterUnusedVars(allVariables, views) const dashboardTemplate = dashboardToTemplate(dashboard, views, variables) - dispatch(setExportTemplate(RemoteDataState.Done, dashboardTemplate)) + const orgID = dashboard.orgID // TODO remove when org is implicit app state + + dispatch(setExportTemplate(RemoteDataState.Done, dashboardTemplate, orgID)) } catch (error) { dispatch(setExportTemplate(RemoteDataState.Error)) dispatch(notify(copy.createTemplateFailed(error))) diff --git a/ui/src/dashboards/components/DashboardExportOverlay.tsx b/ui/src/dashboards/components/DashboardExportOverlay.tsx index 6066587a58..11e6bc0458 100644 --- a/ui/src/dashboards/components/DashboardExportOverlay.tsx +++ b/ui/src/dashboards/components/DashboardExportOverlay.tsx @@ -26,6 +26,7 @@ interface DispatchProps { interface StateProps { dashboardTemplate: DocumentCreate status: RemoteDataState + orgID: string } type Props = OwnProps & StateProps & DispatchProps & WithRouterProps @@ -41,23 +42,25 @@ class DashboardExportOverlay extends PureComponent { } public render() { - const { - status, - dashboardTemplate, - params: {orgID}, - } = this.props + const {status, dashboardTemplate} = this.props return ( ) } + private get orgID() { + const orgFromExistingResource = this.props.orgID + const orgInRoutes = this.props.params.orgID + return orgFromExistingResource || orgInRoutes + } + private onDismiss = () => { const {router, clearExportTemplate} = this.props @@ -69,6 +72,7 @@ class DashboardExportOverlay extends PureComponent { const mstp = (state: AppState): StateProps => ({ dashboardTemplate: state.templates.exportTemplate.item, status: state.templates.exportTemplate.status, + orgID: state.templates.exportTemplate.orgID, }) const mdtp: DispatchProps = { diff --git a/ui/src/organizations/components/TaskExportOverlay.tsx b/ui/src/organizations/components/TaskExportOverlay.tsx index 2cff383449..59657bbb7c 100644 --- a/ui/src/organizations/components/TaskExportOverlay.tsx +++ b/ui/src/organizations/components/TaskExportOverlay.tsx @@ -26,6 +26,7 @@ interface DispatchProps { interface StateProps { taskTemplate: DocumentCreate status: RemoteDataState + orgID: string } type Props = OwnProps & StateProps & DispatchProps & WithRouterProps @@ -36,27 +37,30 @@ class TaskExportOverlay extends PureComponent { params: {id}, convertToTemplate, } = this.props + convertToTemplate(id) } public render() { - const { - taskTemplate, - params: {orgID}, - status, - } = this.props + const {taskTemplate, status} = this.props return ( ) } + private get orgID() { + const orgFromExistingResource = this.props.orgID + const orgInRoutes = this.props.params.orgID + return orgFromExistingResource || orgInRoutes + } + private onDismiss = () => { const {router, clearExportTemplate} = this.props @@ -68,6 +72,7 @@ class TaskExportOverlay extends PureComponent { const mstp = (state: AppState): StateProps => ({ taskTemplate: state.templates.exportTemplate.item, status: state.templates.exportTemplate.status, + orgID: state.templates.exportTemplate.orgID, }) const mdtp: DispatchProps = { diff --git a/ui/src/shared/components/ExportOverlay.tsx b/ui/src/shared/components/ExportOverlay.tsx index 7ce013b78a..9b1452de03 100644 --- a/ui/src/shared/components/ExportOverlay.tsx +++ b/ui/src/shared/components/ExportOverlay.tsx @@ -139,7 +139,6 @@ class ExportOverlay extends PureComponent { private handleConvertToTemplate = async (): Promise => { const {resource, onDismissOverlay, orgID, notify, resourceName} = this.props - const template = addOrgIDToTemplate(resource, orgID) try { diff --git a/ui/src/shared/utils/resourceToTemplate.ts b/ui/src/shared/utils/resourceToTemplate.ts index 68e7d9abbd..0e141053ae 100644 --- a/ui/src/shared/utils/resourceToTemplate.ts +++ b/ui/src/shared/utils/resourceToTemplate.ts @@ -7,6 +7,7 @@ import { ITemplate, Variable, } from '@influxdata/influx' +import {viewableLabels} from 'src/labels/selectors' const CURRENT_TEMPLATE_VERSION = '1' @@ -71,7 +72,7 @@ export const taskToTemplate = ( 'offset', ]) - const labels = getDeep(task, 'labels', []) + const labels = viewableLabels(task.labels) const includedLabels = labels.map(l => labelToIncluded(l)) const relationshipsLabels = labels.map(l => labelToRelationship(l)) diff --git a/ui/src/tasks/actions/index.ts b/ui/src/tasks/actions/index.ts index 27b2ffd57f..0c334187c2 100644 --- a/ui/src/tasks/actions/index.ts +++ b/ui/src/tasks/actions/index.ts @@ -496,8 +496,9 @@ export const convertToTemplate = (taskID: string) => async ( const task = await client.tasks.get(taskID) const taskTemplate = taskToTemplate(task) + const orgID = task.orgID // TODO remove when org is implicit app state - dispatch(setExportTemplate(RemoteDataState.Done, taskTemplate)) + dispatch(setExportTemplate(RemoteDataState.Done, taskTemplate, orgID)) } catch (error) { dispatch(setExportTemplate(RemoteDataState.Error)) dispatch(notify(copy.createTemplateFailed(error))) diff --git a/ui/src/templates/actions/index.ts b/ui/src/templates/actions/index.ts index df5f753136..d8e8ecdb1a 100644 --- a/ui/src/templates/actions/index.ts +++ b/ui/src/templates/actions/index.ts @@ -54,15 +54,16 @@ export const setTemplatesStatus = ( export interface SetExportTemplate { type: ActionTypes.SetExportTemplate - payload: {status: RemoteDataState; item?: DocumentCreate} + payload: {status: RemoteDataState; item?: DocumentCreate; orgID: string} } export const setExportTemplate = ( status: RemoteDataState, - item?: DocumentCreate + item?: DocumentCreate, + orgID?: string ): SetExportTemplate => ({ type: ActionTypes.SetExportTemplate, - payload: {status, item}, + payload: {status, item, orgID}, }) export const getTemplatesForOrg = (orgName: string) => async dispatch => { @@ -91,6 +92,6 @@ export const convertToTemplate = (id: string) => async ( } } -export const clearExportTemplate = async () => async dispatch => { +export const clearExportTemplate = () => async dispatch => { dispatch(setExportTemplate(RemoteDataState.NotStarted, null)) } diff --git a/ui/src/templates/components/TemplateExportOverlay.tsx b/ui/src/templates/components/TemplateExportOverlay.tsx index 97d0870b82..2f6e242bff 100644 --- a/ui/src/templates/components/TemplateExportOverlay.tsx +++ b/ui/src/templates/components/TemplateExportOverlay.tsx @@ -42,8 +42,9 @@ class TemplateExportOverlay extends PureComponent { } public render() { - const {exportTemplate, status} = this.props const { + exportTemplate, + status, params: {orgID}, } = this.props diff --git a/ui/src/templates/reducers/index.ts b/ui/src/templates/reducers/index.ts index 21b21c48a9..23220a83fd 100644 --- a/ui/src/templates/reducers/index.ts +++ b/ui/src/templates/reducers/index.ts @@ -6,13 +6,17 @@ import {RemoteDataState} from 'src/types' export interface TemplatesState { status: RemoteDataState items: TemplateSummary[] - exportTemplate: {status: RemoteDataState; item: DocumentCreate} + exportTemplate: {status: RemoteDataState; item: DocumentCreate; orgID: string} } const defaultState = (): TemplatesState => ({ status: RemoteDataState.NotStarted, items: [], - exportTemplate: {status: RemoteDataState.NotStarted, item: null}, + exportTemplate: { + status: RemoteDataState.NotStarted, + item: null, + orgID: null, + }, }) const templatesReducer = ( @@ -39,10 +43,19 @@ const templatesReducer = ( } case ActionTypes.SetExportTemplate: { - const {status, item} = action.payload + const {status, item, orgID} = action.payload draftState.exportTemplate.status = status + if (item) { draftState.exportTemplate.item = item + } else { + draftState.exportTemplate.item = null + } + + if (orgID) { + draftState.exportTemplate.orgID = orgID + } else { + draftState.exportTemplate.orgID = null } return }