From 2e7a595b3a9db0d0ca998eb5f3033d2313f7734a Mon Sep 17 00:00:00 2001 From: Gabriel Dutra Date: Mon, 27 May 2019 13:28:16 -0300 Subject: [PATCH] Update Data Source Lifecycle Events (#3828) --- .../pages/data-sources/DataSourcesList.jsx | 2 ++ redash/handlers/data_sources.py | 23 +++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/client/app/pages/data-sources/DataSourcesList.jsx b/client/app/pages/data-sources/DataSourcesList.jsx index 29d51c2263..9d532b1e6a 100644 --- a/client/app/pages/data-sources/DataSourcesList.jsx +++ b/client/app/pages/data-sources/DataSourcesList.jsx @@ -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 = { @@ -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', diff --git a/redash/handlers/data_sources.py b/redash/handlers/data_sources.py index 1324d092dd..0d814a0209 100644 --- a/redash/handlers/data_sources.py +++ b/redash/handlers/data_sources.py @@ -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 @@ -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