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

Comparative Category Widget #505

Merged
merged 27 commits into from
Nov 9, 2022

Conversation

juandjara
Copy link
Contributor

@juandjara juandjara commented Oct 25, 2022

Description

This PR implements part of the work proposed in RFC #479

This widget uses the component AnimatedNumber introduced in PR #504. Because of that, it includes the changes introduced in PR #504. Because of that, this PR should be merged only after PR #504 is merged

Changes added in this PR include:

  • A new widget called ComparativeCategoryWidgetUI in the widgets folder
  • Typescript typings for ComparativeCategoryWidgetUI and the exported enum ORDER_TYPES
  • JSDoc typings comments for ComparativeCategoryWidgetUI and the exported enum ORDER_TYPES
  • Prop-types validation for ComparativeCategoryWidgetUI and all the subcomponents included
  • A basic storybook story for ComparativeComparativeWidgetUI where all prop combinations can be tested and tweaked. A screenshot of this storybook is added as visual feedback.

Captura de pantalla 2022-10-25 a las 12 58 40

Type of change

  • Feature

Acceptance

How to validate the feature:

  1. Open the local storybook running yarn storybook:start in the react-ui folder.
  2. Pick a set of properties to use for testing by tweaking the storybook configuration.
  3. Use this set of properties to render a ComparativeCategoryWidgetUI in your sample project, by importing ComparativeCategoryWidgetUI from @carto/react-ui. You can use this branch of carto-react-template to skip this step if you want, as a test screen is already setup there. Bear in mind that if this feature is not published to npm you will have to link your local version of @carto/react-* packages with yarn link.
  4. Check that the rendered version of the widget in your sample project looks the same as it looks in the storybook.

Basic checklist

  • Good PR name
  • Shortcut link
  • Changelog entry
  • Just one issue per PR
  • GitHub labels
  • Proper status & reviewers
  • Tests
  • Documentation

@juandjara juandjara changed the title Feature/comparative category widget Comparative Category Widget Oct 25, 2022
@coveralls
Copy link
Collaborator

coveralls commented Oct 25, 2022

Pull Request Test Coverage Report for Build 3429857450

  • 120 of 127 (94.49%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.7%) to 72.422%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/react-ui/src/widgets/comparative/ComparativeCategoryWidgetUI/ComparativeCategoryWidgetUI.js 79 82 96.34%
packages/react-ui/src/widgets/comparative/ComparativeCategoryWidgetUI/CategoryItem.js 22 26 84.62%
Totals Coverage Status
Change from base Build 3425917787: 0.7%
Covered Lines: 1844
Relevant Lines: 2371

💛 - Coveralls

* Enum for ComparativeCategoryWidgetUI order types. 'RANKING' orders the data by value and 'FIXED' keep the order present in the original data
* @enum {string}
*/
export const ORDER_TYPES = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we share same order types from CategoryWidget?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, we could move the export const ORDER_TYPES to CategoryWidgetUI and use that instead of writing them to CategoryWidgetUI, so we can import them separately from ComparativeCategoryWidgetUI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solved

}
}))(Tooltip);

function CategoryItem({
Copy link
Contributor

Choose a reason for hiding this comment

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

I would strongly suggest splitting this long file, with different components, into different files, one per component. Also I think it would probably make sense to create a bit more of structure in folders:

  • widgets
    • CategoryWidgetUI
    • comparative
      • Category
        • ComparativeCategoryWidgetUI
        • CategoryItem
        • Skeleton...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Allright, ComparativeCategoryWidget is now split into multiple files and in the folder widgets/comparative

@@ -66,7 +67,7 @@ function ComparativeFormulaWidgetUI({
}

return (
<div>
<div className={classes.formulaChart}>
Copy link
Contributor

Choose a reason for hiding this comment

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

I've removed this class in the previous PR, as it has no content

Copy link
Contributor Author

@juandjara juandjara Oct 28, 2022

Choose a reason for hiding this comment

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

oh sorry, I thought it was there for something. I will be removing it again

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done too

@@ -0,0 +1,47 @@
import React from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

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

Stories file is obviously very useful for debugging, thx for doing it.

But something we're missing here, and in general in comparative is the unit testing side. Same as we have /tests_/widgets/CategoryWidgetUI.test.js we should have corresponding unit tests for each comparative widget.

That's gonna allow us to maintain it better in the future (or maybe to refactor it to share some pieces...). Would you please?
Would you please

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Allright, I will be looking at existing test files and try to create similar ones for comparative widgets

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And this one will be a task for tomorrow

@juandjara
Copy link
Contributor Author

@VictorVelarde thanks a lot for your review!
I will be addressing these comments next monday

@VictorVelarde
Copy link
Contributor

Hi @juandjara, I see you're advancing well. Ping us when this is ready for a 2nd review, thx!

@juandjara
Copy link
Contributor Author

Hi @VictorVelarde! Tests for ComparativeCategoryWidgetUI and other changes are now ready. I've made sure to test almost the same behaviour as the CategoryWidgetUI is testing to ensure a consistent logic. Let me know if you have any more comments or any more feedback in order to finish this PR.

@VictorVelarde
Copy link
Contributor

Thx a lot @juandjara, I think you have done a really nice job here ✨ . I'm gonna land it and make 1.5.0-alpha so you can properly review it in your project

@VictorVelarde VictorVelarde self-requested a review November 9, 2022 19:19
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.

🚀

@VictorVelarde VictorVelarde merged commit b6b679f into master Nov 9, 2022
@VictorVelarde VictorVelarde deleted the feature/comparative-category-widget branch November 9, 2022 19:20
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