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

FIX Layer with empty data #78

Merged
merged 9 commits into from
Jul 16, 2020
Merged

Conversation

manmorjim
Copy link
Contributor

@vercel
Copy link

vercel bot commented Jul 14, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/carto-frontend/web-sdk/cc9so7957
✅ Preview: https://web-sdk-git-bug-ch90394layer-layer-without-data.carto-frontend.vercel.app

const metadata = { geometryType, stats: fieldStats };
if (stats.geometryType) {
geometryType = parseGeometryType(stats.geometryType);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we at least add a console.warn about empty source? Or maybe even have a source.isEmpty property based on this value?

@@ -50,6 +50,11 @@ export function colorBinsStyle(
) {
const evalFN = (layer: StyledLayer) => {
const meta = layer.source.getMetadata();

if (!meta.geometryType) {
Copy link
Contributor

@VictorVelarde VictorVelarde Jul 14, 2020

Choose a reason for hiding this comment

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

I would better go after a layer.source.isEmpty prop, hiding this... what do you think?


const metadata = { geometryType, stats: fieldStats };
if (stats.geometryType) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it easier to do something like:

if (!stats.geometryType) {
  return { 'Point', stats: [] }
}

And even better, if you encapsulate the check !stats.geometryType in a method called hasData.

I would expect you don't need to check if geometryType exists and it is not going to fail for that reason in other places

Copy link
Contributor

Choose a reason for hiding this comment

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

Same thoughts here around 'hasData' or 'isEmpty' method

Copy link
Contributor

@VictorVelarde VictorVelarde left a comment

Choose a reason for hiding this comment

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

It looks good. I just added a couple of small suggestions on how the source is asked about 'isEmpty'

@vercel vercel bot temporarily deployed to Preview July 14, 2020 16:32 Inactive
@manmorjim
Copy link
Contributor Author

Not sure if I understood your suggestions:

I've added a method isEmpty in Source class which is overwritten in the class SQLSource. The isEmpty method of this class returns true if its metadata attribute does not have the geometryType field. Then, style helpers check if the source is empty or not using this method.

@@ -214,6 +215,10 @@ export class SQLSource extends Source {
}
}

public isEmpty() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, I think this is useful. Although I see the default method in the generic Source, I'm missing it in the GeoJSON one. I think we should try to keep the Sources as aligned as possible. What do you think? In that case I would return something like "features.length === 0"…

@@ -60,6 +60,11 @@ export abstract class Source extends WithEvents {
this.registerAvailableEvents(['filterChange']);
}

// eslint-disable-next-line class-methods-use-this
public isEmpty() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not an abstract method? I find strange to see an implementation in the interface...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to add a default implementation to avoid having to add the method in every source. But I reconsidered your suggestion and I agree that every source should implement its own method.

@VictorVelarde
Copy link
Contributor

@manmorjim Some small comments / suggestions. Feel free to merge after considering them

@manmorjim manmorjim merged commit 708406d into develop Jul 16, 2020
@manmorjim manmorjim deleted the bug/ch90394/layer-layer-without-data branch July 16, 2020 07:25
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.

3 participants