Skip to content
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

parse geojson from provider #32

Merged
merged 5 commits into from
Feb 14, 2023
Merged

parse geojson from provider #32

merged 5 commits into from
Feb 14, 2023

Conversation

sansth1010
Copy link
Collaborator

PR for 5620

{},
defaultDataset,
adlib(feedTemplate, { ...dataset?.properties, ...dataset?.geometry }, feedTemplateTransforms)
);
Copy link
Member

Choose a reason for hiding this comment

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

Too much going on here to easily understand. Can you move to a helper and make it more clear?

Copy link
Collaborator Author

@sansth1010 sansth1010 Feb 13, 2023

Choose a reason for hiding this comment

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

Agreed! Moved it into generateDcatItem() function and updated variable names to make it more clear.

@sansth1010 sansth1010 requested a review from rgwozdz February 13, 2023 20:16
Copy link
Member

@rgwozdz rgwozdz left a comment

Choose a reason for hiding this comment

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

Looking good, but need a few changes. Use the Jest coverage to ensure we have 100% test coverage.


// moving feature properties fields at the top level
// and geometry to second as the values for the properties
// can be easily referenced in template
Copy link
Member

Choose a reason for hiding this comment

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

Comments here are not necessary. They should only be used when the code cannot be written in away that explains itself. See https://bpoplauschi.github.io/2021/01/20/Clean-Code-Comments-by-Uncle-Bob-part-2.html.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is great point. I wanted to mention why we are restructuring geojson properties and geometry like I am doing right now as opposed to passing the whole object geojsonFeature. This would relate to how we are mapping the values in the template. But, I have removed the comment.

// and geometry to second as the values for the properties
// can be easily referenced in template
const dcatFeedData = {
...geojsonFeature?.properties,
Copy link
Member

Choose a reason for hiding this comment

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

I think you don't need the ? as geojson should always have properties. But if you are worried about it not being defined, I think this code will cause an exception. If properties is undefined, it will try to destructure undefined and you'll have an error.

I think this is probably not under test. I think you should implement test coverage, and add tests for whatever is not covered.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is true. My intention was to not allow it to fail even if some if some of geojson attributes are missing. I have removed the optional chaining operator for now and added test coverage for it.

// can be easily referenced in template
const dcatFeedData = {
...geojsonFeature?.properties,
...{ geometry: geojsonFeature?.geometry }
Copy link
Member

Choose a reason for hiding this comment

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

I think this destructuring is unnecessary. Can't you just do:

geometry: geojsonFeature.geometry

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, we can remove the unnecessary destructuring.

@@ -25,6 +22,32 @@ function removeUninterpolatedDistributions(distributions: any[]) {
return distributions.filter((distro) => !(typeof distro === 'string' && distro.match(/{{.+}}/)?.length));
}

function generateDcatItem(feedTemplate, feedTemplateTransforms, geojsonFeature) {
Copy link
Member

Choose a reason for hiding this comment

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

this is typescript, but you have not given the parameters types, and the function doesn't have a return type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, missed the types. I had added them. However. let me know if I need to narrow down my types to be even more concrete.

@sansth1010
Copy link
Collaborator Author

sansth1010 commented Feb 14, 2023

@rgwozdz : Test coverage currently:

image

There were few trivial unreachable conditions from previous code that needed to updated.

@sansth1010 sansth1010 requested a review from rgwozdz February 14, 2023 07:02
@sansth1010 sansth1010 merged commit 78c222b into beta Feb 14, 2023
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