From 83a5b601a6e522f1f1897dc82e8e3b07f42d36d7 Mon Sep 17 00:00:00 2001 From: Stefano Ricci <1219739+SteRiccio@users.noreply.github.com> Date: Fri, 17 Nov 2023 12:27:30 +0100 Subject: [PATCH] Fixed include key code attribute labels in records export (#3147) * 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 Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- core/i18n/resources/en.js | 1 + .../record/repository/recordRepository.js | 8 ++++---- server/modules/record/service/recordService.js | 18 ++++++++++++------ webapp/components/Table/Header/Header.js | 12 ++++++++++-- .../Data/Records/HeaderLeft/HeaderLeft.js | 4 ++-- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/core/i18n/resources/en.js b/core/i18n/resources/en.js index d47f26959e..f4eb8d0eae 100644 --- a/core/i18n/resources/en.js +++ b/core/i18n/resources/en.js @@ -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', diff --git a/server/modules/record/repository/recordRepository.js b/server/modules/record/repository/recordRepository.js index 9a67eb3dd2..e0695a9d3a 100644 --- a/server/modules/record/repository/recordRepository.js +++ b/server/modules/record/repository/recordRepository.js @@ -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 diff --git a/server/modules/record/service/recordService.js b/server/modules/record/service/recordService.js index bef63c216f..7e8ea00d57 100644 --- a/server/modules/record/service/recordService.js +++ b/server/modules/record/service/recordService.js @@ -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' @@ -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)), @@ -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', diff --git a/webapp/components/Table/Header/Header.js b/webapp/components/Table/Header/Header.js index e3595fdfc4..5b167820b8 100644 --- a/webapp/components/Table/Header/Header.js +++ b/webapp/components/Table/Header/Header.js @@ -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 (
{React.createElement(headerLeftComponent, { ...props, ...headerProps })} - {visibleColumnsSelectionEnabled && ( + {visibleColumnsSelectionEnabled && totalCount > 0 && ( )}
@@ -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, } diff --git a/webapp/views/App/views/Data/Records/HeaderLeft/HeaderLeft.js b/webapp/views/App/views/Data/Records/HeaderLeft/HeaderLeft.js index 57338bff4f..1f7f13d045 100644 --- a/webapp/views/App/views/Data/Records/HeaderLeft/HeaderLeft.js +++ b/webapp/views/App/views/Data/Records/HeaderLeft/HeaderLeft.js @@ -89,12 +89,12 @@ const HeaderLeft = ({ handleSearch, navigateToRecord, onRecordsUpdate, search, s onChange={(e) => handleSearch(e.target.value)} /> )} - {canExportRecordsSummary && ( + {canExportRecordsSummary && totalCount > 0 && ( )} {published && canUpdateRecordsStep && selectedItemsCount > 0 && (