Skip to content

Commit

Permalink
Update Data Source Lifecycle Events (#3828)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldutra authored and arikfr committed May 27, 2019
1 parent 7679df6 commit 28e9740
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 2 additions & 0 deletions client/app/pages/data-sources/DataSourcesList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import CardsList from '@/components/cards-list/CardsList';
import LoadingState from '@/components/items-list/components/LoadingState';
import CreateSourceDialog from '@/components/CreateSourceDialog';
import helper from '@/components/dynamic-form/dynamicFormHelper';
import recordEvent from '@/services/recordEvent';

class DataSourcesList extends React.Component {
state = {
Expand Down Expand Up @@ -56,6 +57,7 @@ class DataSourcesList extends React.Component {
};

showCreateSourceDialog = () => {
recordEvent('view', 'page', 'data_sources/new');
CreateSourceDialog.showModal({
types: this.state.dataSourceTypes,
sourceType: 'Data Source',
Expand Down
23 changes: 16 additions & 7 deletions redash/handlers/data_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ def post(self, data_source_id):

abort(400)

self.record_event({
'action': 'edit',
'object_id': data_source.id,
'object_type': 'datasource',
})

return data_source.to_dict(all=True)

@require_admin
Expand Down Expand Up @@ -202,15 +208,18 @@ class DataSourceTestResource(BaseResource):
def post(self, data_source_id):
data_source = get_object_or_404(models.DataSource.get_by_id_and_org, data_source_id, self.current_org)

response = {}
try:
data_source.query_runner.test_connection()
except Exception as e:
response = {"message": text_type(e), "ok": False}
else:
response = {"message": "success", "ok": True}

self.record_event({
'action': 'test',
'object_id': data_source_id,
'object_type': 'datasource',
'result': response,
})

try:
data_source.query_runner.test_connection()
except Exception as e:
return {"message": text_type(e), "ok": False}
else:
return {"message": "success", "ok": True}
return response

0 comments on commit 28e9740

Please sign in to comment.