Skip to content

Commit

Permalink
Export editor creation
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfyWin committed Oct 1, 2024
1 parent bc4ba17 commit 30de2ee
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import React from 'react'
import {PropTypes as T} from 'prop-types'

import {trans} from '#/main/app/intl'
import {Tool} from '#/main/core/tool'

import {TransferForm} from '#/main/transfer/components/form'
import {ExportList} from '#/main/transfer/tools/export/containers/list'
import {ExportForm} from '#/main/transfer/tools/export/containers/form'
import {ExportDetails} from '#/main/transfer/tools/export/containers/details'
import {ExportEditor} from '#/main/transfer/tools/export/editor/containers/main'

const ExportTool = (props) =>
<Tool
Expand All @@ -21,17 +19,7 @@ const ExportTool = (props) =>
}, {
path: '/new',
disabled: !props.canExport,
render: () => (
<TransferForm
path={props.path+'/new'}
title={trans('export', {}, 'transfer')}
explanation={props.explanation}
openForm={props.openForm}
contextData={props.contextData}
>
<ExportForm />
</TransferForm>
)
render: () => (<ExportEditor path={props.path}/>)
}, {
path: '/:id',
onEnter: (params) => props.open(params.id),
Expand All @@ -42,11 +30,8 @@ const ExportTool = (props) =>

ExportTool.propTypes = {
path: T.string.isRequired,
contextData: T.object,
explanation: T.object,
canExport: T.bool.isRequired,
open: T.func.isRequired,
openForm: T.func.isRequired
open: T.func.isRequired
}

export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ import {ExportEditorPlaning} from '#/main/transfer/tools/export/editor/component
import {ExportEditorOverview} from '#/main/transfer/tools/export/editor/components/overview'

const ExportEditor = (props) => {
const entity = props.formData.action.substring(0, props.formData.action.indexOf('_'))
const action = props.formData.action.substring(props.formData.action.indexOf('_') + 1)
const entity = typeof props.formData.action !== 'undefined' ? props.formData.action.substring(0, props.formData.action.indexOf('_')) : ''
const action = typeof props.formData.action !== 'undefined' ? props.formData.action.substring(props.formData.action.indexOf('_') + 1) : ''

return (
<Editor
path={props.path + '/edit'}
title={get(props.formData, 'name')}
path={props.path + (props.isNew ? '/new' : '/edit')}
title={props.isNew ? trans('export', {}, 'transfer') : get(props.formData, 'name')}
name={selectors.FORM_NAME}
target={['apiv2_transfer_export_update', {id: props.formData.id}]}
target={(formData, isNew) => isNew ? ['apiv2_transfer_export_create']: ['apiv2_transfer_export_update', {id: props.formData.id}]}
onSave={props.onSave}
close={props.path}
defaultPage="overview"
actionsPage={ExportEditorActions}
actionsPage={!props.isNew ? ExportEditorActions : undefined}
overviewPage={ExportEditorOverview}
pages={[
{
Expand All @@ -42,6 +43,8 @@ const ExportEditor = (props) => {
render: () => (
<ExportEditorPlaning
schedulerEnabled={props.schedulerEnabled}
updateProp={props.updateProp}
isNew={props.isNew}
/>
)
}
Expand All @@ -52,11 +55,13 @@ const ExportEditor = (props) => {

ExportEditor.propTypes = {
path: T.string.isRequired,
isNew: T.bool.isRequired,
formData: T.shape({
id: T.string,
name: T.string,
action: T.string
}),
onSave: T.func.isRequired,
explanation: T.object.isRequired,
updateProp: T.func.isRequired,
schedulerEnabled: T.bool.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ import {selectors as formSelectors} from '#/main/app/content/form'

const ExportEditorOverview = () => {
const formData = useSelector(state => formSelectors.data(formSelectors.form(state, selectors.FORM_NAME)))
const isNew = useSelector(state => formSelectors.isNew(formSelectors.form(state, selectors.FORM_NAME)))
const explanation = useSelector(state => selectors.exportExplanation(state))

const entity = formData.action.substring(0, formData.action.indexOf('_'))
const action = formData.action.substring(formData.action.indexOf('_') + 1)
let entity = typeof formData.action !== 'undefined' ? formData.action.substring(0, formData.action.indexOf('_')) : formData.type
let action = typeof formData.action !== 'undefined' ? formData.action.substring(formData.action.indexOf('_') + 1) : formData.action
if(typeof formData.type !== 'undefined' && formData.type !== entity) {
entity = formData.type
action = ''
}

const additionalFields = explanation ? get(explanation, entity+'.'+action+'.fields', []): []
const filters = additionalFields.map(field => merge({}, field, {
Expand All @@ -31,18 +36,26 @@ const ExportEditorOverview = () => {
fields: [
{
name: 'type',
type: 'string',
type: 'choice',
label: trans('type'),
hideLabel: true,
disabled: true,
calculated: (formData) => trans(formData.action.substring(0, formData.action.indexOf('_')))
},{
disabled: !isNew,
calculated: () => entity,
options: {
noEmpty: false,
condensed: true,
choices: Object.keys(explanation).sort().reduce((o, key) => Object.assign(o, {
[key]: trans(key, {}, 'transfer')
}), {})
}
}, {
name: 'action',
type: 'choice',
label: trans('action'),
disabled: true,
disabled: !isNew,
displayed: !!entity,
calculated: () => entity + '_' + action,
options: {
noEmpty: true,
noEmpty: false,
condensed: true,
choices: Object.keys(get(explanation, entity, [])).reduce((o, key) => Object.assign(o, {
[entity + '_' + key]: trans(key, {}, 'transfer')
Expand All @@ -51,7 +64,8 @@ const ExportEditorOverview = () => {
}, {
name: 'name',
type: 'string',
label: trans('name')
label: trans('name'),
disabled: false
}
].concat(filters)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {connect} from 'react-redux'

import isEmpty from 'lodash/isEmpty'
import {param} from '#/main/app/config'
import {withRouter} from '#/main/app/router'
import {selectors} from '#/main/transfer/tools/export/store'
import {actions, selectors} from '#/main/transfer/tools/export/store'
import {actions as formActions, selectors as formSelectors} from '#/main/app/content/form/store'
import {ExportEditor as ExportEditorComponent} from '#/main/transfer/tools/export/editor/components/main'

Expand All @@ -12,14 +13,20 @@ const ExportEditor = withRouter(
exportFile: selectors.exportFile(state),
explanation: selectors.exportExplanation(state),
schedulerEnabled: param('schedulerEnabled'),
formData: formSelectors.data(formSelectors.form(state, selectors.FORM_NAME))
formData: formSelectors.data(formSelectors.form(state, selectors.FORM_NAME)),
isNew: formSelectors.isNew(formSelectors.form(state, selectors.FORM_NAME))
}),
(dispatch) => ({
openForm(exportFile) {
dispatch(formActions.reset(selectors.FORM_NAME, exportFile, false))
},
updateProp(prop, value) {
dispatch(formActions.updateProp(selectors.FORM_NAME, prop, value))
},
onSave(response) {
if (isEmpty(response.scheduler)) {
return dispatch(actions.execute(response.id))
}
}
})
)(ExportEditorComponent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const reducer = combineReducers({
explanation: makeReducer({}, {
[makeInstanceAction(TOOL_LOAD, selectors.STORE_NAME)]: (state, action) => action.toolData.explanation
}),
form: makeFormReducer(selectors.FORM_NAME, {new: true}),
form: makeFormReducer(selectors.FORM_NAME, {new: true, data: {format: 'csv'}}),

details: makeReducer(null, {
[TOOL_OPEN]: () => null,
Expand Down

0 comments on commit 30de2ee

Please sign in to comment.