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

Pie widget: UI improvements && bugfixing #778

Merged
merged 11 commits into from
Oct 5, 2023
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Not released

- PieWidgetUI: Refactor & New CentralText component [#779](https://github.com/CartoDB/carto-react/pull/779)
- Pie widget: New ChartLegend component from scratch [#777](https://github.com/CartoDB/carto-react/pull/777)
- Pie Widget: Add maxNumber of elements + a sorted by size desc by default [#774](https://github.com/CartoDB/carto-react/pull/774)
- Pie Widget: Add number of selected categories + clear button [#771](https://github.com/CartoDB/carto-react/pull/771)
Comment on lines +5 to +8
Copy link
Contributor

Choose a reason for hiding this comment

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

@aaranadev, @menusal we want to land this improved PieWidget very soon. We'll ping you once we have the release, so you can test in PS projs


## 2.2

### 2.2.10 (2023-10-05)
Expand Down
6 changes: 6 additions & 0 deletions packages/react-ui/src/theme/sections/components/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ export const navigationOverrides = {
MuiLink: {
defaultProps: {
underline: 'hover'
},

styleOverrides: {
root: () => ({
cursor: 'pointer'
})
}
}
};
18 changes: 5 additions & 13 deletions packages/react-ui/src/widgets/CategoryWidgetUI/CategoryWidgetUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
CategoriesRoot
} from './CategoryWidgetUI.styled';
import SearchIcon from '../../assets/icons/SearchIcon';
import { ORDER_TYPES } from '../utils/chartConstants';

function usePrevious(value) {
const ref = useRef();
Expand Down Expand Up @@ -225,14 +226,14 @@ function CategoryWidgetUI(props) {
useEffect(() => {
if (data) {
// Ranking
if (order === CategoryWidgetUI.ORDER_TYPES.RANKING) {
if (order === ORDER_TYPES.RANKING) {
const sorted = [...data].sort((a, b) => b.value - a.value);
const compressed = compressList(sorted);
compressed.length ? setMaxValue(compressed[0].value) : setMaxValue(1);
setSortedData(compressed);

// Fixed order
} else if (order === CategoryWidgetUI.ORDER_TYPES.FIXED) {
} else if (order === ORDER_TYPES.FIXED) {
setMaxValue(
Math.max.apply(
Math,
Expand Down Expand Up @@ -438,21 +439,12 @@ function CategoryWidgetUI(props) {
);
}

/**
* Enum for CategoryWidgetUI order types. 'RANKING' orders the data by value and 'FIXED' keeps the order present in the original data
* @enum {string}
*/
CategoryWidgetUI.ORDER_TYPES = {
RANKING: 'ranking',
FIXED: 'fixed'
};

CategoryWidgetUI.defaultProps = {
data: null,
formatter: (v) => v,
labels: {},
maxItems: 5,
order: CategoryWidgetUI.ORDER_TYPES.RANKING,
order: ORDER_TYPES.RANKING,
selectedCategories: [],
animation: true,
filterable: true,
Expand All @@ -472,7 +464,7 @@ CategoryWidgetUI.propTypes = {
maxItems: PropTypes.number,
selectedCategories: PropTypes.array,
onSelectedCategoriesChange: PropTypes.func,
order: PropTypes.oneOf(Object.values(CategoryWidgetUI.ORDER_TYPES)),
order: PropTypes.oneOf(Object.values(ORDER_TYPES)),
animation: PropTypes.bool,
filterable: PropTypes.bool,
searchable: PropTypes.bool,
Expand Down
Loading