Skip to content

allow customers to append custom distributions to the dcat:distribution array #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 21, 2022

Conversation

sonofflynn89
Copy link
Collaborator

@sonofflynn89 sonofflynn89 commented Apr 21, 2022

Part of https://devtopia.esri.com/dc/hub/issues/1188.
To allow customers to add custom distributions to their feed via their dcat config, I made a few changes:

  • Remove dcat:distribution from the list of non-editable fields
  • Run customizations of dcat:distribution through adlib
  • Prepend the result from adlib onto the final dcat:distribution array IFF the adlib result is an array

We are not adding any validation as part of this PR. If the dcat config's dcat:distribution is an array, we just throw it in there.

@sonofflynn89 sonofflynn89 force-pushed the f/1188-append-distributions-in-config branch from 70199f3 to d1481de Compare April 21, 2022 18:09
@@ -203,91 +195,154 @@ describe('formatDcatDataset', () => {
'dct:title': 'OGC WMS',
},
};
const result = JSON.parse(formatDcatDataset(distDataset, defaultFormatTemplate));
Copy link
Collaborator Author

@sonofflynn89 sonofflynn89 Apr 21, 2022

Choose a reason for hiding this comment

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

This looks like a big diff, but if you open in VSC mode (hit .), you'll see that I moved all of this into a nested distributions describe and made the following changes:

  • Create a distributions const that all tests can reference, reducing redundancy
  • Create a getDistributions testing helper that returns the underlying parsed dcat:distribution array for each test (greatly simplifies the expect statements for each test)
  • Verify order of all distributions explicitly (since we were implicitly checking before)
  • Add tests around appending custom distributions

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, well thought out

@@ -46,9 +46,10 @@ export function formatDcatDataset(dcatDataset: any, template: DatasetFormatTempl

const formattedDataset = adlib(template, dcatDataset, transforms);

setLeftoverInterpolations(formattedDataset);
// reset uninterpolated, non-editable fields since customers cannot remove them
resetUninterpolatedPaths(formattedDataset, nonEditableFieldPaths);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When I revisited setLeftoverInterpolations for the first time, I could not for the life of me remember why we had this function. I eventually figured it out, but if I (who approved the original PR) had a hard time remembering the purpose of the function, I guarantee you that others will as well.

Changing the name to something like resetUninterpolatedPathsOfUneditableFields seemed way too verbose, so I opted to create a generic function name, explicitly pass in nonEditableFieldPaths and add in a clarifying comment. I'm hoping this semantic change will be a little more friendly for future devs (including ourselves).

Copy link
Contributor

Choose a reason for hiding this comment

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

Fine by me

@@ -46,9 +46,10 @@ export function formatDcatDataset(dcatDataset: any, template: DatasetFormatTempl

const formattedDataset = adlib(template, dcatDataset, transforms);

setLeftoverInterpolations(formattedDataset);
// reset uninterpolated, non-editable fields since customers cannot remove them
resetUninterpolatedPaths(formattedDataset, nonEditableFieldPaths);
Copy link
Contributor

Choose a reason for hiding this comment

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

Fine by me

@@ -203,91 +195,154 @@ describe('formatDcatDataset', () => {
'dct:title': 'OGC WMS',
},
};
const result = JSON.parse(formatDcatDataset(distDataset, defaultFormatTemplate));
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, well thought out

@sonofflynn89 sonofflynn89 merged commit 751b5ba into main Apr 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants