Skip to content

Commit d8cbb41

Browse files
authored
[DUOS-2806] Fix empty columns for new study datasets (#2429)
1 parent 2de4d15 commit d8cbb41

File tree

4 files changed

+109
-11
lines changed

4 files changed

+109
-11
lines changed

cypress/component/DacDatasetTable/dac_dataset_table.spec.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,25 @@ const sampleDataset = {
8080
'propertyValue': 'human',
8181
'propertyType': 'String'
8282
}
83-
]
83+
],
84+
'study': {
85+
'studyId': 1,
86+
'name': 'xyz 123',
87+
'description': 'test',
88+
'publicVisibility': true,
89+
'datasetIds': [
90+
1408
91+
],
92+
'properties': [
93+
{
94+
'studyPropertyId': 110,
95+
'studyId': 17,
96+
'key': 'dataCustodianEmail',
97+
'type': 'Json',
98+
"value": []
99+
}
100+
],
101+
},
84102
};
85103

86104
// It's necessary to wrap components that contain `Link` components
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { firstNonEmptyPropertyValue } from '../../../src/utils/DatasetUtils';
2+
3+
describe('firstNonEmptyPropertyValue', () => {
4+
it('ensure no errors when no study properties', async () => {
5+
const dataset = { id: 1, study: { id: 2 }};
6+
const result = firstNonEmptyPropertyValue(dataset, [ 'test' ]);
7+
expect(result).to.be.empty;
8+
});
9+
it('ensure no errors when no dataset properties', async () => {
10+
const dataset = { id: 1 };
11+
const result = firstNonEmptyPropertyValue(dataset, [ 'test' ]);
12+
expect(result).to.be.empty;
13+
});
14+
it('ensure no errors when incorrect properties', async () => {
15+
const dataset = { id: 1, study: { id: 2, properties: [ { key: 'hello', value: 'goodbye' } ]}};
16+
const result = firstNonEmptyPropertyValue(dataset, [ 'test' ]);
17+
expect(result).to.be.empty;
18+
});
19+
it('ensure no errors when empty study property values', async () => {
20+
const dataset = { id: 1, study: { id: 2, properties: [ { key: 'hello' } ]}};
21+
const result = firstNonEmptyPropertyValue(dataset, [ 'hello' ]);
22+
expect(result).to.be.empty;
23+
});
24+
it('ensure no errors when empty dataset property values', async () => {
25+
const dataset = { id: 1, properties: [ { propertyName: 'hello' } ]};
26+
const result = firstNonEmptyPropertyValue(dataset, [ 'hello' ]);
27+
expect(result).to.be.empty;
28+
});
29+
it('extract hello property from study', async () => {
30+
const dataset = { id: 1, study: { id: 2, properties: [ { key: 'hello', value: 'goodbye' } ]}};
31+
const result = firstNonEmptyPropertyValue(dataset, [ 'hello' ]);
32+
expect(result).to.equal('goodbye');
33+
});
34+
it('extract hello property from dataset', async () => {
35+
const dataset = { id: 1, properties: [ { propertyName: 'hello', propertyValue: 'goodbye' } ]};
36+
const result = firstNonEmptyPropertyValue(dataset, [ 'hello' ]);
37+
expect(result).to.equal('goodbye');
38+
});
39+
it('prioritize study property over dataset property', async () => {
40+
const dataset = { id: 1, properties: [ { propertyName: 'hello', propertyValue: 'goodbye' } ], study: { id: 2, properties: [ { key: 'hello', value: 'world' } ]}};
41+
const result = firstNonEmptyPropertyValue(dataset, [ 'hello' ]);
42+
expect(result).to.equal('world');
43+
});
44+
it('extract first available property from study', async () => {
45+
const dataset = { id: 1, study: { id: 2, properties: [ { key: 'hello', value: 'goodbye' }, { key: 'world', value: 'hello' } ]}};
46+
const result = firstNonEmptyPropertyValue(dataset, [ 'hello', 'world' ]);
47+
expect(result).to.equal('goodbye');
48+
});
49+
it('extract first available property from dataset', async () => {
50+
const dataset = { id: 1, properties: [ { propertyName: 'hello', propertyValue: 'goodbye' }, { propertyName: 'world', propertyValue: 'hello' } ]};
51+
const result = firstNonEmptyPropertyValue(dataset, [ 'hello', 'world' ]);
52+
expect(result).to.equal('goodbye');
53+
});
54+
it('extract mix of properties from study and dataset', async () => {
55+
const dataset = { id: 1, properties: [ { propertyName: 'hello', propertyValue: 'goodbye' } ], study: { id: 2, properties: [ { key: 'world', value: 'hello' } ]}};
56+
const result = firstNonEmptyPropertyValue(dataset, [ 'world', 'hello' ]);
57+
expect(result).to.equal('hello');
58+
});
59+
});

src/components/dac_dataset_table/DACDatasetTableCellData.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import style from '../../pages/DACDatasets.module.css';
33
import {styles} from './DACDatasetsTable';
44
import {DatasetService} from '../../utils/DatasetService';
55
import DACDatasetApprovalStatus from './DACDatasetApprovalStatus';
6-
import {isEmpty, join, map} from 'lodash/fp';
6+
import {isEmpty, map} from 'lodash/fp';
77
import ReactTooltip from 'react-tooltip';
8+
import { firstNonEmptyPropertyValue } from '../../utils/DatasetUtils';
89

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

@@ -19,14 +20,11 @@ export function duosIdCellData({dataset, label = 'duosIdCellData'}) {
1920
}
2021

2122
export function dataSubmitterCellData({dataset, label = 'dataSubmitterCellData'}) {
22-
// We need an update to the dac-dataset API to get the data submitter value.
23-
// The Data Submitter is always pre-populated with the user who originally created the dataset.
24-
// See https://broadworkbench.atlassian.net/browse/DUOS-2291 for details
25-
// Until that happens, we can rely on the data depositor field.
2623
const dataDepositor = DatasetService.findDatasetPropertyValue(dataset, 'Data Depositor');
24+
const displayValue = isEmpty(dataDepositor) ? dataset.createUser.displayName : dataDepositor;
2725
return {
28-
data: <div className={style['cell-data']}>{dataDepositor}</div>,
29-
value: dataDepositor,
26+
data: <div className={style['cell-data']}>{displayValue}</div>,
27+
value: displayValue,
3028
id: `data-submitter-cell-data-${dataset.dataSetId}`,
3129
cellStyle: {width: styles.cellWidths.dataSubmitter},
3230
label
@@ -46,9 +44,7 @@ export function datasetNameCellData({dataset, label = 'datasetNameCellData'}) {
4644
export function dataCustodianCellData({dataset, label = 'dataCustodianCellData'}) {
4745
// Newer datasets have a list of data custodian emails.
4846
// Older datasets may or may not have a data depositor
49-
const dataCustodians = DatasetService.findDatasetPropertyValueList(dataset, 'Data Custodian Email');
50-
const dataDepositor = DatasetService.findDatasetPropertyValue(dataset, 'Data Depositor');
51-
const displayValue = isEmpty(dataCustodians) ? dataDepositor : join(', ')(dataCustodians);
47+
const displayValue = firstNonEmptyPropertyValue(dataset, [ 'Data Custodian Email', 'Data Depositor', 'dataCustodianEmail' ]);
5248
return {
5349
data: <div className={style['cell-data']}>{displayValue}</div>,
5450
value: displayValue,

src/utils/DatasetUtils.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export const firstNonEmptyPropertyValue = (dataset: any, propertyNames: string[]): string => {
2+
for (const propertyName of propertyNames) {
3+
let propertyValue: string[] = [];
4+
if ('study' in dataset && 'properties' in dataset.study) {
5+
const property = dataset.study.properties.find((property: any) => property.key === propertyName);
6+
const value = property?.value;
7+
if (value !== undefined) {
8+
const valueAsIterable = typeof value === 'string' ? [value] : value;
9+
propertyValue.push(...valueAsIterable);
10+
}
11+
}
12+
if ('properties' in dataset && propertyValue.length === 0) {
13+
const property = dataset.properties.find((property: any) => property.propertyName === propertyName);
14+
const value = property?.propertyValue;
15+
if (value !== undefined) {
16+
const valueAsIterable = typeof value === 'string' ? [value] : value;
17+
propertyValue.push(...valueAsIterable);
18+
}
19+
}
20+
if (propertyValue.length > 0) {
21+
return propertyValue.join(', ');
22+
}
23+
}
24+
return '';
25+
}

0 commit comments

Comments
 (0)