This is an automated email from the ASF dual-hosted git repository.

graceguo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 83b4165  [perf logging] Add extra logging for new/editMode dash (#9745)
83b4165 is described below

commit 83b4165e6138a51854313f52f14264a59b381c06
Author: Grace Guo <[email protected]>
AuthorDate: Wed May 6 09:03:04 2020 -0700

    [perf logging] Add extra logging for new/editMode dash (#9745)
    
    * [perf logging] Add extra logging for new/editMode dash
    
    * fix review comments
---
 .../dashboard/util/isDashboardEmpty_spec.ts        | 42 ++++++++++++++++++++++
 .../src/dashboard/components/Dashboard.jsx         |  8 ++++-
 .../src/dashboard/util/isDashboardEmpty.ts         | 28 +++++++++++++++
 3 files changed, 77 insertions(+), 1 deletion(-)

diff --git 
a/superset-frontend/spec/javascripts/dashboard/util/isDashboardEmpty_spec.ts 
b/superset-frontend/spec/javascripts/dashboard/util/isDashboardEmpty_spec.ts
new file mode 100644
index 0000000..70bab02
--- /dev/null
+++ b/superset-frontend/spec/javascripts/dashboard/util/isDashboardEmpty_spec.ts
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import isDashboardEmpty from '../../../../src/dashboard/util/isDashboardEmpty';
+import getEmptyLayout from '../../../../src/dashboard/util/getEmptyLayout';
+
+describe('isDashboardEmpty', () => {
+  const emptyLayout: object = getEmptyLayout();
+  const testLayout: object = {
+    ...emptyLayout,
+    'MARKDOWN-IhTGLhyiTd': {
+      children: [],
+      id: 'MARKDOWN-IhTGLhyiTd',
+      meta: { code: 'test me', height: 50, width: 4 },
+      parents: ['ROOT_ID', 'GRID_ID', 'ROW-uPjcKNYJQy'],
+      type: 'MARKDOWN',
+    },
+  };
+
+  it('should return true for empty dashboard', () => {
+    expect(isDashboardEmpty(emptyLayout)).toBe(true);
+  });
+
+  it('should return false for non-empty dashboard', () => {
+    expect(isDashboardEmpty(testLayout)).toBe(false);
+  });
+});
diff --git a/superset-frontend/src/dashboard/components/Dashboard.jsx 
b/superset-frontend/src/dashboard/components/Dashboard.jsx
index 4da1428..34e0f12 100644
--- a/superset-frontend/src/dashboard/components/Dashboard.jsx
+++ b/superset-frontend/src/dashboard/components/Dashboard.jsx
@@ -39,6 +39,7 @@ import { areObjectsEqual } from '../../reduxUtils';
 
 import '../stylesheets/index.less';
 import getLocationHash from '../util/getLocationHash';
+import isDashboardEmpty from '../util/isDashboardEmpty';
 
 const propTypes = {
   actions: PropTypes.shape({
@@ -90,7 +91,12 @@ class Dashboard extends React.PureComponent {
   }
 
   componentDidMount() {
-    const eventData = {};
+    const { dashboardState, layout } = this.props;
+    const eventData = {
+      is_edit_mode: dashboardState.editMode,
+      mount_duration: Logger.getTimestamp(),
+      is_empty: isDashboardEmpty(layout),
+    };
     const directLinkComponentId = getLocationHash();
     if (directLinkComponentId) {
       eventData.target_id = directLinkComponentId;
diff --git a/superset-frontend/src/dashboard/util/isDashboardEmpty.ts 
b/superset-frontend/src/dashboard/util/isDashboardEmpty.ts
new file mode 100644
index 0000000..78481c5
--- /dev/null
+++ b/superset-frontend/src/dashboard/util/isDashboardEmpty.ts
@@ -0,0 +1,28 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { CHART_TYPE, MARKDOWN_TYPE } from './componentTypes';
+
+const USER_CONTENT_COMPONENT_TYPE: string[] = [CHART_TYPE, MARKDOWN_TYPE];
+export default function isDashboardEmpty(layout: any): boolean {
+  // has at least one chart or markdown component
+  return !Object.values(layout).some(
+    ({ type }: { type?: string }) =>
+      type && USER_CONTENT_COMPONENT_TYPE.includes(type),
+  );
+}

Reply via email to