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

refactor: run react-codemod sort-comp #12395

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions superset-frontend/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ module.exports = {
'react/no-unused-prop-types': 0,
'react/prop-types': 0,
'react/require-default-props': 0,
'react/sort-comp': 0, // TODO: re-enable in separate PR
'react/static-property-placement': 0, // re-enable up for discussion
'prettier/prettier': 'error',
},
Expand Down Expand Up @@ -247,7 +246,6 @@ module.exports = {
'react/no-unused-prop-types': 0,
'react/prop-types': 0,
'react/require-default-props': 0,
'react/sort-comp': 0, // TODO: re-enable in separate PR
'react/static-property-placement': 0, // disabled temporarily
'prettier/prettier': 'error',
},
Expand Down
70 changes: 35 additions & 35 deletions superset-frontend/src/SqlLab/components/ExploreResultsButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ class ExploreResultsButton extends React.PureComponent {
return [];
}

getQueryDuration() {
return moment
.duration(this.props.query.endDttm - this.props.query.startDttm)
.asSeconds();
}

getInvalidColumns() {
const re1 = /__\d+$/; // duplicate column name pattern
const re2 = /^__timestamp/i; // reserved temporal column alias
Expand All @@ -77,15 +71,10 @@ class ExploreResultsButton extends React.PureComponent {
.filter(col => re1.test(col) || re2.test(col));
}

datasourceName() {
const { query } = this.props;
const uniqueId = shortid.generate();
let datasourceName = uniqueId;
if (query) {
datasourceName = query.user ? `${query.user}-` : '';
datasourceName += `${query.tab}-${uniqueId}`;
}
return datasourceName;
getQueryDuration() {
return moment
.duration(this.props.query.endDttm - this.props.query.startDttm)
.asSeconds();
}

buildVizOptions() {
Expand All @@ -100,6 +89,37 @@ class ExploreResultsButton extends React.PureComponent {
};
}

datasourceName() {
const { query } = this.props;
const uniqueId = shortid.generate();
let datasourceName = uniqueId;
if (query) {
datasourceName = query.user ? `${query.user}-` : '';
datasourceName += `${query.tab}-${uniqueId}`;
}
return datasourceName;
}

renderInvalidColumnMessage() {
const invalidColumns = this.getInvalidColumns();
if (invalidColumns.length === 0) {
return null;
}
return (
<div>
{t('Column name(s) ')}
<code>
<strong>{invalidColumns.join(', ')} </strong>
</code>
{t(`cannot be used as a column name. The column name/alias "__timestamp"
is reserved for the main temporal expression, and column aliases ending with
double underscores followed by a numeric value (e.g. "my_col__1") are reserved
for deduplicating duplicate column names. Please use aliases to rename the
invalid column names.`)}
</div>
);
}

renderTimeoutWarning() {
return (
<Alert bsStyle="warning">
Expand All @@ -124,26 +144,6 @@ class ExploreResultsButton extends React.PureComponent {
);
}

renderInvalidColumnMessage() {
const invalidColumns = this.getInvalidColumns();
if (invalidColumns.length === 0) {
return null;
}
return (
<div>
{t('Column name(s) ')}
<code>
<strong>{invalidColumns.join(', ')} </strong>
</code>
{t(`cannot be used as a column name. The column name/alias "__timestamp"
is reserved for the main temporal expression, and column aliases ending with
double underscores followed by a numeric value (e.g. "my_col__1") are reserved
for deduplicating duplicate column names. Please use aliases to rename the
invalid column names.`)}
</div>
);
}

render() {
const allowsSubquery =
this.props.database && this.props.database.allows_subquery;
Expand Down
50 changes: 25 additions & 25 deletions superset-frontend/src/SqlLab/components/HighlightedSql.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,31 @@ class HighlightedSql extends React.Component {
};
}

generateModal() {
let rawSql;
if (this.props.rawSql && this.props.rawSql !== this.props.sql) {
rawSql = (
<div>
<h4>{t('Raw SQL')}</h4>
<SyntaxHighlighter language="sql" style={github}>
{this.props.rawSql}
</SyntaxHighlighter>
</div>
);
}
this.setState({
modalBody: (
<div>
<h4>{t('Source SQL')}</h4>
<SyntaxHighlighter language="sql" style={github}>
{this.props.sql}
</SyntaxHighlighter>
{rawSql}
</div>
),
});
}

shrinkSql() {
const ssql = this.props.sql || '';
let lines = ssql.split('\n');
Expand Down Expand Up @@ -77,31 +102,6 @@ class HighlightedSql extends React.Component {
);
}

generateModal() {
let rawSql;
if (this.props.rawSql && this.props.rawSql !== this.props.sql) {
rawSql = (
<div>
<h4>{t('Raw SQL')}</h4>
<SyntaxHighlighter language="sql" style={github}>
{this.props.rawSql}
</SyntaxHighlighter>
</div>
);
}
this.setState({
modalBody: (
<div>
<h4>{t('Source SQL')}</h4>
<SyntaxHighlighter language="sql" style={github}>
{this.props.sql}
</SyntaxHighlighter>
{rawSql}
</div>
),
});
}

render() {
return (
<ModalTrigger
Expand Down
76 changes: 38 additions & 38 deletions superset-frontend/src/SqlLab/components/QuerySearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,9 @@ class QuerySearch extends React.PureComponent {
this.refreshQueries();
}

onUserClicked(userId) {
this.setState({ userId }, () => {
this.refreshQueries();
});
onChange(db) {
const val = db ? db.value : null;
this.setState({ databaseId: val });
}

onDbClicked(dbId) {
Expand All @@ -105,17 +104,18 @@ class QuerySearch extends React.PureComponent {
});
}

onChange(db) {
const val = db ? db.value : null;
this.setState({ databaseId: val });
}

onKeyDown(event) {
if (event.keyCode === 13) {
this.refreshQueries();
}
}

onUserClicked(userId) {
this.setState({ userId }, () => {
this.refreshQueries();
});
}

getTimeFromSelection(selection) {
switch (selection) {
case 'now':
Expand All @@ -142,44 +142,23 @@ class QuerySearch extends React.PureComponent {
this.setState({ from: val });
}

changeTo(status) {
const val = status ? status.value : null;
this.setState({ to: val });
}

changeUser(user) {
const val = user ? user.value : null;
this.setState({ userId: val });
}

insertParams(baseUrl, params) {
const validParams = params.filter(function (p) {
return p !== '';
});
return `${baseUrl}?${validParams.join('&')}`;
changeSearch(event) {
this.setState({ searchText: event.target.value });
}

changeStatus(status) {
const val = status ? status.value : null;
this.setState({ status: val });
}

changeSearch(event) {
this.setState({ searchText: event.target.value });
}

userLabel(user) {
if (user.first_name && user.last_name) {
return `${user.first_name} ${user.last_name}`;
}
return user.username;
changeTo(status) {
const val = status ? status.value : null;
this.setState({ to: val });
}

userMutator(data) {
return data.result.map(({ value, text }) => ({
label: text,
value,
}));
changeUser(user) {
const val = user ? user.value : null;
this.setState({ userId: val });
}

dbMutator(data) {
Expand All @@ -196,6 +175,13 @@ class QuerySearch extends React.PureComponent {
return options;
}

insertParams(baseUrl, params) {
const validParams = params.filter(function (p) {
return p !== '';
});
return `${baseUrl}?${validParams.join('&')}`;
}

refreshQueries() {
this.setState({ queriesLoading: true });
const params = [
Expand All @@ -222,6 +208,20 @@ class QuerySearch extends React.PureComponent {
});
}

userLabel(user) {
if (user.first_name && user.last_name) {
return `${user.first_name} ${user.last_name}`;
}
return user.username;
}

userMutator(data) {
return data.result.map(({ value, text }) => ({
label: text,
value,
}));
}

render() {
return (
<TableWrapper>
Expand Down
24 changes: 12 additions & 12 deletions superset-frontend/src/SqlLab/components/ScheduleQueryButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ class ScheduleQueryButton extends React.PureComponent {
this.onDescriptionChange = this.onDescriptionChange.bind(this);
}

onCancel() {
this.saveModal.close();
}

onDescriptionChange(e) {
this.setState({ description: e.target.value });
}

onLabelChange(e) {
this.setState({ label: e.target.value });
}

onSchedule({ formData }) {
const query = {
label: this.state.label,
Expand All @@ -123,18 +135,6 @@ class ScheduleQueryButton extends React.PureComponent {
this.saveModal.close();
}

onCancel() {
this.saveModal.close();
}

onLabelChange(e) {
this.setState({ label: e.target.value });
}

onDescriptionChange(e) {
this.setState({ description: e.target.value });
}

toggleSchedule() {
this.setState(prevState => ({ showSchedule: !prevState.showSchedule }));
}
Expand Down
Loading