Skip to content

Commit

Permalink
feat: extract first non empty property value
Browse files Browse the repository at this point in the history
  • Loading branch information
fboulnois committed Jan 8, 2024
1 parent 99fa68a commit e45e9ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/components/dac_dataset_table/DACDatasetTableCellData.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {DatasetService} from '../../utils/DatasetService';
import DACDatasetApprovalStatus from './DACDatasetApprovalStatus';
import {isEmpty, map} from 'lodash/fp';
import ReactTooltip from 'react-tooltip';
import { firstNonEmptyPropertyValue } from '../../utils/DatasetUtils';

export const consoleTypes = { CHAIR: 'chair' };

Expand Down Expand Up @@ -43,10 +44,7 @@ export function datasetNameCellData({dataset, label = 'datasetNameCellData'}) {
export function dataCustodianCellData({dataset, label = 'dataCustodianCellData'}) {
// Newer datasets have a list of data custodian emails.
// Older datasets may or may not have a data depositor
const datasetCustodians = DatasetService.findDatasetPropertyValueList(dataset, 'Data Custodian Email')?.join(', ');
const dataDepositor = DatasetService.findDatasetPropertyValue(dataset, 'Data Depositor');
const studyCustodians = DatasetService.findDatasetPropertyValueList(dataset.study, 'dataCustodianEmail')?.join(', ');
const displayValue = isEmpty(datasetCustodians) ? (isEmpty(dataDepositor) ? studyCustodians : dataDepositor) : datasetCustodians;
const displayValue = firstNonEmptyPropertyValue(dataset, [ 'Data Custodian Email', 'Data Depositor', 'dataCustodianEmail' ]);
return {
data: <div className={style['cell-data']}>{displayValue}</div>,
value: displayValue,
Expand Down
21 changes: 21 additions & 0 deletions src/utils/DatasetUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export const firstNonEmptyPropertyValue = (dataset: any, propertyNames: string[]): string => {
for (const propertyName of propertyNames) {
let propertyValue: string[] = [];
if ('study' in dataset && 'properties' in dataset.study) {
const property = dataset.study.properties.find((property: any) => property.key === propertyName);
if (property !== undefined) {
propertyValue = propertyValue.concat(property.value);
}
}
if ('properties' in dataset && propertyValue.length === 0) {
const property = dataset.properties.find((property: any) => property.propertyName === propertyName);
if (property !== undefined) {
propertyValue = propertyValue.concat(property.propertyValue);
}
}
if (propertyValue.length > 0) {
return propertyValue.join(', ');
}
}
return '';
}

0 comments on commit e45e9ea

Please sign in to comment.