Skip to content
This repository has been archived by the owner on Jul 9, 2022. It is now read-only.

Prefer ts #153

Closed
wants to merge 3 commits 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
31 changes: 24 additions & 7 deletions .github/workflows/prefer_typescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,43 @@ on:
- master

jobs:
comment:
name: Comment about preferring TypeScript
check:
runs-on: ubuntu-latest
steps:
- name: Get changed files
id: changed
uses: trilom/file-changes-action@master
with:
githubToken: ${{ secrets.GITHUB_TOKEN }}

- name: Determine if a .js or .jsx file was added
id: check
run: |
echo ::set-output name=was_js_file_added::$(jq 'map(endswith(".js") or endswith(".jsx"))' ${HOME}/files_added.json | jq 'reduce .[] as $is_js (false; . or $is_js)')
- if: steps.check.outputs.was_js_file_added != 'false'
name: Comment about preferring TypeScript
js_files_added() {
jq -r '
map(
select(
(contains("cypress-base/") | not) and
(endswith(".js") or endswith(".jsx"))
)
) | join("\n")
' ${HOME}/files_added.json
}
echo ::set-output name=js_files_added::$(js_files_added)

- if: steps.check.outputs.js_files_added
name: Add Comment to PR
uses: unsplash/comment-on-pr@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
msg: |
## WARNING: Prefer TypeScript
### WARNING: Prefer TypeScript

It looks like your PR contains new `.js` or `.jsx` files. As decided in [SIP-36](https://github.com/apache/incubator-superset/issues/9101), all new files should be written in TypeScript. Please convert new JavaScript files to TypeScript and then re-request review.
Looks like your PR contains new `.js` or `.jsx` files:

```
${{steps.check.outputs.js_files_added}}
```

As decided in [SIP-36](https://github.com/apache/incubator-superset/issues/9101), all new frontend code should be written in TypeScript. Please convert above files to TypeScript then re-request review.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ combine_as_imports = true
include_trailing_comma = true
line_length = 88
known_first_party = superset
known_third_party =alembic,apispec,backoff,bleach,cachelib,celery,click,colorama,contextlib2,croniter,cryptography,dateutil,flask,flask_appbuilder,flask_babel,flask_caching,flask_compress,flask_login,flask_migrate,flask_sqlalchemy,flask_talisman,flask_testing,flask_wtf,geohash,geopy,humanize,isodate,jinja2,markdown,markupsafe,marshmallow,msgpack,numpy,pandas,parsedatetime,pathlib2,polyline,prison,pyarrow,pyhive,pytz,retry,selenium,setuptools,simplejson,slack,sphinx_rtd_theme,sqlalchemy,sqlalchemy_utils,sqlparse,werkzeug,wtforms,wtforms_json,yaml
known_third_party =alembic,apispec,backoff,bleach,cachelib,celery,click,colorama,contextlib2,croniter,cryptography,dateutil,flask,flask_appbuilder,flask_babel,flask_caching,flask_compress,flask_login,flask_migrate,flask_sqlalchemy,flask_talisman,flask_testing,flask_wtf,geohash,geopy,humanize,isodate,jinja2,markdown,markupsafe,marshmallow,msgpack,numpy,pandas,parameterized,parsedatetime,pathlib2,polyline,prison,pyarrow,pyhive,pytz,retry,selenium,setuptools,simplejson,slack,sphinx_rtd_theme,sqlalchemy,sqlalchemy_utils,sqlparse,werkzeug,wtforms,wtforms_json,yaml
multi_line_output = 3
order_by_type = false

Expand Down
24 changes: 22 additions & 2 deletions superset-frontend/src/SqlLab/actions/sqlLab.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const CtasEnum = {
TABLE: 'TABLE',
VIEW: 'VIEW',
};
const ERR_MSG_CANT_LOAD_QUERY = t("The query couldn't be loaded");

// a map of SavedQuery field names to the different names used client-side,
// because for now making the names consistent is too complicated
Expand Down Expand Up @@ -1182,7 +1183,7 @@ export function popStoredQuery(urlId) {
}),
),
)
.catch(() => dispatch(addDangerToast(t("The query couldn't be loaded"))));
.catch(() => dispatch(addDangerToast(ERR_MSG_CANT_LOAD_QUERY)));
};
}
export function popSavedQuery(saveQueryId) {
Expand All @@ -1197,7 +1198,26 @@ export function popSavedQuery(saveQueryId) {
};
return dispatch(addQueryEditor(queryEditorProps));
})
.catch(() => dispatch(addDangerToast(t("The query couldn't be loaded"))));
.catch(() => dispatch(addDangerToast(ERR_MSG_CANT_LOAD_QUERY)));
};
}
export function popQuery(queryId) {
return function (dispatch) {
return SupersetClient.get({
endpoint: `/api/v1/query/${queryId}`,
})
.then(({ json }) => {
const queryData = json.result;
const queryEditorProps = {
dbId: queryData.database.id,
schema: queryData.schema,
sql: queryData.sql,
title: `Copy of ${queryData.tab_name}`,
autorun: false,
};
return dispatch(addQueryEditor(queryEditorProps));
})
.catch(() => dispatch(addDangerToast(ERR_MSG_CANT_LOAD_QUERY)));
};
}
export function popDatasourceQuery(datasourceKey, sql) {
Expand Down
19 changes: 5 additions & 14 deletions superset-frontend/src/SqlLab/components/QueryTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import ResultSet from './ResultSet';
import ModalTrigger from '../../components/ModalTrigger';
import HighlightedSql from './HighlightedSql';
import { fDuration } from '../../modules/dates';
import { storeQuery } from '../../utils/common';
import QueryStateLabel from './QueryStateLabel';

const propTypes = {
Expand Down Expand Up @@ -57,18 +56,10 @@ class QueryTable extends React.PureComponent {
activeQuery: null,
};
}
callback(url) {
openQuery(id) {
const url = `/superset/sqllab?queryId=${id}`;
window.open(url);
}
openQuery(dbId, schema, sql) {
const newQuery = {
dbId,
title: t('Untitled Query'),
schema,
sql,
};
storeQuery(newQuery).then(url => this.callback(url));
}
hideVisualizeModal() {
this.setState({ showVisualizeModal: false });
}
Expand Down Expand Up @@ -127,10 +118,10 @@ class QueryTable extends React.PureComponent {
<div style={{ width: '100px' }}>
<button
className="btn btn-link btn-xs"
onClick={this.openQuery.bind(this, q.dbId, q.schema, q.sql)}
onClick={this.openQuery.bind(this, q.queryId)}
>
<i className="fa fa-external-link" />
{t('Open in SQL Editor')}
<i className="fa fa-external-link m-r-3" />
{t('Edit')}
</button>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const RunQueryActionButton = ({
runQuery = NO_OP,
selectedText,
stopQuery = NO_OP,
sql,
sql = '',
}: Props) => {
const runBtnText = selectedText ? t('Run Selected Query') : t('Run');
const btnStyle = selectedText ? 'warning' : 'primary';
Expand Down
10 changes: 9 additions & 1 deletion superset-frontend/src/SqlLab/components/TabbedSqlEditors.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,19 @@ class TabbedSqlEditors extends React.PureComponent {
};

// Popping a new tab based on the querystring
if (query.id || query.sql || query.savedQueryId || query.datasourceKey) {
if (
query.id ||
query.sql ||
query.savedQueryId ||
query.datasourceKey ||
query.queryId
) {
if (query.id) {
this.props.actions.popStoredQuery(query.id);
} else if (query.savedQueryId) {
this.props.actions.popSavedQuery(query.savedQueryId);
} else if (query.queryId) {
this.props.actions.popQuery(query.queryId);
} else if (query.datasourceKey) {
this.props.actions.popDatasourceQuery(query.datasourceKey, query.sql);
} else if (query.sql) {
Expand Down
Loading