Add orgID to export redux state

pull/12819/head
Deniz Kusefoglu 2019-03-21 12:39:42 -07:00
parent 48b0eec4ad
commit 5537719594
9 changed files with 51 additions and 24 deletions

View File

@ -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)))

View File

@ -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<Props> {
}
public render() {
const {
status,
dashboardTemplate,
params: {orgID},
} = this.props
const {status, dashboardTemplate} = this.props
return (
<ExportOverlay
resourceName="Dashboard"
resource={dashboardTemplate}
onDismissOverlay={this.onDismiss}
orgID={orgID}
orgID={this.orgID}
status={status}
/>
)
}
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<Props> {
const mstp = (state: AppState): StateProps => ({
dashboardTemplate: state.templates.exportTemplate.item,
status: state.templates.exportTemplate.status,
orgID: state.templates.exportTemplate.orgID,
})
const mdtp: DispatchProps = {

View File

@ -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<Props> {
params: {id},
convertToTemplate,
} = this.props
convertToTemplate(id)
}
public render() {
const {
taskTemplate,
params: {orgID},
status,
} = this.props
const {taskTemplate, status} = this.props
return (
<ExportOverlay
resourceName="Task"
resource={taskTemplate}
onDismissOverlay={this.onDismiss}
orgID={orgID}
orgID={this.orgID}
status={status}
/>
)
}
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<Props> {
const mstp = (state: AppState): StateProps => ({
taskTemplate: state.templates.exportTemplate.item,
status: state.templates.exportTemplate.status,
orgID: state.templates.exportTemplate.orgID,
})
const mdtp: DispatchProps = {

View File

@ -139,7 +139,6 @@ class ExportOverlay extends PureComponent<Props> {
private handleConvertToTemplate = async (): Promise<void> => {
const {resource, onDismissOverlay, orgID, notify, resourceName} = this.props
const template = addOrgIDToTemplate(resource, orgID)
try {

View File

@ -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<Label[]>(task, 'labels', [])
const labels = viewableLabels(task.labels)
const includedLabels = labels.map(l => labelToIncluded(l))
const relationshipsLabels = labels.map(l => labelToRelationship(l))

View File

@ -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)))

View File

@ -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))
}

View File

@ -42,8 +42,9 @@ class TemplateExportOverlay extends PureComponent<Props> {
}
public render() {
const {exportTemplate, status} = this.props
const {
exportTemplate,
status,
params: {orgID},
} = this.props

View File

@ -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
}