Skip to content

Commit

Permalink
Fix job errors export to CSV (#3593)
Browse files Browse the repository at this point in the history
* Fix job errors export to CSV

* improved missing parent entity error message

---------

Co-authored-by: Stefano Ricci <[email protected]>
  • Loading branch information
SteRiccio and SteRiccio authored Oct 10, 2024
1 parent 2a2be9e commit 7e0a41f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 30 deletions.
2 changes: 1 addition & 1 deletion core/i18n/resources/en/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -1718,7 +1718,7 @@ Levels will be renamed into level_1, level_2... level_N and an extra 'area' prop
keyDuplicate: 'Duplicate record key',
entityKeyDuplicate: 'Duplicate key',
entityKeyValueNotSpecified: 'Key value for "{{keyDefName}}" not specified',
missingAncestorForEntity: 'Cannot find ancestor "{{ancestorName}}" for entity "{{entityName}}"',
missingAncestorForEntity: 'Cannot find "{{ancestorName}}" with these keys: {{keyValues}}',
oneOrMoreInvalidValues: 'One or more values are invalid',
uniqueAttributeDuplicate: 'Duplicate value',
valueInvalid: 'Invalid value',
Expand Down
26 changes: 16 additions & 10 deletions core/record/_record/recordNodesUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ const { updateNodesDependents } = CoreRecordNodesUpdater

import { afterNodesUpdate } from './recordNodesUpdaterCommon'

const getKeyValuePairs = ({ survey, entityDef, valuesByDefUuid }) => {
const keyDefs = Survey.getNodeDefKeys(entityDef)(survey)
return keyDefs
.map((keyDef) => {
const keyDefUuid = NodeDef.getUuid(keyDef)
const keyDefName = NodeDef.getName(keyDef)
const value = valuesByDefUuid[keyDefUuid]
const keyValue = NodeValueFormatter.format({ survey, nodeDef: keyDef, value })
return `${keyDefName}=${keyValue}`
})
.join(',')
}

const _valueAdapterByType = {
[NodeDef.nodeDefType.code]: ({ survey, record, parentNode, attributeDef, value }) => {
if (value[Node.valuePropsCode.itemUuid]) {
Expand Down Expand Up @@ -126,16 +139,7 @@ const _getOrCreateEntityByKeys =
const entityDef = Survey.getNodeDefByUuid(entityDefUuid)(survey)

if (!insertMissingNodes) {
const keyDefs = Survey.getNodeDefKeys(entityDef)(survey)
const keyValuePairs = keyDefs
.map((keyDef) => {
const keyDefUuid = NodeDef.getUuid(keyDef)
const keyDefName = NodeDef.getName(keyDef)
const value = valuesByDefUuid[keyDefUuid]
const keyValue = NodeValueFormatter.format({ survey, nodeDef: keyDef, value })
return `${keyDefName}=${keyValue}`
})
.join(',')
const keyValuePairs = getKeyValuePairs({ survey, entityDef, valuesByDefUuid })
throw new SystemError('appErrors:record.entityNotFound', {
entityName: NodeDef.getName(entityDef),
keyValues: keyValuePairs,
Expand All @@ -153,9 +157,11 @@ const _getOrCreateEntityByKeys =
})(record)

if (!entityParent) {
const keyValuePairs = getKeyValuePairs({ survey, entityDef: entityParentDef, valuesByDefUuid })
throw new SystemError('validationErrors.record.missingAncestorForEntity', {
entityName: NodeDef.getName(entityDef),
ancestorName: NodeDef.getName(entityParentDef),
keyValues: keyValuePairs,
})
}
const { entity: entityInserted, updateResult } = _addEntityAndKeyValues({
Expand Down
6 changes: 1 addition & 5 deletions webapp/components/DataGrid/DataGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ const DataGrid = (props) => {
rows,
} = props

const components = {
...(allowExportToCsv ? { Footer: FooterWithExport({ exportFileName }) } : {}),
}

const columns = useMemo(() => columnsProp.map((col) => ({ ...col, disableColumnMenu: true })), [columnsProp])

const getRowHeight = useMemo(() => (autoRowHeight ? () => 'auto' : undefined), [autoRowHeight])
Expand All @@ -43,14 +39,14 @@ const DataGrid = (props) => {
checkboxSelection={checkboxSelection}
className={classNames('data-grid', className)}
columns={columns}
components={components}
density={density}
disableRowSelectionOnClick={disableSelectionOnClick}
getRowClassName={getRowClassName}
getRowHeight={getRowHeight}
getRowId={getRowId}
initialState={initialState}
rows={rows}
slots={allowExportToCsv ? { footer: FooterWithExport({ exportFileName }) } : undefined}
/>
)
}
Expand Down
22 changes: 8 additions & 14 deletions webapp/views/App/JobMonitor/JobErrors/JobErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import PropTypes from 'prop-types'
import * as JobSerialized from '@common/job/jobSerialized'
import { ValidationUtils } from '@core/validation/validationUtils'

import { useSurvey } from '@webapp/store/survey'
import { useI18n } from '@webapp/store/system'

import { ExpansionPanel } from '@webapp/components'
import ValidationFieldMessages from '@webapp/components/validationFieldMessages'
import { DataGrid } from '@webapp/components/DataGrid'
import { useSurvey } from '@webapp/store/survey'
import { ExpansionPanel } from '@webapp/components'
import { LabelWithTooltip } from '@webapp/components/form/LabelWithTooltip'

const validationWrapper = (fields) => ({
const toValidation = (fields) => ({
valid: false,
fields,
})
Expand Down Expand Up @@ -49,23 +49,17 @@ const JobErrors = ({
field: 'error',
flex: 0.6,
headerName: i18n.t('common.error', { count: errorsCount }),
renderCell: ({ value }) => (
<ValidationFieldMessages validation={validationWrapper(value)} showKeys={false} />
),
valueFormatter: ({ value }) => {
const jointMessages = ValidationUtils.getJointMessages({ i18n, survey, showKeys: false })(
validationWrapper(value)
)
renderCell: ({ value }) => <ValidationFieldMessages validation={toValidation(value)} showKeys={false} />,
valueFormatter: (value) => {
const validation = toValidation(value)
const jointMessages = ValidationUtils.getJointMessages({ i18n, survey, showKeys: false })(validation)
return jointMessages.map(({ text }) => text).join(', ')
},
},
]}
density="compact"
exportFileName={exportFileName}
rows={Object.entries(errors).map(([errorKey, error]) => ({
errorKey,
error,
}))}
rows={Object.entries(errors).map(([errorKey, error]) => ({ errorKey, error }))}
getRowId={(row) => row.errorKey}
/>
</ExpansionPanel>
Expand Down

0 comments on commit 7e0a41f

Please sign in to comment.