Skip to content

Commit

Permalink
Fixed include key code attribute labels in records export (#3147)
Browse files Browse the repository at this point in the history
* Fixed include key code attribute labels in records export

* changed export label

* records table: hide buttons when there is no data

---------

Co-authored-by: Stefano Ricci <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 17, 2023
1 parent 441f95c commit 83a5b60
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 14 deletions.
1 change: 1 addition & 0 deletions core/i18n/resources/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ Are you sure you want to continue?`,
demoteAllRecordsFromAnalysis: 'Analysis -> Cleansing',
demoteAllRecordsFromCleansing: 'Cleansing -> Entry',
editRecord: 'Edit record',
exportList: 'Export list',
filterPlaceholder: 'Filter by keys or owner',
viewRecord: 'View record',
owner: 'Owner',
Expand Down
8 changes: 4 additions & 4 deletions server/modules/record/repository/recordRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ export const fetchRecordsSummaryBySurveyId = async (
{}
)
const nodeDefKeysSelect = nodeDefKeys
?.map(
(nodeDefKey) =>
`${rootEntityTableAlias}.${getNodeDefKeyColumnName(nodeDefKey)} as "${getNodeDefKeyColAlias(nodeDefKey)}"`
)
?.flatMap((nodeDefKey) => {
const colNames = NodeDefTable.getColumnNames(nodeDefKey)
return colNames.map((keyColName) => `${rootEntityTableAlias}.${keyColName} AS ${keyColName}`)
})
.join(', ')

const nodeDefKeysSelectSearch = nodeDefKeys
Expand Down
18 changes: 12 additions & 6 deletions server/modules/record/service/recordService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import * as fs from 'fs'

import * as Log from '@server/log/log'

import * as NodeDefTable from '@common/surveyRdb/nodeDefTable'

import * as A from '@core/arena'
import SystemError from '@core/systemError'
import * as PromiseUtils from '@core/promiseUtils'
Expand Down Expand Up @@ -86,11 +88,15 @@ export const exportRecordsSummaryToCsv = async ({ res, surveyId, cycle }) => {
const validation = Validation.getValidation(recordSummary)
return {
step: Record.getStep(recordSummary),
...nodeDefKeys.reduce((keysAcc, nodeDef) => {
const name = NodeDef.getName(nodeDef)
const value = recordSummary[A.camelize(name)]
const formatter = valueFormattersByType[NodeDef.getType(nodeDef)]
return { ...keysAcc, [name]: value && formatter ? formatter({ value }) : value }
...nodeDefKeys.reduce((keysAcc, nodeDefKey) => {
const nodeDefKeyColumnNames = NodeDefTable.getColumnNames(nodeDefKey)
nodeDefKeyColumnNames.forEach((nodeDefKeyColumnName) => {
const value = recordSummary[A.camelize(nodeDefKeyColumnName)]
const formatter = valueFormattersByType[NodeDef.getType(nodeDefKey)]
const valueFormatted = formatter ? formatter({ value }) : value
keysAcc[nodeDefKeyColumnName] = valueFormatted
})
return keysAcc
}, {}),
data_created: DateUtils.formatDateTimeExport(Record.getDateCreated(recordSummary)),
date_modified: DateUtils.formatDateTimeExport(Record.getDateModified(recordSummary)),
Expand All @@ -105,7 +111,7 @@ export const exportRecordsSummaryToCsv = async ({ res, surveyId, cycle }) => {
Response.setContentTypeFile({ res, fileName, contentType: Response.contentTypes.csv })

const fields = [
...nodeDefKeys.map(NodeDef.getName),
...nodeDefKeys.flatMap((nodeDefKey) => NodeDefTable.getColumnNames(nodeDefKey)),
'step',
'owner_name',
'data_created',
Expand Down
12 changes: 10 additions & 2 deletions webapp/components/Table/Header/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ import PropTypes from 'prop-types'
import { VisibleColumnsMenu } from './VisibleColumnsMenu'

const Header = (props) => {
const { columns, headerLeftComponent, headerProps, onVisibleColumnsChange, visibleColumnsSelectionEnabled } = props
const {
columns,
headerLeftComponent,
headerProps,
onVisibleColumnsChange,
totalCount,
visibleColumnsSelectionEnabled,
} = props

return (
<div className="table__header">
{React.createElement(headerLeftComponent, { ...props, ...headerProps })}
{visibleColumnsSelectionEnabled && (
{visibleColumnsSelectionEnabled && totalCount > 0 && (
<VisibleColumnsMenu columns={columns} onSelectionChange={onVisibleColumnsChange} />
)}
</div>
Expand All @@ -25,6 +32,7 @@ Header.propTypes = {
list: PropTypes.array.isRequired,
offset: PropTypes.number.isRequired,
onVisibleColumnsChange: PropTypes.func.isRequired,
totalCount: PropTypes.number.isRequired,
visibleColumnsSelectionEnabled: PropTypes.bool,
}

Expand Down
4 changes: 2 additions & 2 deletions webapp/views/App/views/Data/Records/HeaderLeft/HeaderLeft.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ const HeaderLeft = ({ handleSearch, navigateToRecord, onRecordsUpdate, search, s
onChange={(e) => handleSearch(e.target.value)}
/>
)}
{canExportRecordsSummary && (
{canExportRecordsSummary && totalCount > 0 && (
<ButtonDownload
testId={TestId.records.exportBtn}
href={`/api/survey/${surveyId}/records/summary/export`}
requestParams={{ cycle }}
label="common.export"
label="dataView.records.exportList"
/>
)}
{published && canUpdateRecordsStep && selectedItemsCount > 0 && (
Expand Down

0 comments on commit 83a5b60

Please sign in to comment.