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

[bot] Apply Grit pattern: react_to_hooks #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
* under the License.
*/

import React, { ReactNode } from 'react';

import { useState, useCallback } from 'react';

export type Props = {
children: ReactNode;
Expand All @@ -28,18 +29,15 @@ type State = {
open: boolean;
};

export default class Expandable extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = { open: false };
this.handleToggle = this.handleToggle.bind(this);
}
export default export const Expandable = (props: Props) => {


handleToggle() {
const [open, setOpen] = useState(false);

const handleToggleHandler = useCallback(() => {
this.setState(({ open }) => ({ open: !open }));
}
}, []);

render() {
const { open } = this.state;
const { children, expandableWhat } = this.props;

Expand All @@ -56,6 +54,8 @@ export default class Expandable extends React.Component<Props, State> {
<br />
{open ? children : null}
</div>
);
}
}
);
};



Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
* under the License.
*/

import React, { ReactNode } from 'react';

import React, { useState, useEffect, useCallback } from 'react';
import {
SupersetClient,
Method,
makeApi,
SupersetApiError,
SupersetClient,
Method,
makeApi,
SupersetApiError,
} from '@superset-ui/core';
import ErrorMessage from './ErrorMessage';

Expand Down Expand Up @@ -52,14 +53,12 @@ export const renderError = (error: Error) => (
</div>
);

export default class VerifyCORS extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = { didVerify: false };
this.handleVerify = this.handleVerify.bind(this);
}
export default export const VerifyCORS = (props: Props) => {


componentDidUpdate(prevProps: Props) {
const [didVerify, setDidVerify] = useState(false);

useEffect(() => {
const { endpoint, host, postPayload, method } = this.props;
if (
(this.state.didVerify || this.state.error) &&
Expand All @@ -71,9 +70,8 @@ export default class VerifyCORS extends React.Component<Props, State> {
// eslint-disable-next-line react/no-did-update-set-state
this.setState({ didVerify: false, error: undefined });
}
}

handleVerify() {
}, []);
const handleVerifyHandler = useCallback(() => {
const { endpoint, host, postPayload, method } = this.props;
SupersetClient.reset();
SupersetClient.configure({
Expand All @@ -96,9 +94,8 @@ export default class VerifyCORS extends React.Component<Props, State> {
this.setState({ didVerify: true, error: undefined, payload: result }),
)
.catch(error => this.setState({ error }));
}
}, []);

render() {
const { didVerify, error, payload } = this.state;
const { children } = this.props;

Expand Down Expand Up @@ -133,6 +130,8 @@ export default class VerifyCORS extends React.Component<Props, State> {
</div>
)}
</div>
);
}
}
);
};



Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
* under the License.
*/
/* eslint-disable react/sort-prop-types, react/jsx-sort-default-props */
import React from 'react';

import { useCallback } from 'react';
import PropTypes from 'prop-types';
import { ParentSize } from '@vx/responsive';

Expand Down Expand Up @@ -54,9 +55,13 @@
position: 'relative',
};

class WithLegend extends React.Component {
getContainerDirection() {
const { position } = this.props;
const WithLegend = (props) => {

Check failure on line 58 in superset-frontend/plugins/legacy-plugin-chart-histogram/src/WithLegend.jsx

View workflow job for this annotation

GitHub Actions / frontend-build

Replace `(props)` with `props`

Check failure on line 58 in superset-frontend/plugins/legacy-plugin-chart-histogram/src/WithLegend.jsx

View workflow job for this annotation

GitHub Actions / frontend-build

Replace `(props)` with `props`

Check failure on line 59 in superset-frontend/plugins/legacy-plugin-chart-histogram/src/WithLegend.jsx

View workflow job for this annotation

GitHub Actions / frontend-build

Delete `⏎⏎····⏎⏎··`

Check failure on line 59 in superset-frontend/plugins/legacy-plugin-chart-histogram/src/WithLegend.jsx

View workflow job for this annotation

GitHub Actions / frontend-build

Delete `⏎⏎····⏎⏎··`



const getContainerDirectionHandler = useCallback(() => {
const { position } = props;
switch (position) {
case 'left':
return 'row';
Expand All @@ -68,10 +73,9 @@
case 'top':
return 'column';
}
}

getLegendJustifyContent() {
const { legendJustifyContent, position } = this.props;
}, []);
const getLegendJustifyContentHandler = useCallback(() => {

Check failure on line 77 in superset-frontend/plugins/legacy-plugin-chart-histogram/src/WithLegend.jsx

View workflow job for this annotation

GitHub Actions / frontend-build

Delete `··`

Check failure on line 77 in superset-frontend/plugins/legacy-plugin-chart-histogram/src/WithLegend.jsx

View workflow job for this annotation

GitHub Actions / frontend-build

Delete `··`
const { legendJustifyContent, position } = props;
if (legendJustifyContent) {
return legendJustifyContent;
}
Expand All @@ -86,18 +90,17 @@
case 'top':
return 'flex-end';
}
}
}, []);

render() {
const { className, width, height, position, renderChart, renderLegend } =

Check failure on line 95 in superset-frontend/plugins/legacy-plugin-chart-histogram/src/WithLegend.jsx

View workflow job for this annotation

GitHub Actions / frontend-build

Replace `····` with `··`

Check failure on line 95 in superset-frontend/plugins/legacy-plugin-chart-histogram/src/WithLegend.jsx

View workflow job for this annotation

GitHub Actions / frontend-build

Replace `····` with `··`
this.props;
props;

Check failure on line 96 in superset-frontend/plugins/legacy-plugin-chart-histogram/src/WithLegend.jsx

View workflow job for this annotation

GitHub Actions / frontend-build

Delete `··`

Check failure on line 96 in superset-frontend/plugins/legacy-plugin-chart-histogram/src/WithLegend.jsx

View workflow job for this annotation

GitHub Actions / frontend-build

Delete `··`

const isHorizontal = position === 'left' || position === 'right';

Check failure on line 98 in superset-frontend/plugins/legacy-plugin-chart-histogram/src/WithLegend.jsx

View workflow job for this annotation

GitHub Actions / frontend-build

Replace `····` with `··`

Check failure on line 98 in superset-frontend/plugins/legacy-plugin-chart-histogram/src/WithLegend.jsx

View workflow job for this annotation

GitHub Actions / frontend-build

Replace `····` with `··`

const style = {

Check failure on line 100 in superset-frontend/plugins/legacy-plugin-chart-histogram/src/WithLegend.jsx

View workflow job for this annotation

GitHub Actions / frontend-build

Delete `··`

Check failure on line 100 in superset-frontend/plugins/legacy-plugin-chart-histogram/src/WithLegend.jsx

View workflow job for this annotation

GitHub Actions / frontend-build

Delete `··`
display: 'flex',

Check failure on line 101 in superset-frontend/plugins/legacy-plugin-chart-histogram/src/WithLegend.jsx

View workflow job for this annotation

GitHub Actions / frontend-build

Replace `······` with `····`

Check failure on line 101 in superset-frontend/plugins/legacy-plugin-chart-histogram/src/WithLegend.jsx

View workflow job for this annotation

GitHub Actions / frontend-build

Replace `······` with `····`
flexDirection: this.getContainerDirection(),
flexDirection: getContainerDirectionHandler(),

Check failure on line 102 in superset-frontend/plugins/legacy-plugin-chart-histogram/src/WithLegend.jsx

View workflow job for this annotation

GitHub Actions / frontend-build

Delete `··`

Check failure on line 102 in superset-frontend/plugins/legacy-plugin-chart-histogram/src/WithLegend.jsx

View workflow job for this annotation

GitHub Actions / frontend-build

Delete `··`
};

Check failure on line 103 in superset-frontend/plugins/legacy-plugin-chart-histogram/src/WithLegend.jsx

View workflow job for this annotation

GitHub Actions / frontend-build

Delete `··`

Check failure on line 103 in superset-frontend/plugins/legacy-plugin-chart-histogram/src/WithLegend.jsx

View workflow job for this annotation

GitHub Actions / frontend-build

Delete `··`
if (width) {
style.width = width;
}
Expand All @@ -116,7 +119,7 @@
const legendStyle = {
...LEGEND_STYLE_BASE,
flexDirection: legendDirection,
justifyContent: this.getLegendJustifyContent(),
justifyContent: getLegendJustifyContentHandler(),
};
const legendContainerStyle = {
flexWrap: 'wrap',
Expand All @@ -143,9 +146,11 @@
</ParentSize>
</div>
</div>
);
}
}
);
};




WithLegend.propTypes = propTypes;
WithLegend.defaultProps = defaultProps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*/
/* eslint-disable react/jsx-sort-default-props, react/sort-prop-types */
/* eslint-disable react/forbid-prop-types, react/require-default-props */
import React from 'react';

import { useState, useCallback } from 'react';
import PropTypes from 'prop-types';
import MapGL from 'react-map-gl';
import ViewportMercator from 'viewport-mercator-project';
Expand Down Expand Up @@ -55,37 +56,26 @@ const defaultProps = {
pointRadiusUnit: 'Pixels',
};

class MapBox extends React.Component {
constructor(props) {
super(props);

const { width, height, bounds } = this.props;
// Get a viewport that fits the given bounds, which all marks to be clustered.
// Derive lat, lon and zoom from this viewport. This is only done on initial
// render as the bounds don't update as we pan/zoom in the current design.
const MapBox = (props) => {
const { width, height, bounds } = props;
const mercator = new ViewportMercator({
width,
height,
}).fitBounds(bounds);
const { latitude, longitude, zoom } = mercator;

this.state = {
viewport: {
const [viewport, setViewport] = useState({
longitude,
latitude,
zoom,
},
};
this.handleViewportChange = this.handleViewportChange.bind(this);
}

handleViewportChange(viewport) {
this.setState({ viewport });
const { onViewportChange } = this.props;
});

const handleViewportChangeHandler = useCallback((viewport) => {
setViewport(viewport);
const { onViewportChange } = props;
onViewportChange(viewport);
}
}, [viewport]);

render() {
const {
width,
height,
Expand All @@ -100,8 +90,8 @@ class MapBox extends React.Component {
rgb,
hasCustomMetric,
bounds,
} = this.props;
const { viewport } = this.state;
} = props;

const isDragging =
viewport.isDragging === undefined ? false : viewport.isDragging;

Expand All @@ -126,7 +116,7 @@ class MapBox extends React.Component {
width={width}
height={height}
mapboxApiAccessToken={mapboxApiKey}
onViewportChange={this.handleViewportChange}
onViewportChange={handleViewportChangeHandler}
preserveDrawingBuffer
>
<ScatterPlotGlowOverlay
Expand All @@ -147,9 +137,11 @@ class MapBox extends React.Component {
}}
/>
</MapGL>
);
}
}
);
};




MapBox.propTypes = propTypes;
MapBox.defaultProps = defaultProps;
Expand Down