Skip to content

Commit

Permalink
[DUOS-1764][risk=no] Loop over all dataset ids instead of assuming th…
Browse files Browse the repository at this point in the history
…e first (#1677)

* loop over all dataset ids instead of assuming the first
  • Loading branch information
rushtong authored Jul 21, 2022
1 parent 21eddae commit ae44dfe
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 21 deletions.
3 changes: 2 additions & 1 deletion cypress/component/DarCollectionTable/chair_actions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ const missingElectionSet = {
elections: {},
data: {
datasetIds: [1]
}
},
datasetIds: [1]
},
2: {
elections: {
Expand Down
5 changes: 4 additions & 1 deletion cypress/component/utils/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,10 @@ describe('Dar Collection determineCollectionStatus', () => {
it('Returns empty string when there are no elections and the collection does not contains relevant datasets', () => {
const collection = {
dars: {
0: {data: {datasetIds: [100]}}
0: {
data: {datasetIds: [100]},
datasetIds: [100]
}
}
};
const status = determineCollectionStatus(collection);
Expand Down
20 changes: 13 additions & 7 deletions src/components/dar_collection_table/ChairActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { div, h } from 'react-hyperscript-helpers';
import TableIconButton from '../TableIconButton';
import { Styles } from '../../libs/theme';
import { Block } from '@material-ui/icons';
import { isEmpty, filter, map, flow, includes, toLower, forEach, flatten, flatMap, uniq, isNil } from 'lodash/fp';
import { isEmpty, filter, find, map, flow, includes, intersection, toLower, forEach, flatten, flatMap, uniq, isNil } from 'lodash/fp';
import { Storage } from '../../libs/storage';
import SimpleButton from '../SimpleButton';

Expand All @@ -26,17 +26,23 @@ const initUserData = ({dars, elections, relevantDatasets}) => {
uniq
)(relevantDatasets);
const relevantDarsNoElections = filter(dar => {
const datasetId = !isEmpty(dar.data) ? dar.data.datasetIds[0] : undefined;
return includes(datasetId, relevantDatasetIds) ? isEmpty(dar.elections) : false;
// Dataset IDs should be on the DAR, but if not, pull from the dar.data
const datasetIds = isNil(dar.datasetIds) ? dar.data.datasetIds : dar.datasetIds;
const relevant = flow(
map(id => { return includes(id, relevantDatasetIds) ? isEmpty(dar.elections) : false; }),
find((r) => { return true === r; } )
)(datasetIds);
return !isNil(relevant);
})(dars);
const relevantElections = filter((election) => {
//NOTE: not all elections have the dataSetId attribute tied to it (not sure why)
//For this ticket I'm going to use dar.data.datasetIds[0] as a fallback value
// NOTE: not all elections have the dataSetId attribute tied to it (https://broadworkbench.atlassian.net/browse/DUOS-1689)
// For this ticket I'm going to use dar.datasetIds/dar.data.datasetIds as a fallback value
if(!isNil(election.dataSetId)) {
return includes(election.dataSetId, relevantDatasetIds);
} else {
const datasetId = !isEmpty(dars[election.referenceId].data) ? dars[election.referenceId].data.datasetIds[0] : -1;
return includes(datasetId, relevantDatasetIds);
// Dataset IDs should be on the DAR, but if not, pull from the dar.data
const datasetIds = isNil(dars[election.referenceId].datasetIds) ? dars[election.referenceId].data.datasetIds : dars[election.referenceId].datasetIds;
return intersection(datasetIds, relevantDatasetIds).length > 0;
}
})(elections);
return {relevantDarsNoElections, relevantElections, relevantDatasetIds};
Expand Down
5 changes: 3 additions & 2 deletions src/components/dar_table/DarElectionRecords.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isEmpty } from 'lodash/fp';
import {isEmpty, isNil} from 'lodash/fp';
import { div, h, a } from 'react-hyperscript-helpers';
import {
applyTextHover,
Expand Down Expand Up @@ -70,7 +70,8 @@ export default function DarElectionRecords(props) {
inline: true,
hideUnderLimit: true,
readLessText: ' Read Less',
content: dar && dar.data ? getNameOfDatasetForThisDAR(dar.data.datasets, dar.data.datasetIds) : '- -'
// Dataset IDs should be on the DAR, but if not, pull from the dar.data
content: dar && dar.data ? getNameOfDatasetForThisDAR(dar.data.datasets, isNil(dar.datasetIds) ? dar.data.datasetIds : dar.datasetIds) : '- -'
})]),
div({style: Object.assign({}, Styles.TABLE.SUBMISSION_DATE_CELL, recordTextStyle)}, [getElectionDate(election)]),
div({style: Object.assign({}, Styles.TABLE.DAC_CELL, recordTextStyle)}, [dac ? dac.name : '- -']),
Expand Down
4 changes: 3 additions & 1 deletion src/components/dar_table/DarTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export const getTableHeaderTemplateWithSort = (sortFunc, descOrder, consoleType)
]),
div({style: Styles.TABLE.DATASET_CELL, key: 'dataset_name_cell', className: 'cell-sort', onClick: sortFunc({
getValue: (a) => {
return a.dar && a.dar.data ? Utils.getNameOfDatasetForThisDAR(a.dar.data.datasets, a.dar.data.datasetIds) : '- -';
// Dataset IDs should be on the DAR, but if not, pull from the dar.data
const datasetIds = isNil(a.dar.datasetIds) ? a.dar.data.datasetIds : a.dar.datasetIds;
return a.dar && a.dar.data ? Utils.getNameOfDatasetForThisDAR(a.dar.data.datasets, datasetIds) : '- -';
},
descendantOrder: descOrder
})}, [
Expand Down
15 changes: 9 additions & 6 deletions src/libs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ export const darCollectionUtils = {
//see if its relevant, if it is, add 1 to submitted on hash
//return empty array at the end
if(isEmpty(elections)) {
const datasetId = (isEmpty(dar.data) || isEmpty(dar.data.datasetIds)) ? -1 : dar.data.datasetIds[0];
if(includes(relevantDatasets, datasetId)) {
if(isNil(electionStatusCount['Submitted'])) {
electionStatusCount['Submitted'] = 0;
// Dataset IDs should be on the DAR, but if not, pull from the dar.data
const datasetIds = isNil(dar.datasetIds) ? dar.data.datasetIds : dar.datasetIds;
forEach((datasetId) => {
if (includes(relevantDatasets, datasetId)) {
if (isNil(electionStatusCount['Submitted'])) {
electionStatusCount['Submitted'] = 0;
}
electionStatusCount['Submitted']++;
}
electionStatusCount['Submitted']++;
}
})(datasetIds);
return [];
} else {
//if elections exist, filter out elections based on relevant ids
Expand Down
7 changes: 4 additions & 3 deletions src/utils/DarCollectionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ export const generatePreProcessedBucketData = async ({dars, datasets}) => {
});

forEach((dar) => {
const darDatasetId = dar.datasetIds[0];
const targetBucket = datasetBucketMap[darDatasetId];
targetBucket.dars.push(dar);
forEach((datasetId) => {
const targetBucket = datasetBucketMap[datasetId];
targetBucket.dars.push(dar);
})(dar.datasetIds);
})(dars);
return buckets;
};
Expand Down

0 comments on commit ae44dfe

Please sign in to comment.