Skip to content

Commit

Permalink
Allow to disable WrapperWidgetUI (#420)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio Clebal authored Jun 2, 2022
1 parent cb816fb commit dc29d15
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Not released

- Allow to disable WrapperWidgetUI [#420](https://github.com/CartoDB/carto-react/pull/420)

## 1.3

### 1.3.0-alpha.12 (2022-06-01)
Expand Down
10 changes: 10 additions & 0 deletions packages/react-ui/__tests__/widgets/WrapperWidgetUI.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ describe('WrapperWidgetUI', () => {
expect(screen.getByText(/test/)).toBeInTheDocument();
});

test('should not appear if disabled', () => {
render(
<WrapperWidgetUI title={TITLE} disabled={true}>
<p>__test__</p>
</WrapperWidgetUI>
);
expect(screen.queryByText(TITLE)).not.toBeInTheDocument();
expect(screen.getByText('__test__')).toBeInTheDocument();
});

describe('events', () => {
const FORMULA_DATA = '1234';
const WrappedWithFormulaWidget = ({ numberOfChilds = 1 }) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ TableWidgetUI.propTypes = {
rowsPerPageOptions: PropTypes.array,
onSetRowsPerPage: PropTypes.func,
onRowClick: PropTypes.func,
height: PropTypes.string,
height: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
dense: PropTypes.bool
};

Expand Down
15 changes: 13 additions & 2 deletions packages/react-ui/src/widgets/WrapperWidgetUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ function WrapperWidgetUI(props) {
const [anchorEl, setAnchorEl] = useState(null);
const classes = useStyles({ ...props, expanded });
const open = Boolean(anchorEl);
const { options = [], actions = [], optionsIcon = <MoreVert /> } = props;
const {
disabled = false,
options = [],
actions = [],
optionsIcon = <MoreVert />
} = props;

const handleExpandClick = () => {
if (props.expandable) {
Expand Down Expand Up @@ -158,6 +163,10 @@ function WrapperWidgetUI(props) {
);
};

if (disabled) {
return props.children;
}

return (
<Box component='section' aria-label={props.title} className={classes.root}>
{props.isLoading ? <LinearProgress className={classes.loading} /> : null}
Expand Down Expand Up @@ -253,7 +262,8 @@ function WrapperWidgetUI(props) {
WrapperWidgetUI.defaultProps = {
expanded: true,
expandable: true,
isLoading: false
isLoading: false,
disabled: false
};

WrapperWidgetUI.propTypes = {
Expand All @@ -262,6 +272,7 @@ WrapperWidgetUI.propTypes = {
expanded: PropTypes.bool,
onExpandedChange: PropTypes.func,
isLoading: PropTypes.bool,
disabled: PropTypes.bool,
actions: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.string.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ export const Loading = Template.bind({});
const LoadingProps = { title: 'Loading', loading: true };
Loading.args = LoadingProps;

export const Disabled = Template.bind({});
const DisabledProps = { title: 'Disabled', disabled: true };
Disabled.args = DisabledProps;

export const WithActions = Template.bind({});
WithActions.args = {
title: 'Wrapper with actions',
Expand Down
10 changes: 5 additions & 5 deletions packages/react-widgets/src/widgets/ScatterPlotWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import useWidgetFetch from '../hooks/useWidgetFetch';

/**
* Renders a <ScatterPlotWidget /> component
* @param props
* @param {object} props
* @param {string} props.id - ID for the widget instance.
* @param {string} props.title - Title to show in the widget header.
* @param {string} props.dataSource - ID of the data source to get the data from.
Expand All @@ -19,10 +19,10 @@ import useWidgetFetch from '../hooks/useWidgetFetch';
* @param {string | string[]} props.yAxisColumn - Name of the data source's column to get the y axis from. If multiples are provided, they will be merged into a single one using yAxisJoinOperation property.
* @param {AggregationTypes} [props.yAxisJoinOperation] - Operation applied to aggregate multiple yAxis columns into a single one.
* @param {boolean} [props.animation] - Enable/disable widget animations on data updates. Enabled by default.
* @param {formatterCallback} [props.xAxisFormatter] - Function to format X axis values.
* @param {formatterCallback} [props.yAxisFormatter] - Function to format Y axis values.
* @param {formatterCallback} [props.tooltipFormatter] - Function to format Y axis values.
* @param {errorCallback} [props.onError] - Function to handle error messages from the widget.
* @param {Function} [props.xAxisFormatter] - Function to format X axis values.
* @param {Function} [props.yAxisFormatter] - Function to format Y axis values.
* @param {Function} [props.tooltipFormatter] - Function to format Y axis values.
* @param {Function} [props.onError] - Function to handle error messages from the widget.
* @param {Object} [props.wrapperProps] - Extra props to pass to [WrapperWidgetUI](https://storybook-react.carto.com/?path=/docs/widgets-wrapperwidgetui--default)
* @param {Object} [props.noDataAlertProps] - Extra props to pass to [NoDataAlert]()
* @param {Object} [props.droppingFeaturesAlertProps] - Extra props to pass to [NoDataAlert]() when dropping feature
Expand Down

0 comments on commit dc29d15

Please sign in to comment.