Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Add Closure to CSV Download #1249

Merged
merged 1 commit into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Confirm or reject status reports [#1235](https://github.com/open-apparel-registry/open-apparel-registry/pull/1235)
- Report Facility Status from Facility Details [#1239](https://github.com/open-apparel-registry/open-apparel-registry/pull/1239)
- Add Report Waffle Switch [#1246](https://github.com/open-apparel-registry/open-apparel-registry/pull/1246)
- Add Closure to CSV Download [#1249](https://github.com/open-apparel-registry/open-apparel-registry/pull/1249)

### Changed

Expand Down
83 changes: 83 additions & 0 deletions src/app/src/__tests__/utils.facilitiesCSV.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,86 @@ it('creates a 2-d array including PPE headers and values', () => {
formatDataForCSV(facilities, { includePPEFields: true }),
).toEqual(expected2DArray);
});

it('creates a 2-d array including closure headers and values', () => {
const facilities = [
{
properties: {
name: 'name',
address: 'address',
country_code: 'country_code',
country_name: 'country_name',
oar_id: 'oar_id',
contributors: [
{
id: 1,
name: 'contributor_name',
verified: false,
},
],
is_closed: true,
},
geometry: {
coordinates: [
'lng',
'lat',
],
},
},
{
properties: {
name: 'name',
address: 'address',
country_code: 'country_code',
country_name: 'country_name',
oar_id: 'oar_id',
contributors: [
{
id: 1,
name: 'contributor_name',
verified: false,
},
],
is_closed: false,
},
geometry: {
coordinates: [
'lng',
'lat',
],
},
},
];

const expected2DArray = [
csvHeaders.concat([
'is_closed',
]),
[
'oar_id',
'name',
'address',
'country_code',
'country_name',
'lat',
'lng',
'contributor_name',
'CLOSED',
],
[
'oar_id',
'name',
'address',
'country_code',
'country_name',
'lat',
'lng',
'contributor_name',
null,
],
];

expect(
formatDataForCSV(facilities, { includeClosureFields: true }),
).toEqual(expected2DArray);
});
16 changes: 13 additions & 3 deletions src/app/src/actions/logDownload.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function logDownload() {

const vectorTileFlagIsActive = get(featureFlags, 'flags.vector_tile', false);
const ppeIsActive = get(featureFlags, 'flags.ppe', false);
const reportsAreActive = get(featureFlags, 'flags.report_a_facility', false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Nice integration with our new switch


const path = `${window.location.pathname}${window.location.search}${window.location.hash}`;

Expand All @@ -48,7 +49,10 @@ export function logDownload() {
.post(makeLogDownloadUrl(path, recordCount))
.then(() => downloadFacilitiesCSV(
facilities,
{ includePPEFields: ppeIsActive },
{
includePPEFields: ppeIsActive,
includeClosureFields: reportsAreActive,
},
))
.then(() => dispatch(completeLogDownload()))
.catch(err => dispatch(logErrorAndDispatchFailure(
Expand All @@ -61,7 +65,10 @@ export function logDownload() {
await apiRequest.post(makeLogDownloadUrl(path, count));

if (!nextPageURL) {
downloadFacilitiesCSV(facilities, { includePPEFields: ppeIsActive });
downloadFacilitiesCSV(facilities, {
includePPEFields: ppeIsActive,
includeClosureFields: reportsAreActive,
});
} else {
let nextFacilitiesSetURL = nextPageURL;

Expand Down Expand Up @@ -103,7 +110,10 @@ export function logDownload() {
},
} = getState();

downloadFacilitiesCSV(features, { includePPEFields: ppeIsActive });
downloadFacilitiesCSV(features, {
includePPEFields: ppeIsActive,
includeClosureFields: reportsAreActive,
});
}

return dispatch(completeLogDownload());
Expand Down
21 changes: 14 additions & 7 deletions src/app/src/util/util.facilitiesCSV.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const createFacilityRowFromFeature = (feature, options) => {
country_name,
oar_id,
contributors,
is_closed,
},
geometry: {
coordinates: [
Expand All @@ -41,6 +42,8 @@ export const createFacilityRowFromFeature = (feature, options) => {
: feature.properties[f],
)
: [];
const closureFields = options && options.includeClosureFields
? [is_closed ? 'CLOSED' : null] : [];

return Object.freeze([
oar_id,
Expand All @@ -51,18 +54,22 @@ export const createFacilityRowFromFeature = (feature, options) => {
lat,
lng,
contributors ? contributors.map(c => c.name).join('|') : '',
].concat(ppeFields));
].concat(ppeFields).concat(closureFields));
};

export const makeFacilityReducer = options => (acc, next) =>
acc.concat([createFacilityRowFromFeature(next, options)]);

export const makeHeaderRow = options =>
[
options && options.includePPEFields
? csvHeaders.concat(PPE_FIELD_NAMES)
: csvHeaders,
];
export const makeHeaderRow = (options) => {
let headerRow = csvHeaders;
if (options && options.includePPEFields) {
headerRow = headerRow.concat(PPE_FIELD_NAMES);
}
if (options && options.includeClosureFields) {
headerRow = headerRow.concat(['is_closed']);
}
return [headerRow];
};

export const formatDataForCSV = (facilities, options = {}) =>
facilities.reduce(
Expand Down